Browse Source

Working on Editor Shortcuts

Josh Engebretson 10 years ago
parent
commit
cd3a9c8931

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

@@ -508,7 +508,7 @@ static bool InvokeShortcut(int key, SPECIAL_KEY special_key, MODIFIER_KEYS modif
         id = TBIDC("findnext");
     else if (upper_key == 'P')
         id = TBIDC("play");
-    else if (upper_key == 'B')
+    else if (upper_key == 'I')
         id = TBIDC("beautify");
     else if (special_key == TB_KEY_PAGE_UP)
         id = TBIDC("prev_doc");

+ 2 - 0
Source/AtomicEditor/Source/AEApplication.cpp

@@ -26,6 +26,7 @@
 #include <Atomic/Graphics/Renderer.h>
 
 #include "AEEditorStrings.h"
+#include "AEEditorShortcuts.h"
 #include "Project/ProjectUtils.h"
 #include "Subprocess/AESubprocessSystem.h"
 #include "Build/BuildSystem.h"
@@ -96,6 +97,7 @@ void AEApplication::Start()
     input->SetMouseVisible(true);
 
     context_->RegisterSubsystem(new EditorStrings(context_));
+    context_->RegisterSubsystem(new EditorShortcuts(context_));
     context_->RegisterSubsystem(new ProjectUtils(context_));
     context_->RegisterSubsystem(new Javascript(context_));
     context_->RegisterSubsystem(new SubprocessSystem(context_));

+ 6 - 0
Source/AtomicEditor/Source/AEEditor.cpp

@@ -309,6 +309,12 @@ void Editor::HandleExitRequested(StringHash eventType, VariantMap& eventData)
     }
 
     mainframe_ = 0;
+    player_ = 0;
+    project_ = 0;
+    javascript_ = 0;
+    aejavascript_ = 0;
+    aepreferences_ = 0;
+
     context_->RemoveSubsystem(Javascript::GetBaseTypeStatic());
 
     SendEvent(E_EDITORSHUTDOWN);

+ 0 - 0
Source/AtomicEditor/Source/AEEditorCommands.cpp


+ 0 - 0
Source/AtomicEditor/Source/AEEditorCommands.h


+ 211 - 0
Source/AtomicEditor/Source/AEEditorShortcuts.cpp

@@ -0,0 +1,211 @@
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// Please see LICENSE.md in repository root for license information
+// https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#include "AtomicEditor.h"
+
+#include <rapidjson/document.h>
+#include "rapidjson/prettywriter.h"
+#include "rapidjson/filestream.h"
+
+#include <Atomic/Core/Context.h>
+#include <Atomic/IO/FileSystem.h>
+#include <Atomic/IO/Log.h>
+#include <Atomic/IO/File.h>
+#include <Atomic/Input/Input.h>
+#include <Atomic/Input/InputEvents.h>
+
+#include "UI/UIMainFrame.h"
+#include "UI/UIResourceFrame.h"
+#include "UI/Modal/UIModalOps.h"
+
+#include "AEEditor.h"
+#include "AEEvents.h"
+#include "AEEditorShortcuts.h"
+
+using namespace rapidjson;
+
+namespace AtomicEditor
+{
+
+EditorShortcuts::EditorShortcuts(Context* context) :
+    Object(context)
+{
+    SubscribeToEvent(E_KEYDOWN, HANDLER(EditorShortcuts, HandleKeyDown));
+    SubscribeToEvent(E_KEYUP, HANDLER(EditorShortcuts, HandleKeyUp));
+    SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(EditorShortcuts, HandleEditorShutdown));
+}
+
+EditorShortcuts::~EditorShortcuts()
+{
+
+}
+
+void EditorShortcuts::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
+{
+    context_->RemoveSubsystem(GetType());
+}
+
+bool EditorShortcuts::IsProjectLoaded()
+{
+    Editor* editor = context_->GetSubsystem<Editor>();
+    return editor->GetProject() != NULL;
+}
+
+void EditorShortcuts::InvokePlayStop()
+{
+    if (!IsProjectLoaded())
+        return;
+
+    Editor* editor = context_->GetSubsystem<Editor>();
+
+    if (!editor->IsPlayingProject())
+    {
+        VariantMap eventData;
+        eventData[EditorPlayRequest::P_MODE] = (unsigned) AE_PLAYERMODE_WIDGET;
+        SendEvent(E_EDITORPLAYREQUEST, eventData);
+    }
+    else
+    {
+        SendEvent(E_EDITORPLAYSTOP);
+    }
+}
+
+void EditorShortcuts::InvokeResourceFrameShortcut(const String& id)
+{
+    if (!IsProjectLoaded())
+        return;
+
+    MainFrame* frame = GetSubsystem<MainFrame>();
+    ResourceFrame* resourceFrame = frame->GetResourceFrame();
+    TBWidgetEvent ev(EVENT_TYPE_SHORTCUT);
+    ev.ref_id = TBIDC(id.CString());
+    resourceFrame->OnEvent(ev);
+
+}
+
+void EditorShortcuts::InvokeFileSave()
+{
+    InvokeResourceFrameShortcut("save");
+}
+
+void EditorShortcuts::InvokeFileClose()
+{
+    InvokeResourceFrameShortcut("close");
+}
+
+void EditorShortcuts::InvokeEditCut()
+{
+    InvokeResourceFrameShortcut("cut");
+}
+
+void EditorShortcuts::InvokeEditCopy()
+{
+    InvokeResourceFrameShortcut("copy");
+}
+
+void EditorShortcuts::InvokeEditPaste()
+{
+    InvokeResourceFrameShortcut("paste");
+}
+
+void EditorShortcuts::InvokeEditSelectAll()
+{
+    InvokeResourceFrameShortcut("selectall");
+}
+
+void EditorShortcuts::InvokeEditUndo()
+{
+    InvokeResourceFrameShortcut("undo");
+}
+
+void EditorShortcuts::InvokeEditRedo()
+{
+    InvokeResourceFrameShortcut("redo");
+}
+
+void EditorShortcuts::InvokeEditFind()
+{
+    InvokeResourceFrameShortcut("find");
+}
+
+void EditorShortcuts::InvokeEditFindNext()
+{
+    InvokeResourceFrameShortcut("findnext");
+}
+
+void EditorShortcuts::InvokeEditFindPrev()
+{
+    InvokeResourceFrameShortcut("findprev");
+}
+
+void EditorShortcuts::InvokeEditFormatCode()
+{
+    InvokeResourceFrameShortcut("beautify");
+}
+
+void EditorShortcuts::InvokeBuild()
+{
+    if (!IsProjectLoaded())
+        return;
+
+    UIModalOps* ops = GetSubsystem<UIModalOps>();
+
+    if (!ops->ModalActive())
+        ops->ShowBuild();
+
+}
+
+void EditorShortcuts::InvokeBuildSettings()
+{
+    if (!IsProjectLoaded())
+        return;
+
+    UIModalOps* ops = GetSubsystem<UIModalOps>();
+
+    if (!ops->ModalActive())
+        ops->ShowBuildSettings();
+
+}
+
+void EditorShortcuts::HandleKeyDown(StringHash eventType, VariantMap& eventData)
+{
+    using namespace KeyDown;
+
+    Input* input = context_->GetSubsystem<Input>();
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+    bool cmdKey = (input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL));
+#else
+    bool cmdKey = (input->GetKeyDown(KEY_LGUI) || input->GetKeyDown(KEY_RGUI));
+#endif
+
+    int keycode = eventData[P_KEY].GetInt();
+    int qualifiers = eventData[P_QUALIFIERS].GetInt();
+
+
+    if (cmdKey && keycode == KEY_P)
+    {
+        InvokePlayStop();
+    }
+    else if (cmdKey && (qualifiers & QUAL_SHIFT) && keycode == KEY_B)
+    {
+        InvokeBuildSettings();
+    }
+    else if (cmdKey && keycode == KEY_B)
+    {
+        InvokeBuild();
+    }
+
+
+}
+
+void EditorShortcuts::HandleKeyUp(StringHash eventType, VariantMap& eventData)
+{
+    using namespace KeyUp;
+
+
+}
+
+
+}

+ 61 - 0
Source/AtomicEditor/Source/AEEditorShortcuts.h

@@ -0,0 +1,61 @@
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// Please see LICENSE.md in repository root for license information
+// https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+#include <Atomic/IO/FileSystem.h>
+
+using namespace Atomic;
+
+namespace AtomicEditor
+{
+
+class EditorShortcuts : public Object
+{
+
+    OBJECT(EditorShortcuts);
+
+public:
+
+    /// Construct.
+    EditorShortcuts(Context* context);
+    /// Destruct.
+    ~EditorShortcuts();
+
+    void InvokeFileClose();
+    void InvokeFileSave();
+
+    void InvokeEditCut();
+    void InvokeEditCopy();
+    void InvokeEditPaste();
+    void InvokeEditSelectAll();
+
+    void InvokeEditUndo();
+    void InvokeEditRedo();
+
+    void InvokeEditFind();
+    void InvokeEditFindNext();
+    void InvokeEditFindPrev();
+
+    void InvokeEditFormatCode();
+
+    void InvokeBuild();
+    void InvokeBuildSettings();
+
+    void InvokePlayStop();
+
+private:
+
+    bool IsProjectLoaded();
+
+    void InvokeResourceFrameShortcut(const String& id);
+
+    void HandleKeyDown(StringHash eventType, VariantMap& eventData);
+    void HandleKeyUp(StringHash eventType, VariantMap& eventData);
+    void HandleEditorShutdown(StringHash eventType, VariantMap& eventData);
+};
+
+
+}

+ 1 - 0
Source/AtomicEditor/Source/AEEditorStrings.cpp

@@ -43,6 +43,7 @@ void EditorStrings::InitializeStrings()
     stringLookup_[ShortcutCut] = "⌘X";
     stringLookup_[ShortcutCopy] = "⌘C";
     stringLookup_[ShortcutPaste] = "⌘V";
+    stringLookup_[ShortcutSelectAll] = "⌘A";
     stringLookup_[ShortcutFind] = "⌘F";
     stringLookup_[ShortcutFindNext] = "⌘G";
     stringLookup_[ShortcutFindPrev] = "⇧⌘G";

+ 1 - 0
Source/AtomicEditor/Source/AEEditorStrings.h

@@ -29,6 +29,7 @@ public:
         ShortcutCut,
         ShortcutCopy,
         ShortcutPaste,
+        ShortcutSelectAll,
         ShortcutFind,
         ShortcutFindNext,
         ShortcutFindPrev,

+ 5 - 7
Source/AtomicEditor/Source/Editors/JSResourceEditor.cpp

@@ -273,16 +273,9 @@ bool JSResourceEditor::OnEvent(const TBWidgetEvent &ev)
             file.Write((void*) text.CStr(), text.Length());
             file.Close();
 
-            ResourceCache* cache = GetSubsystem<ResourceCache>();
-
-            //SharedPtr<File> jsFile (GetSubsystem<ResourceCache>()->GetFile<File>(fullpath_));
-            //cache->ReloadResource(jsFile);
-
             String filename = GetFileNameAndExtension(fullpath_);
             button_->SetText(filename.CString());
-
             modified_ = false;
-
             SendEvent(E_JAVASCRIPTSAVED);
 
             return true;
@@ -330,6 +323,11 @@ bool JSResourceEditor::OnEvent(const TBWidgetEvent &ev)
                 }
             }
         }
+        else if (ev.ref_id == TBIDC("cut") || ev.ref_id == TBIDC("copy") || ev.ref_id == TBIDC("paste")
+                 || ev.ref_id == TBIDC("selectall") || ev.ref_id == TBIDC("undo") || ev.ref_id == TBIDC("redo") )
+        {
+            editField_->OnEvent(ev);
+        }
     }
 
     if (ev.type == EVENT_TYPE_CLICK)

+ 0 - 2
Source/AtomicEditor/Source/Editors/JSResourceEditor.h

@@ -52,8 +52,6 @@ private:
     TBEditField* editField_;
     JSAutocomplete* autocomplete_;
 
-
-
     float textDelta_;
     bool textDirty_;
 

+ 6 - 0
Source/AtomicEditor/Source/Editors/TextResourceEditor.cpp

@@ -164,6 +164,12 @@ bool TextResourceEditor::OnEvent(const TBWidgetEvent &ev)
 
             finder->Find(text, flags);
         }
+        else if (ev.ref_id == TBIDC("cut") || ev.ref_id == TBIDC("copy") || ev.ref_id == TBIDC("paste")
+                 || ev.ref_id == TBIDC("selectall") || ev.ref_id == TBIDC("undo") || ev.ref_id == TBIDC("redo") )
+        {
+            editField_->OnEvent(ev);
+        }
+
     }
 
     if (ev.type == EVENT_TYPE_CLICK)

+ 58 - 52
Source/AtomicEditor/Source/UI/UIMainFrame.cpp

@@ -11,8 +11,6 @@
 #include <Atomic/UI/TBUI.h>
 #include <Atomic/IO/Log.h>
 #include <Atomic/Core/Context.h>
-#include <Atomic/Input/Input.h>
-#include <Atomic/Input/InputEvents.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/GraphicsEvents.h>
 #include <Atomic/Resource/ResourceCache.h>
@@ -33,6 +31,7 @@
 #include "AEEvents.h"
 #include "AEEditor.h"
 #include "AEEditorStrings.h"
+#include "AEEditorShortcuts.h"
 #include "AEPreferences.h"
 #include "AEJavascript.h"
 #include "Player/AEPlayer.h"
@@ -118,8 +117,6 @@ MainFrame::MainFrame(Context* context) :
     findtextwidget_ = new FindTextWidget(context_);
     UpdateFindTextWidget();
 
-    SubscribeToEvent(E_KEYDOWN, HANDLER(MainFrame, HandleKeyDown));
-    SubscribeToEvent(E_KEYUP, HANDLER(MainFrame, HandleKeyUp));
     SubscribeToEvent(E_SCREENMODE, HANDLER(MainFrame, HandleScreenMode));
     SubscribeToEvent(E_JAVASCRIPTSAVED, HANDLER(MainFrame, HandleJavascriptSaved));
     SubscribeToEvent(E_PLATFORMCHANGE, HANDLER(MainFrame, HandlePlatformChange));
@@ -170,14 +167,15 @@ void MainFrame::InitializeMenuSources()
     menuEditSource.AddItem(new MenubarItem("Cut", TBIDC("edit cut"),  EDITOR_STRING(ShortcutCut)));
     menuEditSource.AddItem(new MenubarItem("Copy", TBIDC("edit copy"),  EDITOR_STRING(ShortcutCopy)));
     menuEditSource.AddItem(new MenubarItem("Paste", TBIDC("edit paste"),  EDITOR_STRING(ShortcutPaste)));
+    menuEditSource.AddItem(new MenubarItem("Select All", TBIDC("edit select all"),  EDITOR_STRING(ShortcutSelectAll)));
     menuEditSource.AddItem(new MenubarItem("-"));
     menuEditSource.AddItem(new MenubarItem("Find", TBIDC("edit find"),  EDITOR_STRING(ShortcutFind)));
     menuEditSource.AddItem(new MenubarItem("Find Next", TBIDC("edit find next"),  EDITOR_STRING(ShortcutFindNext)));
     menuEditSource.AddItem(new MenubarItem("Find Prev", TBIDC("edit find prev"),  EDITOR_STRING(ShortcutFindPrev)));
     menuEditSource.AddItem(new MenubarItem("-"));
-    menuEditSource.AddItem(new MenubarItem("Format Code", TBIDC("format code"),  EDITOR_STRING(ShortcutBeautify)));
+    menuEditSource.AddItem(new MenubarItem("Format Code", TBIDC("edit format code"),  EDITOR_STRING(ShortcutBeautify)));
     menuEditSource.AddItem(new MenubarItem("-"));
-    menuEditSource.AddItem(new MenubarItem("Play", TBIDC("play"),  EDITOR_STRING(ShortcutPlay)));
+    menuEditSource.AddItem(new MenubarItem("Play", TBIDC("edit play"),  EDITOR_STRING(ShortcutPlay)));
 
     menuHelpSource.AddItem(new MenubarItem("API Documentation", TBIDC("help_api")));
     menuHelpSource.AddItem(new MenubarItem("-"));
@@ -263,44 +261,6 @@ bool MainFrame::UpdateJavascriptErrors()
 
 }
 
-void MainFrame::HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    using namespace KeyDown;
-
-    Input* input = context_->GetSubsystem<Input>();
-    Editor* editor = context_->GetSubsystem<Editor>();
-
-#ifdef ATOMIC_PLATFORM_WINDOWS
-    bool cmdKey = (input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL));
-#else
-    bool cmdKey = (input->GetKeyDown(KEY_LGUI) || input->GetKeyDown(KEY_RGUI));
-#endif
-
-    int keycode = eventData[P_KEY].GetInt();
-
-    if (cmdKey && keycode == KEY_P)
-    {
-        if (!editor->IsPlayingProject())
-        {
-            VariantMap eventData;
-            eventData[EditorPlayRequest::P_MODE] = (unsigned) AE_PLAYERMODE_WIDGET;
-            SendEvent(E_EDITORPLAYREQUEST, eventData);
-        }
-        else
-        {
-            SendEvent(E_EDITORPLAYSTOP);
-        }
-    }
-
-}
-
-void MainFrame::HandleKeyUp(StringHash eventType, VariantMap& eventData)
-{
-    using namespace KeyUp;
-
-
-}
-
 bool MainFrame::ResourceFrameVisible()
 {
     TBWidget *child;
@@ -480,6 +440,8 @@ bool MainFrame::HandleMenubarEvent(const TBWidgetEvent &ev)
 
 bool MainFrame::HandlePopupMenuEvent(const TBWidgetEvent &ev)
 {
+    EditorShortcuts* shortcuts = GetSubsystem<EditorShortcuts>();
+
     if (ev.type == EVENT_TYPE_CLICK)
     {
         Editor* editor = GetSubsystem<Editor>();
@@ -509,12 +471,19 @@ bool MainFrame::HandlePopupMenuEvent(const TBWidgetEvent &ev)
                     return true;
                 }
             }
-
             else if (ev.ref_id == TBIDC("close project"))
             {
                 //TODO: Confirmation
                 editor->CloseProject();
             }
+            else if (ev.ref_id == TBIDC("close file"))
+            {
+                shortcuts->InvokeFileClose();
+            }
+            else if (ev.ref_id == TBIDC("save file"))
+            {
+                shortcuts->InvokeFileSave();
+            }
 
             return true;
         }
@@ -555,16 +524,13 @@ bool MainFrame::HandlePopupMenuEvent(const TBWidgetEvent &ev)
 
         if (ev.target->GetID() == TBIDC("build popup"))
         {
-            if (!IsProjectLoaded())
-                return true;
-
             if (ev.ref_id == TBIDC("project_build_settings"))
             {
-                uiModalOps_->ShowBuildSettings();
+                shortcuts->InvokeBuildSettings();
             }
             else if (ev.ref_id == TBIDC("project_build"))
             {
-                uiModalOps_->ShowBuild();
+                shortcuts->InvokeBuild();
             }
 
             return true;
@@ -573,9 +539,49 @@ bool MainFrame::HandlePopupMenuEvent(const TBWidgetEvent &ev)
 
         if (ev.target->GetID() == TBIDC("edit popup"))
         {
-            if (ev.ref_id == TBIDC("format code"))
+            if (ev.ref_id == TBIDC("edit cut"))
             {
-
+                shortcuts->InvokeEditCut();
+            }
+            else if (ev.ref_id == TBIDC("edit copy"))
+            {
+                shortcuts->InvokeEditCopy();
+            }
+            else if (ev.ref_id == TBIDC("edit paste"))
+            {
+                shortcuts->InvokeEditPaste();
+            }
+            else if (ev.ref_id == TBIDC("edit select all"))
+            {
+                shortcuts->InvokeEditSelectAll();
+            }
+            else if (ev.ref_id == TBIDC("edit undo"))
+            {
+                shortcuts->InvokeEditUndo();
+            }
+            else if (ev.ref_id == TBIDC("edit redo"))
+            {
+                shortcuts->InvokeEditRedo();
+            }
+            else if (ev.ref_id == TBIDC("edit find"))
+            {
+                shortcuts->InvokeEditFind();
+            }
+            else if (ev.ref_id == TBIDC("edit find next"))
+            {
+                shortcuts->InvokeEditFindNext();
+            }
+            else if (ev.ref_id == TBIDC("edit find prev"))
+            {
+                shortcuts->InvokeEditFindPrev();
+            }
+            else if (ev.ref_id == TBIDC("edit format code"))
+            {
+                shortcuts->InvokeEditFormatCode();
+            }
+            else if (ev.ref_id == TBIDC("edit play"))
+            {
+                shortcuts->InvokePlayStop();
             }
 
             return true;

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

@@ -85,8 +85,6 @@ private:
 
     void UpdateFindTextWidget();
 
-    void HandleKeyDown(StringHash eventType, VariantMap& eventData);
-    void HandleKeyUp(StringHash eventType, VariantMap& eventData);
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);
     void HandleJavascriptSaved(StringHash eventType, VariantMap& eventData);
     void HandlePlatformChange(StringHash eventType, VariantMap& eventData);

+ 2 - 0
Source/AtomicEditor/Source/UI/UIProjectFrame.cpp

@@ -83,6 +83,8 @@ void ProjectFrame::InitializeMenuSources()
     item->SetSkinImage(TBIDC("JavascriptBitmap"));
     menuCreateSource.AddItem(item);
 
+    menuCreateSource.AddItem(new MenubarItem("-"));
+
     item = new MenubarItem("2D Level", TBIDC("create_2d_level"));
     item->SetSkinImage(TBIDC("2DLevelBitmap"));
     menuCreateSource.AddItem(item);