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" 23 #include "scripting/bindings/sc_base_types.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; 34 class DebuggerMenuHandler; 35 class DebuggerToolbarHandler; 36 class InfoPane; 37 class wxGauge; 38 class ProjectManagerUI; 39 40 struct ToolbarInfo 41 { ToolbarInfoToolbarInfo42 ToolbarInfo() {} ToolbarInfoToolbarInfo43 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 55 wxAuiPaneInfo paneInfo; 56 wxToolBar *toolbar; 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 72 wxAuiManager m_LayoutManager; 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: 78 std::unique_ptr<wxAcceleratorTable> m_pAccel; 79 std::unique_ptr<wxAcceleratorEntry[]> m_pAccelEntries; 80 size_t m_AccelCount; 81 82 MainFrame(wxWindow* parent = (wxWindow*)NULL); 83 ~MainFrame(); 84 85 bool Open(const wxString& filename, bool addToHistory = true); 86 bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); 87 void ShowTips(bool forceShow = false); 88 GetBatchBuildDialog()89 wxScrollingDialog* GetBatchBuildDialog(){ return m_pBatchBuildDialog; } 90 91 // show a file-open dialog and return the selection 92 wxString ShowOpenFileDialog(const wxString& caption, const wxString& filter); 93 // open the filename (based on what it is) 94 bool OpenGeneric(const wxString& filename, bool addToHistory = true); 95 96 void StartupDone(); 97 GetProjectManagerUI()98 cbProjectManagerUI* GetProjectManagerUI() { return m_pPrjManUI; } 99 private: 100 // event handlers 101 102 void OnEraseBackground(wxEraseEvent& event); 103 void OnSize(wxSizeEvent& event); 104 void OnApplicationClose(wxCloseEvent& event); 105 void OnStartHereLink(wxCommandEvent& event); 106 107 // the two functions below are used to show context menu to toggle toolbar view status 108 // OnMouseRightUp is handler for right click on MainFrame's free area which is not covered by 109 // any sub panels, OnToolBarRightClick is used to response the mouse right click command 110 // on the toolbar. 111 void OnMouseRightUp(wxMouseEvent& event); 112 void OnToolBarRightClick(wxCommandEvent& event); 113 114 // common function to show context menu for toggle toolbars 115 void PopupToggleToolbarMenu(); 116 void SetChecksForViewToolbarsMenu(wxMenu &menu); 117 118 // File->New submenu entries handler 119 void OnFileNewWhat(wxCommandEvent& event); 120 121 void OnFileNew(wxCommandEvent& event); 122 void OnFileOpen(wxCommandEvent& event); 123 void OnFileReopenProject(wxCommandEvent& event); 124 void OnFileOpenRecentProjectClearHistory(wxCommandEvent& event); 125 void OnFileReopen(wxCommandEvent& event); 126 void OnFileOpenRecentClearHistory(wxCommandEvent& event); 127 void OnFileImportProjectDevCpp(wxCommandEvent& event); 128 void OnFileImportProjectMSVC(wxCommandEvent& event); 129 void OnFileImportProjectMSVCWksp(wxCommandEvent& event); 130 void OnFileImportProjectMSVS(wxCommandEvent& event); 131 void OnFileImportProjectMSVSWksp(wxCommandEvent& event); 132 void OnFileSave(wxCommandEvent& event); 133 void OnFileSaveAs(wxCommandEvent& event); 134 void OnFileSaveProject(wxCommandEvent& event); 135 void OnFileSaveProjectAs(wxCommandEvent& event); 136 void OnFileSaveProjectTemplate(wxCommandEvent& event); 137 void OnFileOpenDefWorkspace(wxCommandEvent& event); 138 void OnFileSaveWorkspace(wxCommandEvent& event); 139 void OnFileSaveWorkspaceAs(wxCommandEvent& event); 140 void OnFileSaveAll(wxCommandEvent& event); 141 void OnFileCloseWorkspace(wxCommandEvent& event); 142 void OnFileClose(wxCommandEvent& event); 143 void OnFileCloseAll(wxCommandEvent& event); 144 void OnFileCloseProject(wxCommandEvent& event); 145 void OnFilePrintSetup(wxCommandEvent& event); 146 void OnFilePrint(wxCommandEvent& event); 147 void OnFileQuit(wxCommandEvent& event); 148 void OnFileNext(wxCommandEvent& event); 149 void OnFilePrev(wxCommandEvent& event); 150 151 void OnEditUndo(wxCommandEvent& event); 152 void OnEditRedo(wxCommandEvent& event); 153 void OnEditClearHistory(wxCommandEvent& event); 154 void OnEditCopy(wxCommandEvent& event); 155 void OnEditCut(wxCommandEvent& event); 156 void OnEditPaste(wxCommandEvent& event); 157 void OnEditSwapHeaderSource(wxCommandEvent& event); 158 void OnEditGotoMatchingBrace(wxCommandEvent& event); 159 void OnEditHighlightMode(wxCommandEvent& event); 160 void OnEditFoldAll(wxCommandEvent& event); 161 void OnEditUnfoldAll(wxCommandEvent& event); 162 void OnEditToggleAllFolds(wxCommandEvent& event); 163 void OnEditFoldBlock(wxCommandEvent& event); 164 void OnEditUnfoldBlock(wxCommandEvent& event); 165 void OnEditToggleFoldBlock(wxCommandEvent& event); 166 void OnEditEOLMode(wxCommandEvent& event); 167 void OnEditEncoding(wxCommandEvent& event); 168 void OnEditParaUp(wxCommandEvent& event); 169 void OnEditParaUpExtend(wxCommandEvent& event); 170 void OnEditParaDown(wxCommandEvent& event); 171 void OnEditParaDownExtend(wxCommandEvent& event); 172 void OnEditWordPartLeft(wxCommandEvent& event); 173 void OnEditWordPartLeftExtend(wxCommandEvent& event); 174 void OnEditWordPartRight(wxCommandEvent& event); 175 void OnEditWordPartRightExtend(wxCommandEvent& event); 176 void OnEditZoomIn(wxCommandEvent& event); 177 void OnEditZoomOut(wxCommandEvent& event); 178 void OnEditZoomReset(wxCommandEvent& event); 179 void OnEditLineCut(wxCommandEvent& event); 180 void OnEditLineDelete(wxCommandEvent& event); 181 void OnEditLineDuplicate(wxCommandEvent& event); 182 void OnEditLineTranspose(wxCommandEvent& event); 183 void OnEditLineCopy(wxCommandEvent& event); 184 void OnEditLinePaste(wxCommandEvent& event); 185 void OnEditLineMove(wxCommandEvent& event); 186 void OnEditUpperCase(wxCommandEvent& event); 187 void OnEditLowerCase(wxCommandEvent& event); 188 void OnEditInsertNewLine(wxCommandEvent& event); 189 void OnEditGotoLineEnd(wxCommandEvent& event); 190 void OnEditInsertNewLineBelow(wxCommandEvent& event); 191 void OnEditInsertNewLineAbove(wxCommandEvent& event); 192 void OnEditSelectAll(wxCommandEvent& event); 193 void OnEditSelectNext(wxCommandEvent& event); 194 void OnEditSelectNextSkip(wxCommandEvent& event); 195 void OnEditCommentSelected(wxCommandEvent& event); 196 void OnEditUncommentSelected(wxCommandEvent& event); 197 void OnEditToggleCommentSelected(wxCommandEvent& event); 198 void OnEditStreamCommentSelected(wxCommandEvent& event); 199 void OnEditBoxCommentSelected(wxCommandEvent& event); 200 void OnEditShowCallTip(wxCommandEvent& event); 201 void OnEditCompleteCode(wxCommandEvent& event); 202 203 void OnEditBookmarksToggle(wxCommandEvent& event); 204 void OnEditBookmarksNext(wxCommandEvent& event); 205 void OnEditBookmarksPrevious(wxCommandEvent& event); 206 void OnEditBookmarksClearAll(wxCommandEvent& event); 207 208 void OnViewLayout(wxCommandEvent& event); 209 void OnViewLayoutSave(wxCommandEvent& event); 210 void OnViewLayoutDelete(wxCommandEvent& event); 211 void OnViewScriptConsole(wxCommandEvent& event); 212 void OnViewHideEditorTabs(wxCommandEvent& event); 213 214 void OnSearchFind(wxCommandEvent& event); 215 void OnSearchFindNext(wxCommandEvent& event); 216 void OnSearchFindNextSelected(wxCommandEvent& event); 217 void OnSearchReplace(wxCommandEvent& event); 218 void OnSearchGotoLine(wxCommandEvent& event); 219 void OnSearchGotoNextChanged(wxCommandEvent& event); 220 void OnSearchGotoPrevChanged(wxCommandEvent& event); 221 222 void OnPluginsExecuteMenu(wxCommandEvent& event); 223 224 void OnSettingsEnvironment(wxCommandEvent& event); 225 void OnSettingsKeyBindings(wxCommandEvent& event); 226 void OnGlobalUserVars(wxCommandEvent& event); 227 void OnSettingsEditor(wxCommandEvent& event); 228 void OnSettingsCompiler(wxCommandEvent& event); 229 void OnSettingsDebugger(wxCommandEvent& event); 230 void OnSettingsPlugins(wxCommandEvent& event); 231 void OnSettingsScripting(wxCommandEvent& event); 232 233 void OnHelpAbout(wxCommandEvent& event); 234 void OnHelpTips(wxCommandEvent& event); 235 void OnHelpPluginMenu(wxCommandEvent& event); 236 237 void OnViewToolbarsFit(wxCommandEvent& event); 238 void OnViewToolbarsOptimize(wxCommandEvent& event); 239 void OnToggleBar(wxCommandEvent& event); 240 void OnToggleStatusBar(wxCommandEvent& event); 241 void OnFocusEditor(wxCommandEvent& event); 242 void OnFocusManagement(wxCommandEvent& event); 243 void OnFocusLogsAndOthers(wxCommandEvent& event); 244 void OnSwitchTabs(wxCommandEvent& event); 245 void OnToggleFullScreen(wxCommandEvent& event); 246 void OnToggleStartPage(wxCommandEvent& event); 247 248 // plugin events 249 void OnPluginLoaded(CodeBlocksEvent& event); 250 void OnPluginUnloaded(CodeBlocksEvent& event); 251 void OnPluginInstalled(CodeBlocksEvent& event); 252 void OnPluginUninstalled(CodeBlocksEvent& event); 253 254 // general UpdateUI events 255 void OnEditorUpdateUI(CodeBlocksEvent& event); 256 257 void OnFileMenuUpdateUI(wxUpdateUIEvent& event); 258 void OnEditMenuUpdateUI(wxUpdateUIEvent& event); 259 void OnViewMenuUpdateUI(wxUpdateUIEvent& event); 260 void OnSearchMenuUpdateUI(wxUpdateUIEvent& event); 261 void OnProjectMenuUpdateUI(wxUpdateUIEvent& event); 262 263 // project events 264 void OnProjectActivated(CodeBlocksEvent& event); 265 void OnProjectOpened(CodeBlocksEvent& event); 266 void OnProjectClosed(CodeBlocksEvent& event); 267 268 // dock/undock window requests 269 void OnRequestDockWindow(CodeBlocksDockEvent& event); 270 void OnRequestUndockWindow(CodeBlocksDockEvent& event); 271 void OnRequestShowDockWindow(CodeBlocksDockEvent& event); 272 void OnRequestHideDockWindow(CodeBlocksDockEvent& event); 273 void OnDockWindowVisibility(CodeBlocksDockEvent& event); 274 275 // layout requests 276 void OnLayoutUpdate(CodeBlocksLayoutEvent& event); 277 void OnLayoutQuery(CodeBlocksLayoutEvent& event); 278 void OnLayoutSwitch(CodeBlocksLayoutEvent& event); 279 280 // log requests 281 void OnAddLogWindow(CodeBlocksLogEvent& event); 282 void OnRemoveLogWindow(CodeBlocksLogEvent& event); 283 void OnHideLogWindow(CodeBlocksLogEvent& event); 284 void OnSwitchToLogWindow(CodeBlocksLogEvent& event); 285 void OnGetActiveLogWindow(CodeBlocksLogEvent& event); 286 void OnShowLogManager(CodeBlocksLogEvent& event); 287 void OnHideLogManager(CodeBlocksLogEvent& event); 288 void OnLockLogManager(CodeBlocksLogEvent& event); 289 void OnUnlockLogManager(CodeBlocksLogEvent& event); 290 291 // editor changed events 292 void OnEditorOpened(CodeBlocksEvent& event); 293 void OnEditorActivated(CodeBlocksEvent& event); 294 void OnEditorClosed(CodeBlocksEvent& event); 295 void OnEditorSaved(CodeBlocksEvent& event); 296 void OnEditorModified(CodeBlocksEvent& event); 297 void OnPageChanged(wxNotebookEvent& event); 298 void OnShiftTab(wxCommandEvent& event); 299 void OnCtrlAltTab(wxCommandEvent& event); 300 void OnNotebookDoubleClick(CodeBlocksEvent& event); 301 // Statusbar highlighting menu 302 void OnHighlightMenu(wxCommandEvent& event); 303 304 // Allow plugins to obtain copy of global accelerators 305 void OnGetGlobalAccels(wxCommandEvent& event); 306 307 protected: 308 void CreateIDE(); 309 void CreateMenubar(); 310 void CreateToolbars(); 311 void ScanForPlugins(); 312 void AddToolbarItem(int id, const wxString& title, const wxString& shortHelp, const wxString& longHelp, const wxString& image); 313 void RecreateMenuBar(); 314 void RegisterEvents(); 315 void SetupGUILogging(int uiSize16); 316 void SetupDebuggerUI(); 317 318 void RegisterScriptFunctions(); 319 void RunStartupScripts(); 320 321 enum { Installed, Uninstalled, Unloaded }; 322 void PluginsUpdated(cbPlugin* plugin, int status); 323 324 void DoAddPlugin(cbPlugin* plugin); 325 ToolbarInfo DoAddPluginToolbar(cbPlugin* plugin); 326 void DoAddPluginStatusField(cbPlugin* plugin); 327 void AddPluginInPluginsMenu(cbPlugin* plugin); 328 void AddPluginInHelpPluginsMenu(cbPlugin* plugin); 329 wxMenuItem* AddPluginInMenus(wxMenu* menu, cbPlugin* plugin, wxObjectEventFunction callback, int pos = -1, bool checkable = false); 330 331 void LoadViewLayout(const wxString& name, bool isTemp = false); 332 void SaveViewLayout(const wxString& name, const wxString& layout, const wxString& layoutMP, bool select = false); 333 void DoSelectLayout(const wxString& name); 334 void DoFixToolbarsLayout(); 335 bool DoCheckCurrentLayoutForChanges(bool canCancel = true); 336 337 void AddEditorInWindowMenu(const wxString& filename, const wxString& title); 338 void RemoveEditorFromWindowMenu(const wxString& filename); 339 int IsEditorInWindowMenu(const wxString& filename); 340 wxString GetEditorDescription(EditorBase* eb); 341 342 bool DoCloseCurrentWorkspace(); 343 bool DoOpenProject(const wxString& filename, bool addToHistory = true); 344 bool DoOpenFile(const wxString& filename, bool addToHistory = true); 345 void DoOnFileOpen(bool bProject = false); 346 347 void DoCreateStatusBar(); 348 void DoUpdateStatusBar(); 349 void DoUpdateAppTitle(); 350 void DoUpdateLayout(); 351 void DoUpdateLayoutColours(); 352 void DoUpdateEditorStyle(); 353 void DoUpdateEditorStyle(cbAuiNotebook* target, const wxString& prefix, long defaultStyle); 354 355 void ShowHideStartPage(bool forceHasProject = false, int forceState = 0); 356 void ShowHideScriptConsole(); 357 358 void LoadWindowState(); 359 void SaveWindowState(); 360 void LoadWindowSize(); 361 362 void InitializeRecentFilesHistory(); 363 void TerminateRecentFilesHistory(); 364 #if wxUSE_STATUSBAR 365 wxStatusBar *OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name) override; 366 #endif 367 protected: 368 RecentItemsList m_filesHistory, m_projectsHistory; 369 370 /// "Close FullScreen" button. Only shown when in FullScreen view 371 wxButton* m_pCloseFullScreenBtn; 372 373 EditorManager* m_pEdMan; 374 ProjectManager* m_pPrjMan; 375 cbProjectManagerUI* m_pPrjManUI; 376 LogManager* m_pLogMan; 377 InfoPane* m_pInfoPane; 378 379 wxToolBar* m_pToolbar; // main toolbar 380 PluginToolbarsMap m_PluginsTools; // plugin -> toolbar map 381 382 PluginIDsMap m_PluginIDsMap; 383 wxMenu* m_ToolsMenu; 384 wxMenu* m_PluginsMenu; 385 wxMenu* m_HelpPluginsMenu; 386 bool m_ScanningForPlugins; // this variable is used to delay the UI construction 387 388 bool m_StartupDone; 389 bool m_InitiatedShutdown; 390 391 int m_AutoHideLockCounter; 392 int m_LastCtrlAltTabWindow; //!< Last window focussed in the cycle 1 = Mgmt. panel, 2 = Editor, 3 = Logs & others 393 394 wxString m_PreviousLayoutName; 395 wxString m_LastLayoutName; 396 wxString m_LastLayoutData; 397 wxString m_LastMessagePaneLayoutData; 398 bool m_LastLayoutIsTemp; 399 400 wxWindow* m_pScriptConsole; 401 402 typedef std::map<int, const wxString> MenuIDToScript; // script menuitem ID -> script function name 403 MenuIDToScript m_MenuIDToScript; 404 405 wxScrollingDialog* m_pBatchBuildDialog; 406 wxButton* m_pHighlightButton; 407 408 DebuggerMenuHandler* m_debuggerMenuHandler; 409 DebuggerToolbarHandler* m_debuggerToolbarHandler; 410 411 FindReplace m_findReplace; 412 413 DECLARE_EVENT_TABLE() 414 }; 415 416 #endif // MAIN_H 417