Code::Blocks  SVN r11506
editormanager.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 EDITORMANAGER_H
7 #define EDITORMANAGER_H
8 
9 #include "prep.h"
10 #include <wx/list.h>
11 #include <wx/treectrl.h>
12 #include <wx/hashmap.h>
13 #include <wx/filename.h>
14 
15 #include "settings.h"
16 #include "manager.h"
17 #include "cbexception.h" // cbThrow
18 
19 #include "printing_types.h"
20 
21 #include "globals.h" // cbC2U, FileType
22 
23 DLLIMPORT extern int ID_NBEditorManager;
24 DLLIMPORT extern int ID_EditorManager;
27 
28 // forward decls
29 class EditorBase;
30 class cbAuiNotebook;
31 class wxAuiNotebookEvent;
32 class EditorColourSet;
33 class cbProject;
34 class ProjectFile;
35 class cbEditor;
36 class cbStyledTextCtrl;
37 class ListCtrlLogger;
38 class LoaderBase;
40 class SearchResultsLog;
41 
42 /*
43  * Struct for store tabs stack info
44  */
46 {
47  cbNotebookStack(wxWindow* a_pWindow = nullptr)
48  : window (a_pWindow),
49  next (nullptr)
50  {}
51 
54 };
55 
56 /*
57  * No description
58  */
59 class DLLIMPORT EditorManager : public Mgr<EditorManager>, public wxEvtHandler
60 {
61  friend class Mgr<EditorManager>;
62  static bool s_CanShutdown;
63  public:
64  EditorManager& operator=(cb_unused const EditorManager& rhs) // prevent assignment operator
65  {
66  cbThrow(_T("Can't assign an EditorManager* !!!"));
67  return *this;
68  }
69 
70  friend class Manager; // give Manager access to our private members
71  static bool CanShutdown(){ return s_CanShutdown; }
72 
73  cbAuiNotebook* GetNotebook() { return m_pNotebook; }
74  cbNotebookStack* GetNotebookStack();
75  void DeleteNotebookStack();
76  void RebuildNotebookStack();
77 
78  void RecreateOpenEditorStyles();
79  int GetEditorsCount();
80 
81  EditorBase* IsOpen(const wxString& filename);
82  cbEditor* Open(const wxString& filename, int pos = 0, ProjectFile* data = nullptr);
83  cbEditor* Open(LoaderBase* fileLdr, const wxString& filename, int pos = 0, ProjectFile* data = nullptr);
84  EditorBase* GetEditor(int index);
85  EditorBase* GetEditor(const wxString& filename){ return IsOpen(filename); } // synonym of IsOpen()
86  EditorBase* GetActiveEditor();
87  cbEditor* GetBuiltinEditor(EditorBase* eb);
88  int FindPageFromEditor(EditorBase* eb);
89 
90  // "overloaded" functions for easier access
91  // they all return a cbEditor pointer if the editor is builtin, or NULL
92  cbEditor* IsBuiltinOpen(const wxString& filename){ return GetBuiltinEditor(IsOpen(filename)); }
93  cbEditor* GetBuiltinEditor(int index){ return GetBuiltinEditor(GetEditor(index)); }
94  cbEditor* GetBuiltinEditor(const wxString& filename){ return IsBuiltinOpen(filename); } // synonym of IsBuiltinOpen()
95  cbEditor* GetBuiltinActiveEditor(){ return GetBuiltinEditor(GetActiveEditor()); }
96 
97  void ActivateNext();
98  void ActivatePrevious();
99  void SetActiveEditor(EditorBase* ed);
100  EditorColourSet* GetColourSet(){ return m_Theme; }
101  void SetColourSet(EditorColourSet* theme);
102  cbEditor* New(const wxString& newFileName = wxEmptyString);
103 
104  // these are used *only* for custom editors
105  void AddCustomEditor(EditorBase* eb);
106  void RemoveCustomEditor(EditorBase* eb);
107 
108  bool UpdateProjectFiles(cbProject* project);
109  bool SwapActiveHeaderSource();
110  bool OpenContainingFolder();
111  bool CloseActive(bool dontsave = false);
112  bool Close(const wxString& filename, bool dontsave = false);
113  bool Close(EditorBase* editor, bool dontsave = false);
114  bool Close(int index, bool dontsave = false);
115 
116  // If file is modified, queries to save (yes/no/cancel).
117  // Returns false on "cancel".
118  bool QueryClose(EditorBase* editor);
119  bool QueryCloseAll();
121  bool CloseAll(bool dontsave = false);
123  bool CloseAllExcept(EditorBase* editor, bool dontsave = false);
125  bool CloseAllInTabCtrl(bool dontsave = false);
127  bool CloseAllInTabCtrlExcept(EditorBase* editor, bool dontsave = false);
129  bool CloseAllInTabCtrlToTheLeft(EditorBase* editor, bool dontsave = false);
131  bool CloseAllInTabCtrlToTheRight(EditorBase* editor, bool dontsave = false);
132  bool Save(const wxString& filename);
133  bool Save(int index);
134  bool SaveActive();
135  bool SaveAs(int index);
136  bool SaveActiveAs();
137  bool SaveAll();
138 
139  void Print(PrintScope ps, PrintColourMode pcm, bool line_numbers);
140 
142  void HideNotebook();
144  void ShowNotebook();
146  void CheckForExternallyModifiedFiles();
147 
148  void SetZoom(int zoom);
149  int GetZoom()const;
150 
151  void MarkReadOnly(int page, bool readOnly = true);
152 
153  wxString GetSelectionClipboard();
154  void SetSelectionClipboard(const wxString& data);
155  private:
156  void OnGenericContextMenuHandler(wxCommandEvent& event);
157  void OnPageChanged(wxAuiNotebookEvent& event);
158  void OnPageChanging(wxAuiNotebookEvent& event);
159  void OnPageClose(wxAuiNotebookEvent& event);
160  void OnPageContextMenu(wxAuiNotebookEvent& event);
161  void OnClose(wxCommandEvent& event);
162  void OnCloseAll(wxCommandEvent& event);
163  void OnCloseAllOthers(wxCommandEvent& event);
164  void OnSave(wxCommandEvent& event);
165  void OnSaveAll(wxCommandEvent& event);
166  void OnSwapHeaderSource(wxCommandEvent& event);
167  void OnOpenContainingFolder(wxCommandEvent& event);
168  void OnTabPosition(wxCommandEvent& event);
169  void OnProperties(wxCommandEvent& event);
170  void OnAddFileToProject(wxCommandEvent& event);
171  void OnRemoveFileFromProject(wxCommandEvent& event);
172  void OnShowFileInTree(wxCommandEvent& event);
173  void OnAppDoneStartup(wxCommandEvent& event);
174  void OnAppStartShutdown(wxCommandEvent& event);
175  void OnUpdateUI(wxUpdateUIEvent& event);
176  void OnTreeItemSelected(wxTreeEvent &event);
177  void OnTreeItemActivated(wxTreeEvent &event);
178  void OnTreeItemRightClick(wxTreeEvent &event);
179  void CollectDefines(CodeBlocksEvent& event);
180 
181  protected:
182  // m_EditorsList access
183  void AddEditorBase(EditorBase* eb);
184  void RemoveEditorBase(EditorBase* eb, bool deleteObject = true);
185  cbEditor* InternalGetBuiltinEditor(int page);
186  EditorBase* InternalGetEditorBase(int page);
187 
188  private:
189  EditorManager(cb_unused const EditorManager& rhs); // prevent copy construction
190 
191  EditorManager();
192  ~EditorManager() override;
193  void OnCheckForModifiedFiles(wxCommandEvent& event);
194  bool IsHeaderSource(const wxFileName& candidateFile, const wxFileName& activeFile, FileType ftActive, bool& isCandidate);
195  wxFileName FindHeaderSource(const wxArrayString& candidateFilesArray, const wxFileName& activeFile, bool& isCandidate);
196 
198  bool CloseEditors(const std::vector<EditorBase*> &editors, bool dontsave = false);
200  void GetEditorsInTabCtrl(std::vector<EditorBase*> &editors, EditorBase *editor);
201 
207  int m_Zoom;
211 
212  DECLARE_EVENT_TABLE()
213 };
214 
215 #endif // EDITORMANAGER_H
216 
217 
cbEditor * IsBuiltinOpen(const wxString &filename)
Definition: editormanager.h:92
cbAuiNotebook * m_pNotebook
cbEditor * GetBuiltinEditor(const wxString &filename)
Definition: editormanager.h:94
cbNotebookStack * m_pNotebookStackTail
cbNotebookStack(wxWindow *a_pWindow=nullptr)
Definition: editormanager.h:47
PrintColourMode
a logger which prints messages to a wxListCtrl
Definition: loggers.h:120
#define _T(string)
FileType
Known file types.
Definition: globals.h:49
DLLIMPORT int ID_EditorManager
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
A generic Code::Blocks event.
Definition: sdk_events.h:20
#define DLLIMPORT
Definition: settings.h:16
cbEditor * GetBuiltinEditor(int index)
Definition: editormanager.h:93
Represents a Code::Blocks project.
Definition: cbproject.h:96
size_t m_nNotebookStackSize
EditorManager & operator=(cb_unused const EditorManager &rhs)
Definition: editormanager.h:64
null_pointer_t nullptr
Definition: nullptr.cpp:16
static bool CanShutdown()
Definition: editormanager.h:71
EditorManagerInternalData * m_pData
DLLIMPORT int idEditorManagerCheckFiles
cbEditor * GetBuiltinActiveEditor()
Definition: editormanager.h:95
Base class that all "editors" should inherit from.
Definition: editorbase.h:30
EditorBase * GetEditor(const wxString &filename)
Definition: editormanager.h:85
bool m_isCheckingForExternallyModifiedFiles
struct EditorManagerInternalData * This is the private data holder for the EditorManager * All data ...
PrintScope
cbNotebookStack * next
Definition: editormanager.h:53
wxString wxEmptyString
Definition: manager.h:183
#define cbThrow(message)
Definition: cbexception.h:42
EditorColourSet * m_Theme
EditorColourSet * GetColourSet()
A file editor.
Definition: cbeditor.h:43
cbAuiNotebook * GetNotebook()
Definition: editormanager.h:73
DLLIMPORT int ID_NBEditorManager
A notebook class This class is derived from wxAuiNotebook, to enhance its abilities.
Definition: cbauibook.h:30
cbNotebookStack * m_pNotebookStackHead
wxWindow * window
Definition: editormanager.h:52
DLLIMPORT int ID_EditorManagerCloseButton
static bool s_CanShutdown
Definition: editormanager.h:62