Make window.close cancelable (resolve #817)
This commit is contained in:
@@ -56,25 +56,27 @@ class NativeWindow {
|
||||
closing = true;
|
||||
parent.onClose.dispatch ();
|
||||
|
||||
}
|
||||
|
||||
if (!parent.onClose.canceled) {
|
||||
|
||||
if (handle != null) {
|
||||
if (!parent.onClose.canceled) {
|
||||
|
||||
#if !macro
|
||||
NativeCFFI.lime_window_close (handle);
|
||||
#end
|
||||
handle = null;
|
||||
if (handle != null) {
|
||||
|
||||
#if !macro
|
||||
NativeCFFI.lime_window_close (handle);
|
||||
#end
|
||||
handle = null;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
closing = false;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
closing = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package lime.app;
|
||||
|
||||
import lime.graphics.Renderer;
|
||||
import lime.graphics.RenderContext;
|
||||
import lime.system.System;
|
||||
import lime.ui.Gamepad;
|
||||
import lime.ui.GamepadAxis;
|
||||
import lime.ui.GamepadButton;
|
||||
@@ -269,6 +270,12 @@ class Application extends Module {
|
||||
|
||||
}
|
||||
|
||||
if (__windows.length == 0) {
|
||||
|
||||
System.exit (0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class Module implements IModule {
|
||||
@:noCompletion public function addWindow (window:Window):Void {
|
||||
|
||||
window.onActivate.add (onWindowActivate.bind (window));
|
||||
window.onClose.add (__onWindowClose.bind (window));
|
||||
window.onClose.add (__onWindowClose.bind (window), false, -10000);
|
||||
window.onCreate.add (onWindowCreate.bind (window));
|
||||
window.onDeactivate.add (onWindowDeactivate.bind (window));
|
||||
window.onDropFile.add (onWindowDropFile.bind (window));
|
||||
|
||||
@@ -265,6 +265,19 @@ namespace lime {
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
|
||||
ProcessWindowEvent (event);
|
||||
|
||||
// Avoid handling SDL_QUIT if in response to window.close
|
||||
SDL_Event event;
|
||||
|
||||
if (SDL_PollEvent (&event)) {
|
||||
|
||||
if (event.type != SDL_QUIT) {
|
||||
|
||||
HandleEvent (&event);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user