Code::Blocks  SVN r11506
main.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  */
5 
6 #ifndef MAIN_H
7 #define MAIN_H
8 
9 #include <map>
10 
11 #include <wx/aui/aui.h> // wxAuiManager
12 #include <wx/toolbar.h>
13 #include <wx/docview.h> // for wxFileHistory
14 #include <wx/notebook.h>
15 #include <wx/dynarray.h>
16 #include <cbeditor.h>
17 #include "manager.h"
18 #include "cbexception.h"
19 #include "cbplugin.h"
20 #include "find_replace.h"
21 #include "sdk_events.h"
22 #include "recentitemslist.h"
24 #include "scrollingdialog.h"
25 
26 WX_DECLARE_HASH_MAP(int, wxString, wxIntegerHash, wxIntegerEqual, PluginIDsMap);
27 WX_DECLARE_HASH_MAP(cbPlugin*, wxToolBar*, wxPointerHash, wxPointerEqual, PluginToolbarsMap);
28 WX_DECLARE_STRING_HASH_MAP(wxString, LayoutViewsMap);
29 
30 extern int idStartHerePageLink;
31 extern int idStartHerePageVarSubst;
32 
33 class cbAuiNotebook;
36 class InfoPane;
37 class wxGauge;
38 class ProjectManagerUI;
39 
41 {
43  ToolbarInfo(wxToolBar *toolbar_in, const wxAuiPaneInfo &paneInfo_in, int priority_in) :
44  paneInfo(paneInfo_in),
45  toolbar(toolbar_in),
46  priority(priority_in)
47  {
48  }
49 
50  bool operator<(const ToolbarInfo& b) const
51  {
52  return priority < b.priority;
53  }
54 
57  int priority;
58 };
59 
60 class MainFrame : public wxFrame
61 {
62  public:
63  // needed for binding with SqPlus
64  MainFrame& operator=(cb_unused const MainFrame& rhs) // prevent assignment operator
65  {
66  cbThrow(_T("Can't use MainFrame's operator="));
67  return *this;
68  }
69  private:
70  MainFrame(cb_unused const MainFrame& rhs); // prevent copy construction
71 
73  LayoutViewsMap m_LayoutViews;
74  LayoutViewsMap m_LayoutMessagePane;
75  bool LayoutDifferent(const wxString& layout1,const wxString& layout2,const wxString& delimiter=_("|"));
76  bool LayoutMessagePaneDifferent(const wxString& layout1,const wxString& layout2, bool checkSelection=false);
77  public:
79  MainFrame(wxWindow* parent = (wxWindow*)NULL);
80  ~MainFrame();
81 
82  bool Open(const wxString& filename, bool addToHistory = true);
83  bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
84  void ShowTips(bool forceShow = false);
85 
86  wxScrollingDialog* GetBatchBuildDialog(){ return m_pBatchBuildDialog; }
87 
88  // show a file-open dialog and return the selection
89  wxString ShowOpenFileDialog(const wxString& caption, const wxString& filter);
90  // open the filename (based on what it is)
91  bool OpenGeneric(const wxString& filename, bool addToHistory = true);
92 
93  void StartupDone();
94 
95  cbProjectManagerUI* GetProjectManagerUI() { return m_pPrjManUI; }
96  private:
97  // event handlers
98 
99  void OnEraseBackground(wxEraseEvent& event);
100  void OnSize(wxSizeEvent& event);
101  void OnApplicationClose(wxCloseEvent& event);
102  void OnStartHereLink(wxCommandEvent& event);
103 
104  // the two functions below are used to show context menu to toggle toolbar view status
105  // OnMouseRightUp is handler for right click on MainFrame's free area which is not covered by
106  // any sub panels, OnToolBarRightClick is used to response the mouse right click command
107  // on the toolbar.
108  void OnMouseRightUp(wxMouseEvent& event);
109  void OnToolBarRightClick(wxCommandEvent& event);
110 
111  // common function to show context menu for toggle toolbars
112  void PopupToggleToolbarMenu();
113  void SetChecksForViewToolbarsMenu(wxMenu &menu);
114 
115  // File->New submenu entries handler
116  void OnFileNewWhat(wxCommandEvent& event);
117 
118  void OnFileNew(wxCommandEvent& event);
119  void OnFileOpen(wxCommandEvent& event);
120  void OnFileReopenProject(wxCommandEvent& event);
121  void OnFileOpenRecentProjectClearHistory(wxCommandEvent& event);
122  void OnFileReopen(wxCommandEvent& event);
123  void OnFileOpenRecentClearHistory(wxCommandEvent& event);
124  void OnFileImportProjectDevCpp(wxCommandEvent& event);
125  void OnFileImportProjectMSVC(wxCommandEvent& event);
126  void OnFileImportProjectMSVCWksp(wxCommandEvent& event);
127  void OnFileImportProjectMSVS(wxCommandEvent& event);
128  void OnFileImportProjectMSVSWksp(wxCommandEvent& event);
129  void OnFileSave(wxCommandEvent& event);
130  void OnFileSaveAs(wxCommandEvent& event);
131  void OnFileSaveProject(wxCommandEvent& event);
132  void OnFileSaveProjectAs(wxCommandEvent& event);
133  void OnFileSaveProjectTemplate(wxCommandEvent& event);
134  void OnFileOpenDefWorkspace(wxCommandEvent& event);
135  void OnFileSaveWorkspace(wxCommandEvent& event);
136  void OnFileSaveWorkspaceAs(wxCommandEvent& event);
137  void OnFileSaveAll(wxCommandEvent& event);
138  void OnFileCloseWorkspace(wxCommandEvent& event);
139  void OnFileClose(wxCommandEvent& event);
140  void OnFileCloseAll(wxCommandEvent& event);
141  void OnFileCloseProject(wxCommandEvent& event);
142  void OnFilePrintSetup(wxCommandEvent& event);
143  void OnFilePrint(wxCommandEvent& event);
144  void OnFileQuit(wxCommandEvent& event);
145  void OnFileNext(wxCommandEvent& event);
146  void OnFilePrev(wxCommandEvent& event);
147 
148  void OnEditUndo(wxCommandEvent& event);
149  void OnEditRedo(wxCommandEvent& event);
150  void OnEditClearHistory(wxCommandEvent& event);
151  void OnEditCopy(wxCommandEvent& event);
152  void OnEditCut(wxCommandEvent& event);
153  void OnEditPaste(wxCommandEvent& event);
154  void OnEditSwapHeaderSource(wxCommandEvent& event);
155  void OnEditGotoMatchingBrace(wxCommandEvent& event);
156  void OnEditHighlightMode(wxCommandEvent& event);
157  void OnEditFoldAll(wxCommandEvent& event);
158  void OnEditUnfoldAll(wxCommandEvent& event);
159  void OnEditToggleAllFolds(wxCommandEvent& event);
160  void OnEditFoldBlock(wxCommandEvent& event);
161  void OnEditUnfoldBlock(wxCommandEvent& event);
162  void OnEditToggleFoldBlock(wxCommandEvent& event);
163  void OnEditEOLMode(wxCommandEvent& event);
164  void OnEditEncoding(wxCommandEvent& event);
165  void OnEditParaUp(wxCommandEvent& event);
166  void OnEditParaUpExtend(wxCommandEvent& event);
167  void OnEditParaDown(wxCommandEvent& event);
168  void OnEditParaDownExtend(wxCommandEvent& event);
169  void OnEditWordPartLeft(wxCommandEvent& event);
170  void OnEditWordPartLeftExtend(wxCommandEvent& event);
171  void OnEditWordPartRight(wxCommandEvent& event);
172  void OnEditWordPartRightExtend(wxCommandEvent& event);
173  void OnEditZoomIn(wxCommandEvent& event);
174  void OnEditZoomOut(wxCommandEvent& event);
175  void OnEditZoomReset(wxCommandEvent& event);
176  void OnEditLineCut(wxCommandEvent& event);
177  void OnEditLineDelete(wxCommandEvent& event);
178  void OnEditLineDuplicate(wxCommandEvent& event);
179  void OnEditLineTranspose(wxCommandEvent& event);
180  void OnEditLineCopy(wxCommandEvent& event);
181  void OnEditLinePaste(wxCommandEvent& event);
182  void OnEditLineMove(wxCommandEvent& event);
183  void OnEditUpperCase(wxCommandEvent& event);
184  void OnEditLowerCase(wxCommandEvent& event);
185  void OnEditInsertNewLine(wxCommandEvent& event);
186  void OnEditGotoLineEnd(wxCommandEvent& event);
187  void OnEditInsertNewLineBelow(wxCommandEvent& event);
188  void OnEditInsertNewLineAbove(wxCommandEvent& event);
189  void OnEditSelectAll(wxCommandEvent& event);
190  void OnEditSelectNext(wxCommandEvent& event);
191  void OnEditSelectNextSkip(wxCommandEvent& event);
192  void OnEditCommentSelected(wxCommandEvent& event);
193  void OnEditUncommentSelected(wxCommandEvent& event);
194  void OnEditToggleCommentSelected(wxCommandEvent& event);
195  void OnEditStreamCommentSelected(wxCommandEvent& event);
196  void OnEditBoxCommentSelected(wxCommandEvent& event);
197  void OnEditShowCallTip(wxCommandEvent& event);
198  void OnEditCompleteCode(wxCommandEvent& event);
199 
200  void OnEditBookmarksToggle(wxCommandEvent& event);
201  void OnEditBookmarksNext(wxCommandEvent& event);
202  void OnEditBookmarksPrevious(wxCommandEvent& event);
203  void OnEditBookmarksClearAll(wxCommandEvent& event);
204 
205  void OnViewLayout(wxCommandEvent& event);
206  void OnViewLayoutSave(wxCommandEvent& event);
207  void OnViewLayoutDelete(wxCommandEvent& event);
208  void OnViewScriptConsole(wxCommandEvent& event);
209  void OnViewHideEditorTabs(wxCommandEvent& event);
210 
211  void OnSearchFind(wxCommandEvent& event);
212  void OnSearchFindNext(wxCommandEvent& event);
213  void OnSearchFindNextSelected(wxCommandEvent& event);
214  void OnSearchReplace(wxCommandEvent& event);
215  void OnSearchGotoLine(wxCommandEvent& event);
216  void OnSearchGotoNextChanged(wxCommandEvent& event);
217  void OnSearchGotoPrevChanged(wxCommandEvent& event);
218 
219  void OnPluginsExecuteMenu(wxCommandEvent& event);
220 
221  void OnSettingsEnvironment(wxCommandEvent& event);
222  void OnSettingsKeyBindings(wxCommandEvent& event);
223  void OnGlobalUserVars(wxCommandEvent& event);
224  void OnSettingsEditor(wxCommandEvent& event);
225  void OnSettingsCompiler(wxCommandEvent& event);
226  void OnSettingsDebugger(wxCommandEvent& event);
227  void OnSettingsPlugins(wxCommandEvent& event);
228  void OnSettingsScripting(wxCommandEvent& event);
229 
230  void OnHelpAbout(wxCommandEvent& event);
231  void OnHelpTips(wxCommandEvent& event);
232  void OnHelpPluginMenu(wxCommandEvent& event);
233 
234  void OnViewToolbarsFit(wxCommandEvent& event);
235  void OnViewToolbarsOptimize(wxCommandEvent& event);
236  void OnToggleBar(wxCommandEvent& event);
237  void OnToggleStatusBar(wxCommandEvent& event);
238  void OnFocusEditor(wxCommandEvent& event);
239  void OnFocusManagement(wxCommandEvent& event);
240  void OnFocusLogsAndOthers(wxCommandEvent& event);
241  void OnSwitchTabs(wxCommandEvent& event);
242  void OnToggleFullScreen(wxCommandEvent& event);
243  void OnToggleStartPage(wxCommandEvent& event);
244 
245  // plugin events
246  void OnPluginLoaded(CodeBlocksEvent& event);
247  void OnPluginUnloaded(CodeBlocksEvent& event);
248  void OnPluginInstalled(CodeBlocksEvent& event);
249  void OnPluginUninstalled(CodeBlocksEvent& event);
250 
251  // general UpdateUI events
252  void OnEditorUpdateUI(CodeBlocksEvent& event);
253 
254  void OnFileMenuUpdateUI(wxUpdateUIEvent& event);
255  void OnEditMenuUpdateUI(wxUpdateUIEvent& event);
256  void OnViewMenuUpdateUI(wxUpdateUIEvent& event);
257  void OnSearchMenuUpdateUI(wxUpdateUIEvent& event);
258  void OnProjectMenuUpdateUI(wxUpdateUIEvent& event);
259 
260  // project events
261  void OnProjectActivated(CodeBlocksEvent& event);
262  void OnProjectOpened(CodeBlocksEvent& event);
263  void OnProjectClosed(CodeBlocksEvent& event);
264 
265  // dock/undock window requests
266  void OnRequestDockWindow(CodeBlocksDockEvent& event);
267  void OnRequestUndockWindow(CodeBlocksDockEvent& event);
268  void OnRequestShowDockWindow(CodeBlocksDockEvent& event);
269  void OnRequestHideDockWindow(CodeBlocksDockEvent& event);
270  void OnDockWindowVisibility(CodeBlocksDockEvent& event);
271 
272  // layout requests
273  void OnLayoutUpdate(CodeBlocksLayoutEvent& event);
274  void OnLayoutQuery(CodeBlocksLayoutEvent& event);
275  void OnLayoutSwitch(CodeBlocksLayoutEvent& event);
276 
277  // log requests
278  void OnAddLogWindow(CodeBlocksLogEvent& event);
279  void OnRemoveLogWindow(CodeBlocksLogEvent& event);
280  void OnHideLogWindow(CodeBlocksLogEvent& event);
281  void OnSwitchToLogWindow(CodeBlocksLogEvent& event);
282  void OnGetActiveLogWindow(CodeBlocksLogEvent& event);
283  void OnShowLogManager(CodeBlocksLogEvent& event);
284  void OnHideLogManager(CodeBlocksLogEvent& event);
285  void OnLockLogManager(CodeBlocksLogEvent& event);
286  void OnUnlockLogManager(CodeBlocksLogEvent& event);
287 
288  // editor changed events
289  void OnEditorOpened(CodeBlocksEvent& event);
290  void OnEditorActivated(CodeBlocksEvent& event);
291  void OnEditorClosed(CodeBlocksEvent& event);
292  void OnEditorSaved(CodeBlocksEvent& event);
293  void OnEditorModified(CodeBlocksEvent& event);
294  void OnPageChanged(wxNotebookEvent& event);
295  void OnShiftTab(wxCommandEvent& event);
296  void OnCtrlAltTab(wxCommandEvent& event);
297  void OnNotebookDoubleClick(CodeBlocksEvent& event);
298  // Statusbar highlighting menu
299  void OnHighlightMenu(wxCommandEvent& event);
300  protected:
301  void CreateIDE();
302  void CreateMenubar();
303  void CreateToolbars();
304  void ScanForPlugins();
305  void AddToolbarItem(int id, const wxString& title, const wxString& shortHelp, const wxString& longHelp, const wxString& image);
306  void RecreateMenuBar();
307  void RegisterEvents();
308  void SetupGUILogging();
309  void SetupDebuggerUI();
310 
311  void RegisterScriptFunctions();
312  void RunStartupScripts();
313 
314  enum { Installed, Uninstalled, Unloaded };
315  void PluginsUpdated(cbPlugin* plugin, int status);
316 
317  void DoAddPlugin(cbPlugin* plugin);
318  ToolbarInfo DoAddPluginToolbar(cbPlugin* plugin);
319  void DoAddPluginStatusField(cbPlugin* plugin);
320  void AddPluginInPluginsMenu(cbPlugin* plugin);
321  void AddPluginInHelpPluginsMenu(cbPlugin* plugin);
322  wxMenuItem* AddPluginInMenus(wxMenu* menu, cbPlugin* plugin, wxObjectEventFunction callback, int pos = -1, bool checkable = false);
323 
324  void LoadViewLayout(const wxString& name, bool isTemp = false);
325  void SaveViewLayout(const wxString& name, const wxString& layout, const wxString& layoutMP, bool select = false);
326  void DoSelectLayout(const wxString& name);
327  void DoFixToolbarsLayout();
328  bool DoCheckCurrentLayoutForChanges(bool canCancel = true);
329 
330  void AddEditorInWindowMenu(const wxString& filename, const wxString& title);
331  void RemoveEditorFromWindowMenu(const wxString& filename);
332  int IsEditorInWindowMenu(const wxString& filename);
333  wxString GetEditorDescription(EditorBase* eb);
334 
335  bool DoCloseCurrentWorkspace();
336  bool DoOpenProject(const wxString& filename, bool addToHistory = true);
337  bool DoOpenFile(const wxString& filename, bool addToHistory = true);
338  void DoOnFileOpen(bool bProject = false);
339 
340  void DoCreateStatusBar();
341  void DoUpdateStatusBar();
342  void DoUpdateAppTitle();
343  void DoUpdateLayout();
344  void DoUpdateLayoutColours();
345  void DoUpdateEditorStyle();
346  void DoUpdateEditorStyle(cbAuiNotebook* target, const wxString& prefix, long defaultStyle);
347 
348  void ShowHideStartPage(bool forceHasProject = false, int forceState = 0);
349  void ShowHideScriptConsole();
350 
351  void LoadWindowState();
352  void SaveWindowState();
353  void LoadWindowSize();
354 
355  void InitializeRecentFilesHistory();
356  void TerminateRecentFilesHistory();
357  #if wxUSE_STATUSBAR
358  wxStatusBar *OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name) override;
359  #endif
360  protected:
362 
365 
371 
372  wxToolBar* m_pToolbar; // main toolbar
373  PluginToolbarsMap m_PluginsTools; // plugin -> toolbar map
374 
375  PluginIDsMap m_PluginIDsMap;
379  bool m_ScanningForPlugins; // this variable is used to delay the UI construction
380 
384 
387 
393 
395 
396  typedef std::map<int, const wxString> MenuIDToScript; // script menuitem ID -> script function name
397  MenuIDToScript m_MenuIDToScript;
398 
401 
404 
406 
407  DECLARE_EVENT_TABLE()
408 };
409 
410 #endif // MAIN_H
wxToolBar * toolbar
Definition: main.h:56
Definition: main.h:60
Base class for plugins.
Definition: cbplugin.h:84
bool m_InitiatedShutdown
Definition: main.h:383
bool m_StartupDone
Definition: main.h:382
bool m_ScanningForPlugins
Definition: main.h:379
ProjectManager * m_pPrjMan
Definition: main.h:367
EditorManager * m_pEdMan
Definition: main.h:366
std::map< int, const wxString > MenuIDToScript
Definition: main.h:396
wxMenu * m_PluginsMenu
Definition: main.h:377
Event used to request from the main app to add a log.
Definition: sdk_events.h:182
WX_DECLARE_STRING_HASH_MAP(wxString, LayoutViewsMap)
Event used to request from the main app to add a window to the docking system.
Definition: sdk_events.h:83
DebuggerToolbarHandler * m_debuggerToolbarHandler
Definition: main.h:403
wxButton * m_pCloseFullScreenBtn
"Close FullScreen" button. Only shown when in FullScreen view
Definition: main.h:364
#define _T(string)
LayoutViewsMap m_LayoutViews
Definition: main.h:73
wxString m_LastMessagePaneLayoutData
Definition: main.h:391
MainFrame & operator=(cb_unused const MainFrame &rhs)
Definition: main.h:64
WX_DECLARE_HASH_MAP(int, wxString, wxIntegerHash, wxIntegerEqual, PluginIDsMap)
bool m_LastLayoutIsTemp
Definition: main.h:392
wxAuiManager m_LayoutManager
Definition: main.h:72
cbProjectManagerUI * GetProjectManagerUI()
Definition: main.h:95
A generic Code::Blocks event.
Definition: sdk_events.h:20
MenuIDToScript m_MenuIDToScript
Definition: main.h:397
FindReplace m_findReplace
Definition: main.h:405
PluginIDsMap m_PluginIDsMap
Definition: main.h:375
RecentItemsList m_projectsHistory
Definition: main.h:361
LayoutViewsMap m_LayoutMessagePane
Definition: main.h:74
int idStartHerePageVarSubst
ToolbarInfo(wxToolBar *toolbar_in, const wxAuiPaneInfo &paneInfo_in, int priority_in)
Definition: main.h:43
wxScrollingDialog * m_pBatchBuildDialog
Definition: main.h:399
bool operator<(const ToolbarInfo &b) const
Definition: main.h:50
wxString m_LastLayoutName
Definition: main.h:389
wxMenu * m_ToolsMenu
Definition: main.h:376
DebuggerMenuHandler * m_debuggerMenuHandler
Definition: main.h:402
wxAuiPaneInfo paneInfo
Definition: main.h:55
wxString m_PreviousLayoutName
Definition: main.h:388
Base class that all "editors" should inherit from.
Definition: editorbase.h:30
wxButton * m_pHighlightButton
Definition: main.h:400
bool m_SmallToolBar
Definition: main.h:381
wxScrollingDialog * GetBatchBuildDialog()
Definition: main.h:86
wxAcceleratorTable * m_pAccel
Definition: main.h:78
const wxString & _(const wxString &string)
#define cbThrow(message)
Definition: cbexception.h:42
wxToolBar * m_pToolbar
Definition: main.h:372
The entry point singleton for working with projects.
PluginToolbarsMap m_PluginsTools
Definition: main.h:373
A notebook class This class is derived from wxAuiNotebook, to enhance its abilities.
Definition: cbauibook.h:30
ToolbarInfo()
Definition: main.h:42
int m_AutoHideLockCounter
Definition: main.h:385
int priority
Definition: main.h:57
wxMenu * m_HelpPluginsMenu
Definition: main.h:378
wxWindow * m_pScriptConsole
Definition: main.h:394
int wxCoord
wxString m_LastLayoutData
Definition: main.h:390
cbProjectManagerUI * m_pPrjManUI
Definition: main.h:368
#define NULL
Definition: prefix.cpp:59
int wxWindowID
LogManager * m_pLogMan
Definition: main.h:369
int m_LastCtrlAltTabWindow
Last window focussed in the cycle 1 = Mgmt. panel, 2 = Editor, 3 = Logs & others. ...
Definition: main.h:386
Event used to request from the main app to manage the view layouts.
Definition: sdk_events.h:158
InfoPane * m_pInfoPane
Definition: main.h:370