Browse Source

Route system exit request to Exit menu handler to perform exit check.

Yao Wei Tjong 姚伟忠 12 years ago
parent
commit
9db5f85daf

+ 3 - 0
Bin/Data/Scripts/Editor.as

@@ -45,6 +45,9 @@ void Start()
     cache.autoReloadResources = true;
     // Use OS mouse without grabbing it
     input.mouseVisible = true;
+    // Disable Editor auto exit, check first if it is OK to exit
+    engine.autoExit = false;
+    SubscribeToEvent(input, "ExitRequested", "HandleExitRequested");
 
     // Create root scene node
     CreateScene();

+ 3 - 3
Bin/Data/Scripts/Editor/EditorScene.as

@@ -66,11 +66,11 @@ bool ResetScene()
 
     if (messageBoxCallback is null && sceneModified)
     {
-        uiMessageBox = MessageBox("Scene has been modified.\nContinue to reset?", "Warning");
-        Button@ cancelButton = uiMessageBox.window.GetChild("CancelButton", true);
+        MessageBox@ messageBox = MessageBox("Scene has been modified.\nContinue to reset?", "Warning");
+        Button@ cancelButton = messageBox.window.GetChild("CancelButton", true);
         cancelButton.visible = true;
         cancelButton.focus = true;
-        SubscribeToEvent(uiMessageBox, "MessageACK", "HandleMessageAcknowledgement");
+        SubscribeToEvent(messageBox, "MessageACK", "HandleMessageAcknowledgement");
         messageBoxCallback = @ResetScene;
         return false;
     }

+ 8 - 5
Bin/Data/Scripts/Editor/EditorUI.as

@@ -6,7 +6,6 @@ UIElement@ uiMenuBar;
 UIElement@ quickMenu;
 Array<QuickMenuItem@> quickMenuItems;
 FileSelector@ uiFileSelector;
-MessageBox@ uiMessageBox;
 
 const ShortStringHash UI_ELEMENT_TYPE("UIElement");
 const ShortStringHash WINDOW_TYPE("Window");
@@ -445,11 +444,11 @@ bool Exit()
 
         if (sceneModified || uiLayoutModified)
         {
-            uiMessageBox = MessageBox(message + "Continue to exit?", "Warning");
-            Button@ cancelButton = uiMessageBox.window.GetChild("CancelButton", true);
+            MessageBox@ messageBox = MessageBox(message + "Continue to exit?", "Warning");
+            Button@ cancelButton = messageBox.window.GetChild("CancelButton", true);
             cancelButton.visible = true;
             cancelButton.focus = true;
-            SubscribeToEvent(uiMessageBox, "MessageACK", "HandleMessageAcknowledgement");
+            SubscribeToEvent(messageBox, "MessageACK", "HandleMessageAcknowledgement");
             messageBoxCallback = @Exit;
             return false;
         }
@@ -461,6 +460,11 @@ bool Exit()
     return true;
 }
 
+void HandleExitRequested()
+{
+    Exit();
+}
+
 bool PickFile()
 {
     Menu@ menu = GetEventSender();
@@ -1335,7 +1339,6 @@ void UpdateDirtyUI()
 
 void HandleMessageAcknowledgement(StringHash eventType, VariantMap& eventData)
 {
-    uiMessageBox = null;
     if (eventData["Ok"].GetBool())
         messageBoxCallback();
     else

+ 6 - 6
Bin/Data/Scripts/Editor/EditorUIElement.as

@@ -161,11 +161,11 @@ bool CloseUILayout()
             UIElement@ element = GetTopLevelUIElement(selectedUIElements[i]);
             if (element !is null && element.vars[MODIFIED_VAR].GetBool())
             {
-                uiMessageBox = MessageBox("UI layout has been modified.\nContinue to close?", "Warning");
-                Button@ cancelButton = uiMessageBox.window.GetChild("CancelButton", true);
+                MessageBox@ messageBox = MessageBox("UI layout has been modified.\nContinue to close?", "Warning");
+                Button@ cancelButton = messageBox.window.GetChild("CancelButton", true);
                 cancelButton.visible = true;
                 cancelButton.focus = true;
-                SubscribeToEvent(uiMessageBox, "MessageACK", "HandleMessageAcknowledgement");
+                SubscribeToEvent(messageBox, "MessageACK", "HandleMessageAcknowledgement");
                 messageBoxCallback = @CloseUILayout;
                 return false;
             }
@@ -204,11 +204,11 @@ bool CloseAllUILayouts()
             UIElement@ element = editorUIElement.children[i];
             if (element !is null && element.vars[MODIFIED_VAR].GetBool())
             {
-                uiMessageBox = MessageBox("UI layout has been modified.\nContinue to close?", "Warning");
-                Button@ cancelButton = uiMessageBox.window.GetChild("CancelButton", true);
+                MessageBox@ messageBox = MessageBox("UI layout has been modified.\nContinue to close?", "Warning");
+                Button@ cancelButton = messageBox.window.GetChild("CancelButton", true);
                 cancelButton.visible = true;
                 cancelButton.focus = true;
-                SubscribeToEvent(uiMessageBox, "MessageACK", "HandleMessageAcknowledgement");
+                SubscribeToEvent(messageBox, "MessageACK", "HandleMessageAcknowledgement");
                 messageBoxCallback = @CloseAllUILayouts;
                 return false;
             }