I'd make the value of the confirm flag a constant rather than checking for "1" everywhere, but its shaping up.
Yes, that string is ugly.
I wanted to make it a Boolean, but I've got carried away by the note.type wich is a String... I don't know why I used the note.type anymore.
Actually now I think that there is no need for a flag.
If you want a confirmation before closing you send just this:
sendNotification(WindowMediator.ENABLE_CONFIRM); without anything else
and if you don't want to do anything on Event.CLOSING you don't send this notification.
Then in the WindowMediator
private var needConfirm:Boolean=false ;
...
override public function handleNotification( note:INotification ):void
{
switch ( note.getName() ) {
case ENABLE_CONFIRM:
needConfirm = true; break;
...
}
protected function onWindowClosing( event:Event ):void
{
if(
needConfirm){
event.preventDefault();
sendNotification( DesktopCitizenConstants.WINDOW_CLOSING);
}else{
stage.nativeWindow.visible = false;
sendNotification( WindowCloseCommand.NAME );
stage.nativeWindow.close();
}
}
Would you agree?
I'll think about a constant though.
----
Now that I'm playing around with the DesktopCitizen I can see again a behavior that I already noticed before but didn't care much about it:
If you start the application and just move the window around, then close the window and open it again only the size is correct, not the position.
It works as it should, only if you
first move the window and
then resize it.
Both events:
stage.nativeWindow.addEventListener( NativeWindowBoundsEvent.RESIZE, onResize );
stage.nativeWindow.addEventListener( NativeWindowBoundsEvent.MOVE, onResize );
are handled in
protected function onResize( event:Event ):void
Tracing the rect.x and rect.y for both event types shows that RESIZE overwrites the x and y due to MOVE with different values.
In DesktopCitizen.xml the values of x and y change only after RESIZE.
So if you only have
stage.nativeWindow.addEventListener( NativeWindowBoundsEvent.MOVE, onResize );
and look at the DesktopCitizen.xml the values of x and y don't change at all after closing.
I know, I'm not explaining it well...
Maybe a nativewindow bug ?
Thank you.
EDIT:
I did this:
protected function onResize( event:
NativeWindowBoundsEvent ):void
{
if ( windowMetricsProxy.displayState == NativeWindowDisplayState.NORMAL )
windowMetricsProxy.bounds = event.afterBounds ; sendNotification( WINDOW_SHOW );
}
and now it works on MOVE too.