Browse Source

Check for unsaved changes before closing whole project or editor

rsredsq 10 years ago
parent
commit
e3e2ca793c

+ 28 - 15
Script/AtomicEditor/editor/Editor.ts

@@ -27,6 +27,8 @@ class Editor extends Atomic.ScriptObject {
         // limit the framerate to limit CPU usage
         Atomic.getEngine().maxFps = 60;
 
+        Atomic.getEngine().autoExit = false;
+
         Editor.instance = this;
 
         this.initUI();
@@ -47,7 +49,7 @@ class Editor extends Atomic.ScriptObject {
             Atomic.graphics.windowTitle = "AtomicEditor";
             this.handleProjectUnloaded(data)
         });
-        this.subscribeToEvent(EditorEvents.Quit, (data) => this.handleEditorEventQuit(data));
+
         this.subscribeToEvent("ExitRequested", (data) => this.handleExitRequested(data));
 
         this.subscribeToEvent("ProjectLoaded", (data) => {
@@ -82,15 +84,29 @@ class Editor extends Atomic.ScriptObject {
         return system.loadProject(event.path);
     }
 
+    checkIfEverythingClosed() {
+        var editor = EditorUI.getCurrentResourceEditor();
+        if (!editor) {
+            this.sendEvent("AllResourceEditorsClosed");
+            return;
+        }
+        this.subscribeToEvent("ResourceEditorClosed", (data) => {
+            this.checkIfEverythingClosed();
+        });
+        editor.requestClose();
+    }
+
     handleEditorCloseProject(event) {
-        var system = ToolCore.getToolSystem();
+        this.subscribeToEvent("AllResourceEditorsClosed", (_) => {
+            var system = ToolCore.getToolSystem();
 
-        if (system.project) {
+            if (system.project) {
 
-            system.closeProject();
-
-        }
+                system.closeProject();
 
+            }
+        });
+        this.checkIfEverythingClosed();
     }
 
     handleProjectUnloaded(event) {
@@ -123,15 +139,12 @@ class Editor extends Atomic.ScriptObject {
 
     // event handling
     handleExitRequested(data) {
-        Preferences.getInstance().write();
-        EditorUI.shutdown();
-
-    }
-
-    handleEditorEventQuit(data) {
-
-        this.sendEvent("ExitRequested");
-
+      this.subscribeToEvent("AllResourceEditorsClosed", (_) => {
+          Preferences.getInstance().write();
+          EditorUI.shutdown();
+          Atomic.getEngine().exit();
+      });
+      this.checkIfEverythingClosed();
     }
 
 

+ 0 - 2
Script/AtomicEditor/editor/EditorEvents.ts

@@ -5,8 +5,6 @@
 // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
 //
 
-export const Quit = "EditorEventQuit";
-
 export const ModalError = "ModalError";
 export interface ModalErrorEvent {
 

+ 1 - 1
Script/AtomicEditor/ui/frames/menus/MainFrameMenu.ts

@@ -46,7 +46,7 @@ class MainFrameMenu extends Atomic.ScriptObject {
 
             if (refid == "quit") {
 
-                Atomic.ui.requestExit();
+                this.sendEvent("ExitRequested");
                 return true;
 
             }

+ 1 - 1
Script/AtomicEditor/ui/modal/license/ActivationWindow.ts

@@ -63,7 +63,7 @@ class ActivationWindow extends ModalWindow {
 
             if (id == "quit") {
 
-                this.sendEvent(EditorEvents.Quit);
+                this.sendEvent("ExitRequested");
                 return true;
 
             } else if (id == "get_key") {

+ 1 - 1
Script/AtomicEditor/ui/modal/license/EULAWindow.ts

@@ -52,7 +52,7 @@ class EULAWindow extends ModalWindow {
 
             if (id == "quit") {
 
-                this.sendEvent(EditorEvents.Quit);
+                this.sendEvent("ExitRequested");
                 return true;
 
             } else if (id == "ok") {

+ 1 - 1
Source/Atomic/UI/UI.cpp

@@ -150,7 +150,7 @@ void UI::HandleExitRequested(StringHash eventType, VariantMap& eventData)
 
 void UI::Shutdown()
 {
-    SetInputDisabled(true);
+    //SetInputDisabled(true);
 }
 
 void UI::Initialize(const String& languageFile)

+ 0 - 6
Source/AtomicEditor/Application/AEEditorApp.cpp

@@ -55,7 +55,6 @@ void AEEditorApp::Start()
     ui->Initialize("AtomicEditor/resources/language/lng_en.tb.txt");
 
     SubscribeToEvent(E_JSERROR, HANDLER(AEEditorApp, HandleJSError));
-    SubscribeToEvent(E_EXITREQUESTED, HANDLER(AEEditorApp, HandleExitRequested));
 
     jsapi_init_editor(vm_);
 
@@ -118,11 +117,6 @@ void AEEditorApp::Stop()
     AEEditorCommon::Stop();
 }
 
-void AEEditorApp::HandleExitRequested(StringHash eventType, VariantMap& eventData)
-{
-
-}
-
 void AEEditorApp::HandleJSError(StringHash eventType, VariantMap& eventData)
 {
     using namespace JSError;

+ 7 - 1
Source/AtomicEditor/Editors/ResourceEditor.cpp

@@ -12,6 +12,8 @@
 
 #include <TurboBadger/tb_message_window.h>
 
+#include "ResourceEditorEvents.h"
+
 #include "ResourceEditor.h"
 
 //#include "../UI/UIMainFrame.h"
@@ -47,7 +49,6 @@ public:
         }
         else
         {
-            editor_->Close();
             return true;
         }
     }
@@ -60,8 +61,12 @@ public:
             {
                 if (ev.ref_id == TBIDC("TBMessageWindow.ok"))
                 {
+                    SharedPtr<ResourceEditor> keepalive(editor_);
                     container_->OnEvent(ev);
                     editor_->Close();
+                    VariantMap editorClosedEvent;
+                    editorClosedEvent[ResourceEditorClosed::P_RESOURCEEDITOR] = editor_;
+                    editor_->SendEvent(E_RESOURCEEDITORCLOSED, editorClosedEvent);
                 }
                 else
                 {
@@ -74,6 +79,7 @@ public:
                 if (RequestClose())
                 {
                     container_->OnEvent(ev);
+                    editor_->Close();
                     return true;
                 }
             }

+ 20 - 0
Source/AtomicEditor/Editors/ResourceEditorEvents.h

@@ -0,0 +1,20 @@
+//
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// LICENSE: Atomic Game Engine Editor and Tools EULA
+// Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
+// license information: https://github.com/AtomicGameEngine/AtomicGameEngine
+//
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+#include "ResourceEditor.h"
+
+namespace AtomicEditor
+{
+EVENT(E_RESOURCEEDITORCLOSED, ResourceEditorClosed)
+{
+    PARAM(P_RESOURCEEDITOR, ResourceEditor);            // ResourceEditor
+}
+}