Browse Source

Exit improvements

Josh Engebretson 10 years ago
parent
commit
44aab51c7b

+ 9 - 1
Source/AtomicEditor/Source/AEEditor.cpp

@@ -40,7 +40,9 @@ namespace AtomicEditor
 
 Editor::Editor(Context* context) :
     Object(context),
-    currentPlatform_(AE_PLATFORM_UNDEFINED)
+    currentPlatform_(AE_PLATFORM_UNDEFINED),
+    requestExit_(false)
+
 {
     RegisterEditorLibrary(context_);
 
@@ -291,6 +293,12 @@ void Editor::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
         SendEvent(E_EDITORPLAYSTOP);
     }
 
+    if (requestExit_)
+    {
+        requestExit_ = false;
+        SendEvent(E_EXITREQUESTED);
+    }
+
 }
 
 void Editor::HandleExitRequested(StringHash eventType, VariantMap& eventData)

+ 5 - 0
Source/AtomicEditor/Source/AEEditor.h

@@ -62,6 +62,9 @@ public:
     void RequestPlatformChange(AEEditorPlatform platform);
     AEEditorPlatform GetCurrentPlatform() { return currentPlatform_; }
 
+    /// Called from UI code such as MainFrame quit menu, caught in post update
+    void RequestExit() { requestExit_ = true; }
+
 private:
 
     void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
@@ -83,6 +86,8 @@ private:
 
     AEEditorPlatform currentPlatform_;
 
+    bool requestExit_;
+
 };
 
 /// Register Javascript library objects.

+ 5 - 4
Source/AtomicEditor/Source/Project/ProjectUtils.cpp

@@ -119,11 +119,12 @@ String ProjectUtils::GetAndroidSDKPath(const String& defaultPath)
 
 String ProjectUtils::NewProjectFileDialog()
 {
+
     String projectPath;
 
     nfdchar_t *outPath = NULL;
 
-    nfdresult_t result = NFD_ChooseDirectory( "Please create a new folder for the project",
+    nfdresult_t result = NFD_SaveDialog( "atomic",
                                 NULL,
                                 &outPath);
 
@@ -132,12 +133,12 @@ String ProjectUtils::NewProjectFileDialog()
         projectPath = outPath;
     }
 
+    GetSubsystem<Graphics>()->RaiseWindow();
+
     if (outPath)
         free(outPath);
 
-    GetSubsystem<Graphics>()->RaiseWindow();
-
-    return GetInternalPath(projectPath);
+    return projectPath;
 
 }
 

+ 22 - 22
Source/AtomicEditor/Source/UI/Modal/UINewProject.cpp

@@ -44,11 +44,8 @@ UINewProject::~UINewProject()
 
 }
 
-bool UINewProject::Create2DProject(const String& fullpath)
+bool UINewProject::Create2DProject(const String& projectPath, const String& filename)
 {
-    Vector<String> elements = fullpath.Split('/');
-    String projectName = elements.Back();
-
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
 #ifdef ATOMIC_PLATFORM_OSX
@@ -58,19 +55,16 @@ bool UINewProject::Create2DProject(const String& fullpath)
 #endif
 
     templateSourceDir += "/ProjectTemplates/Project2D";
-    fileSystem->CopyDir(templateSourceDir + "/Resources", fullpath + "/Resources");
+    fileSystem->CopyDir(templateSourceDir + "/Resources", projectPath + "/Resources");
 
-    File file(context_, fullpath + "/" + projectName + ".atomic", FILE_WRITE);
+    File file(context_, projectPath + "/" + filename + ".atomic", FILE_WRITE);
     file.Close();
 
     return true;
 }
 
-bool UINewProject::CreateEmptyProject(const String& fullpath)
+bool UINewProject::CreateEmptyProject(const String& projectPath, const String &filename)
 {
-    Vector<String> elements = fullpath.Split('/');
-    String projectName = elements.Back();
-
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
 #ifdef ATOMIC_PLATFORM_OSX
@@ -80,18 +74,17 @@ bool UINewProject::CreateEmptyProject(const String& fullpath)
 #endif
 
     templateSourceDir += "/ProjectTemplates/EmptyProject";
-    fileSystem->CopyDir(templateSourceDir + "/Resources", fullpath + "/Resources");
 
-    File file(context_, fullpath + "/" + projectName + ".atomic", FILE_WRITE);
+    fileSystem->CopyDir(templateSourceDir + "/Resources", projectPath + "/Resources");
+
+    File file(context_, projectPath + "/" + filename + ".atomic", FILE_WRITE);
     file.Close();
 
     return true;
 }
 
-bool UINewProject::Create3DProject(const String& fullpath)
+bool UINewProject::Create3DProject(const String& projectPath, const String &filename)
 {
-    Vector<String> elements = fullpath.Split('/');
-    String projectName = elements.Back();
 
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
@@ -102,9 +95,9 @@ bool UINewProject::Create3DProject(const String& fullpath)
 #endif
 
     templateSourceDir += "/ProjectTemplates/Project3D";
-    fileSystem->CopyDir(templateSourceDir + "/Resources", fullpath + "/Resources");
+    fileSystem->CopyDir(templateSourceDir + "/Resources", projectPath + "/Resources");
 
-    File file(context_, fullpath + "/" + projectName + ".atomic", FILE_WRITE);
+    File file(context_, projectPath + "/" + filename + ".atomic", FILE_WRITE);
     file.Close();
 
     return true;
@@ -141,11 +134,17 @@ bool UINewProject::OnEvent(const TBWidgetEvent &ev)
 
         if (projectType != -1)
         {
-            String projectPath = GetSubsystem<ProjectUtils>()->NewProjectFileDialog();
+            String fullProjectPath = GetSubsystem<ProjectUtils>()->NewProjectFileDialog();
 
-            if (!projectPath.Length())
+            if (!fullProjectPath.Length())
                 return true;
 
+            String projectPath;
+            String fileName;
+            String ext;
+
+            SplitPath(fullProjectPath, projectPath, fileName, ext);
+
             FileSystem* fileSystem = GetSubsystem<FileSystem>();
             if (!fileSystem->DirExists(projectPath))
             {
@@ -164,17 +163,18 @@ bool UINewProject::OnEvent(const TBWidgetEvent &ev)
             }
 
             bool result = false;
+
             if (projectType == 0)
             {
-                result = CreateEmptyProject(projectPath);
+                result = CreateEmptyProject(projectPath, fileName);
             }
             else if (projectType == 1)
             {
-                result = Create2DProject(projectPath);
+                result = Create2DProject(projectPath, fileName);
             }
             else if (projectType == 2)
             {
-                result = Create3DProject(projectPath);
+                result = Create3DProject(projectPath, fileName);
             }
 
             if (!result)

+ 3 - 3
Source/AtomicEditor/Source/UI/Modal/UINewProject.h

@@ -24,9 +24,9 @@ public:
 
 private:
 
-    bool CreateEmptyProject(const String& fullpath);
-    bool Create2DProject(const String& fullpath);
-    bool Create3DProject(const String& fullpath);
+    bool CreateEmptyProject(const String& projectPath, const String &filename);
+    bool Create2DProject(const String& projectPath, const String &filename);
+    bool Create3DProject(const String& projectPath, const String &filename);
 
 };
 

+ 20 - 11
Source/AtomicEditor/Source/UI/UIMainFrame.cpp

@@ -59,7 +59,7 @@ MainFrame::MainFrame(Context* context) :
     menuAtomicEditorSource.AddItem(new TBGenericStringItem("Quit", TBIDC("quit")));
 
     menuFileSource.AddItem(new TBGenericStringItem("New Project", TBIDC("new project")));
-    menuFileSource.AddItem(new TBGenericStringItem("Open Project", TBIDC("open project")));    
+    menuFileSource.AddItem(new TBGenericStringItem("Open Project", TBIDC("open project")));
     menuFileSource.AddItem(new TBGenericStringItem("Save Project", TBIDC("save project")));
     menuFileSource.AddItem(new TBGenericStringItem("-"));
     menuFileSource.AddItem(new TBGenericStringItem("Close Project", TBIDC("close project")));
@@ -73,7 +73,7 @@ MainFrame::MainFrame(Context* context) :
     menuEditSource.AddItem(new TBGenericStringItem("-"));
     menuEditSource.AddItem(new TBGenericStringItem("Find", TBIDC("edit find")));
     menuEditSource.AddItem(new TBGenericStringItem("-"));
-    menuEditSource.AddItem(new TBGenericStringItem("Format Code", TBIDC("format code")));    
+    menuEditSource.AddItem(new TBGenericStringItem("Format Code", TBIDC("format code")));
 
     menuResourcesSource.AddItem(new TBGenericStringItem("Create", &menuResourcesCreateSource));
     menuResourcesSource.AddItem(new TBGenericStringItem("-"));
@@ -158,7 +158,7 @@ MainFrame::MainFrame(Context* context) :
     resourceframe_ = new ResourceFrame(context_);
 
     // better way to do this? projectviewcontainer isn't a layout
-    wd = resourceframe_->GetWidgetDelegate();    
+    wd = resourceframe_->GetWidgetDelegate();
     wd->SetSize(rect.w, rect.h);
     //resourceviewcontainer->AddChild(wd);
 
@@ -413,12 +413,12 @@ bool MainFrame::IsProjectLoaded()
 
 bool MainFrame::OnEvent(const TBWidgetEvent &ev)
 {
+    Editor* editor = GetSubsystem<Editor>();
+
     if (ev.type == EVENT_TYPE_CLICK)
     {
         if (ev.target->GetID() == TBIDC("file popup"))
         {
-            Editor* editor = GetSubsystem<Editor>();
-
             if (ev.ref_id == TBIDC("new project"))
             {
                 if (editor->IsProjectLoaded())
@@ -472,7 +472,14 @@ bool MainFrame::OnEvent(const TBWidgetEvent &ev)
             else if (ev.ref_id == TBIDC("quit"))
             {
                 // TODO: confirmation
-                SendEvent(E_EXITREQUESTED);
+
+                // shenanigens, need to delete the popup on quit
+                // otherwise it is still live with a source at exit
+                ev.target->GetParent()->RemoveChild(ev.target);
+                delete ev.target;
+                TBWidgetEvent* eptr = (TBWidgetEvent*) &ev;
+                eptr->target = NULL;
+                editor->RequestExit();
                 return true;
             }
 
@@ -559,11 +566,11 @@ bool MainFrame::OnEvent(const TBWidgetEvent &ev)
             }
             else if (ev.ref_id == TBIDC("help_api"))
             {
-                #ifdef ATOMIC_PLATFORM_OSX
-                    String docSourceDir = fileSystem->GetAppBundleResourceFolder();
-                #else
-                    String docSourceDir = fileSystem->GetProgramDir();
-                #endif
+#ifdef ATOMIC_PLATFORM_OSX
+                String docSourceDir = fileSystem->GetAppBundleResourceFolder();
+#else
+                String docSourceDir = fileSystem->GetProgramDir();
+#endif
 
                 docSourceDir += "Docs/index.html";
 
@@ -588,7 +595,9 @@ bool MainFrame::OnEvent(const TBWidgetEvent &ev)
         if (ev.target->GetID() == TBIDC("menu atomic editor"))
         {
             if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("atomic editor popup")))
+            {
                 menu->Show(&menuAtomicEditorSource, TBPopupAlignment());
+            }
 
             return true;
         }

+ 1 - 0
Source/AtomicEditor/Source/UI/UIMainFrame.h

@@ -15,6 +15,7 @@ namespace tb
 
 class TBEditField;
 class TBLayout;
+class TBMenuWindow;
 
 }
 

+ 23 - 15
Source/AtomicEditor/Source/UI/UIWelcomeFrame.cpp

@@ -192,21 +192,21 @@ void WelcomeFrame::FillExamples()
 
     for (Value::ConstValueIterator itr = examples->value.Begin(); itr != examples->value.End(); itr++)
     {
-         if (!(*itr).IsObject())
+        if (!(*itr).IsObject())
             continue;
 
-         const Value::Member* name = (*itr).FindMember("name");
-         const Value::Member* desc = (*itr).FindMember("desc");
-         const Value::Member* screenshot = (*itr).FindMember("screenshot");
-         const Value::Member* folder = (*itr).FindMember("folder");
+        const Value::Member* name = (*itr).FindMember("name");
+        const Value::Member* desc = (*itr).FindMember("desc");
+        const Value::Member* screenshot = (*itr).FindMember("screenshot");
+        const Value::Member* folder = (*itr).FindMember("folder");
 
-         if (!name || !desc || !screenshot || !folder)
-             continue;
+        if (!name || !desc || !screenshot || !folder)
+            continue;
 
-         if (!name->value.IsString() || !desc->value.IsString() || !screenshot->value.IsString() || !folder->value.IsString())
-             continue;
+        if (!name->value.IsString() || !desc->value.IsString() || !screenshot->value.IsString() || !folder->value.IsString())
+            continue;
 
-         AddExample(name->value.GetString(), desc->value.GetString(), screenshot->value.GetString(), folder->value.GetString());
+        AddExample(name->value.GetString(), desc->value.GetString(), screenshot->value.GetString(), folder->value.GetString());
     }
 
 }
@@ -214,10 +214,17 @@ void WelcomeFrame::FillExamples()
 bool WelcomeFrame::HandleExampleCopy(const String& name, const String& exampleFolder, String& atomicProjectFile)\
 {
     Editor* editor = GetSubsystem<Editor>();
-    String projectPath = GetSubsystem<ProjectUtils>()->NewProjectFileDialog();
 
-    if (!projectPath.Length())
-        return false;
+    String fullProjectPath = GetSubsystem<ProjectUtils>()->NewProjectFileDialog();
+
+    if (!fullProjectPath.Length())
+        return true;
+
+    String projectPath;
+    String fileName;
+    String ext;
+
+    SplitPath(fullProjectPath, projectPath, fileName, ext);
 
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
@@ -249,8 +256,9 @@ bool WelcomeFrame::HandleExampleCopy(const String& name, const String& exampleFo
     }
 
     // example folder name and .atomic must match
-    atomicProjectFile = projectPath + "/" + exampleFolder + ".atomic";
-    result = fileSystem->Copy(exampleSourceDir + "/" + exampleFolder + ".atomic", atomicProjectFile);
+    atomicProjectFile = projectPath + fileName + ".atomic";
+    String sourceProjectFile = exampleSourceDir + "/" + exampleFolder + ".atomic";
+    result = fileSystem->Copy(sourceProjectFile , atomicProjectFile);
 
     if (!result)
     {