Code::Blocks  SVN r11506
manager.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  */
5 
6 #ifndef MANAGER_H
7 #define MANAGER_H
8 
9 #include <map>
10 #include <vector>
11 
12 #ifndef WX_PRECOMP
13 # ifdef __WXMSW__
14 # include <wx/msw/wrapwin.h> // Needed to prevent Yield define bug.
15 # endif
16 #endif
17 #include <wx/event.h>
18 #include <wx/cmdline.h>
19 
20 #include "settings.h"
21 #include "sdk_events.h"
22 #include "cbfunctor.h"
23 #include "cbexception.h"
24 
25 // forward decls
26 class wxFrame;
27 class wxWindow;
28 class ProjectManager;
29 class EditorManager;
30 class DebuggerManager;
31 class LogManager;
32 class PluginManager;
33 class ToolsManager;
34 class MacrosManager;
35 class PersonalityManager;
36 class wxMenu;
37 class wxMenuBar;
38 class wxToolBar;
40 class ScriptingManager;
41 class ConfigManager;
42 class FileManager;
43 class ColourManager;
44 class CCManager;
45 class cbSearchResultsLog;
46 
47 
49 {
51  static bool m_AppShuttingDown;
52  static bool m_AppStartedUp;
53  static bool m_BlockYields;
54  static bool m_IsBatch;
56 
57  Manager();
58  ~Manager();
59 
60  void OnMenu(wxCommandEvent& event);
61 
62 public:
63  static void SetAppStartedUp(bool app_started_up);
64  static void SetAppShuttingDown(bool app_shutting_down);
65  static void SetBatchBuild(bool is_batch);
66  static bool IsBatchBuild() { return m_IsBatch; }
68  static void BlockYields(bool block);
70  static void Yield();
71  static void ProcessPendingEvents();
72  static void Shutdown();
73 
74  bool ProcessEvent(CodeBlocksEvent& event);
75  bool ProcessEvent(CodeBlocksDockEvent& event);
76  bool ProcessEvent(CodeBlocksLayoutEvent& event);
77  bool ProcessEvent(CodeBlocksLogEvent& event);
78 
79 
83  static Manager* Get();
84 
86  static void Free();
87 
88  wxFrame* GetAppFrame() const;
89  wxWindow* GetAppWindow() const;
90 
91  static bool IsAppShuttingDown();
92  static bool IsAppStartedUp();
93 
114  ProjectManager* GetProjectManager() const;
115  EditorManager* GetEditorManager() const;
116  LogManager* GetLogManager() const;
117  PluginManager* GetPluginManager() const;
118  ToolsManager* GetToolsManager() const;
119  MacrosManager* GetMacrosManager() const;
120  PersonalityManager* GetPersonalityManager() const;
121  UserVariableManager* GetUserVariableManager() const;
122  ScriptingManager* GetScriptingManager() const;
123  ConfigManager* GetConfigManager(const wxString& name_space) const;
124  FileManager* GetFileManager() const;
125  DebuggerManager* GetDebuggerManager() const;
126  ColourManager* GetColourManager() const;
127  CCManager* GetCCManager() const;
128 
129 
132  static void InitXRC(bool force=false);
134  static void LoadXRC(wxString relpath);
135  static bool LoadResource(const wxString& file);
136 
138  static wxMenuBar* LoadMenuBar(wxString resid, bool createonfailure = false);
140  static wxMenu* LoadMenu(wxString menu_id, bool createonfailure = false);
142  static wxToolBar* LoadToolBar(wxFrame *parent, wxString resid, bool defaultsmall = true);
143 
144  // Do not use this, use Get()
145  static Manager* Get(wxFrame* appWindow);
146 
147  wxToolBar* CreateEmptyToolbar();
148  static void AddonToolBar(wxToolBar* toolBar,wxString resid);
149  static bool isToolBar16x16(wxToolBar* toolBar);
150 
151  static wxCmdLineParser* GetCmdLineParser();
152 
153  // event sinks
154  void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksEvent>* functor);
155  void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksDockEvent>* functor);
156  void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksLayoutEvent>* functor);
157  void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksLogEvent>* functor);
158  void RemoveAllEventSinksFor(void* owner);
159 
161  cbSearchResultsLog* GetSearchResultLogger() const { return m_SearchResultLog; }
163  void SetSearchResultLogger(cbSearchResultsLog *log) { m_SearchResultLog = log; }
164 
165 private:
166  // event sinks
167  typedef std::vector< IEventFunctorBase<CodeBlocksEvent>* > EventSinksArray;
168  typedef std::map< wxEventType, EventSinksArray > EventSinksMap;
169  typedef std::vector< IEventFunctorBase<CodeBlocksDockEvent>* > DockEventSinksArray;
170  typedef std::map< wxEventType, DockEventSinksArray > DockEventSinksMap;
171  typedef std::vector< IEventFunctorBase<CodeBlocksLayoutEvent>* > LayoutEventSinksArray;
172  typedef std::map< wxEventType, LayoutEventSinksArray > LayoutEventSinksMap;
173  typedef std::vector< IEventFunctorBase<CodeBlocksLogEvent>* > LogEventSinksArray;
174  typedef std::map< wxEventType, LogEventSinksArray > LogEventSinksMap;
175 
176  EventSinksMap m_EventSinks;
177  DockEventSinksMap m_DockEventSinks;
178  LayoutEventSinksMap m_LayoutEventSinks;
179  LogEventSinksMap m_LogEventSinks;
181 };
182 
183 template <class MgrT> class DLLIMPORT Mgr
184 {
185  static MgrT *instance;
186  static bool isShutdown;
187  explicit Mgr(const Mgr<MgrT>&) { ; };
188  Mgr<MgrT>& operator=(Mgr<MgrT> const&) { ; };
189 
190 protected:
191 
192  Mgr() { assert(Mgr<MgrT>::instance == nullptr); }
193  virtual ~Mgr() { Mgr<MgrT>::instance = nullptr; }
194 
195 public:
196 
197  static bool Valid() { return instance; }
198 
199  static MgrT* Get()
200  {
201  if (instance == nullptr)
202  {
203  if (isShutdown == false)
204  instance = new MgrT();
205  else
206  cbAssert(false && "Calling Get after the subsystem has been shutdown is an error!");
207  }
208  return instance;
209  }
210 
211  static void Free()
212  {
213  isShutdown = true;
214  delete instance;
215  instance = nullptr;
216  }
217 };
218 
219 #endif // MANAGER_H
Mgr(const Mgr< MgrT > &)
Definition: manager.h:187
cbSearchResultsLog * m_SearchResultLog
Definition: manager.h:180
static bool m_AppShuttingDown
Definition: manager.h:51
Manage different personalities.
Event used to request from the main app to add a log.
Definition: sdk_events.h:182
Event used to request from the main app to add a window to the docking system.
Definition: sdk_events.h:83
std::vector< IEventFunctorBase< CodeBlocksLayoutEvent > *> LayoutEventSinksArray
Definition: manager.h:171
static MgrT * Get()
Definition: manager.h:199
std::vector< IEventFunctorBase< CodeBlocksEvent > *> EventSinksArray
Definition: manager.h:167
std::map< wxEventType, DockEventSinksArray > DockEventSinksMap
Definition: manager.h:170
static bool m_AppStartedUp
Definition: manager.h:52
static bool m_IsBatch
Definition: manager.h:54
A generic Code::Blocks event.
Definition: sdk_events.h:20
static bool isShutdown
Definition: manager.h:186
wxFrame * m_pAppWindow
Definition: manager.h:50
#define DLLIMPORT
Definition: settings.h:16
PluginManager manages plugins.
Definition: pluginmanager.h:76
std::map< wxEventType, LogEventSinksArray > LogEventSinksMap
Definition: manager.h:174
static bool m_BlockYields
Definition: manager.h:53
LayoutEventSinksMap m_LayoutEventSinks
Definition: manager.h:178
LogEventSinksMap m_LogEventSinks
Definition: manager.h:179
static bool Valid()
Definition: manager.h:197
Base abstract event functor class.
Definition: cbfunctor.h:30
DockEventSinksMap m_DockEventSinks
Definition: manager.h:177
std::vector< IEventFunctorBase< CodeBlocksDockEvent > *> DockEventSinksArray
Definition: manager.h:169
static bool IsBatchBuild()
Definition: manager.h:66
Definition: manager.h:183
Code Completion Plugin Manager.
Definition: ccmanager.h:47
std::map< wxEventType, EventSinksArray > EventSinksMap
Definition: manager.h:168
#define cbAssert(expr)
Definition: cbexception.h:48
std::map< wxEventType, LayoutEventSinksArray > LayoutEventSinksMap
Definition: manager.h:172
static void Free()
Definition: manager.h:211
std::vector< IEventFunctorBase< CodeBlocksLogEvent > *> LogEventSinksArray
Definition: manager.h:173
The entry point singleton for working with projects.
Provides scripting in Code::Blocks.
EventSinksMap m_EventSinks
Definition: manager.h:176
static MgrT * instance
Definition: manager.h:185
Mgr()
Definition: manager.h:192
Mgr< MgrT > & operator=(Mgr< MgrT > const &)
Definition: manager.h:188
void SetSearchResultLogger(cbSearchResultsLog *log)
Sets the pointer to the search result logger, users must not call this method.
Definition: manager.h:163
cbSearchResultsLog * GetSearchResultLogger() const
Returns pointer to the search result logger, might be nullptr or hidden.
Definition: manager.h:161
int wxEventType
virtual ~Mgr()
Definition: manager.h:193
static wxCmdLineParser m_CmdLineParser
Definition: manager.h:55
Event used to request from the main app to manage the view layouts.
Definition: sdk_events.h:158