1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef TrenchBroom_ActionManager 21 #define TrenchBroom_ActionManager 22 23 #include "View/ActionContext.h" 24 #include "View/ViewShortcut.h" 25 26 class wxAcceleratorTable; 27 class wxMenu; 28 class wxMenuBar; 29 30 namespace TrenchBroom { 31 namespace IO { 32 class Path; 33 } 34 35 namespace View { 36 class MenuBar; 37 class ActionMenuItem; 38 class KeyboardShortcutEntry; 39 40 class ActionManager { 41 public: 42 typedef std::vector<KeyboardShortcutEntry*> ShortcutEntryList; 43 private: 44 typedef std::vector<wxAcceleratorEntry> AcceleratorEntryList; 45 46 MenuBar* m_menuBar; 47 ViewShortcut::List m_viewShortcuts; 48 public: 49 static ActionManager& instance(); 50 ~ActionManager(); 51 52 53 static wxMenu* findRecentDocumentsMenu(const wxMenuBar* menuBar); 54 const ActionMenuItem* findMenuItem(int id) const; 55 56 void getShortcutEntries(ShortcutEntryList& entries); 57 String getJSTable(); 58 private: 59 void getKeysJSTable(StringStream& str); 60 void getMenuJSTable(StringStream& str); 61 void getActionJSTable(StringStream& str); 62 public: 63 wxMenuBar* createMenuBar(bool withShortcuts) const; 64 bool isMenuShortcutPreference(const IO::Path& path) const; 65 66 wxAcceleratorTable createViewAcceleratorTable(ActionContext context, ActionView view) const; 67 private: 68 void addViewActions(ActionContext context, ActionView view, AcceleratorEntryList& accelerators) const; 69 void addMenuActions(ActionContext context, ActionView view, AcceleratorEntryList& accelerators) const; 70 public: 71 void resetShortcutsToDefaults(); 72 private: 73 ActionManager(); 74 ActionManager(const ActionManager&); 75 ActionManager& operator=(const ActionManager&); 76 77 void createMenuBar(); 78 void createViewShortcuts(); 79 void createViewShortcut(const KeyboardShortcut& shortcut, int context, const Action& action2D, const Action& action3D); 80 void createViewShortcut(const KeyboardShortcut& shortcut, int context, const Action& action); 81 }; 82 } 83 } 84 85 #endif /* defined(TrenchBroom_ActionManager) */ 86