Code::Blocks  SVN r11506
cbeditor.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 CBEDITOR_H
7 #define CBEDITOR_H
8 
9 #include <wx/hashmap.h>
10 #include <wx/datetime.h>
11 #include <wx/fontmap.h>
12 #include <wx/timer.h>
13 
14 #include "settings.h"
15 #include "editorbase.h"
16 #include "printing_types.h"
17 
18 extern const wxString g_EditorModified;
19 
20 // forward decls
21 struct cbEditorInternalData; // this is the private data struct used by the editor.
22 class cbEditor;
23 class ProjectFile;
24 class EditorColourSet;
25 class wxSplitterWindow;
26 class LoaderBase;
27 class cbStyledTextCtrl;
28 class wxScintillaEvent;
29 class wxBoxSizer;
30 
31 
44 {
45  DECLARE_EVENT_TABLE()
46  friend class EditorManager;
47 
48  protected:
57  cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme);
58  cbEditor(wxWindow* parent, LoaderBase* fileLdr, const wxString& filename, EditorColourSet* theme);
60  ~cbEditor() override;
61  public:
62  enum SplitType
63  {
64  stNoSplit = 0,
66  stVertical
67  };
68 
70  void operator=(cb_unused const cbEditor& rhs){ cbThrow(_T("Can't assign an cbEditor* !!!")); }
71 
72  // properties
73 
82  cbStyledTextCtrl* GetControl() const;
83 
87  cbStyledTextCtrl* GetLeftSplitViewControl() const { return m_pControl; }
88 
92  cbStyledTextCtrl* GetRightSplitViewControl() const { return m_pControl2; }
93 
95  SplitType GetSplitType() const { return m_SplitType; }
96 
101  bool IsOK() const { return m_IsOK; }
102 
106  void SetEditorTitle(const wxString& title);
107 
109  bool GetModified() const override;
110 
112  void SetModified(bool modified = true) override;
113 
118  void SetProjectFile(ProjectFile* project_file,bool preserve_modified = false);
119 
123  ProjectFile* GetProjectFile() const { return m_pProjectFile; }
124 
131  void UpdateProjectFile();
132 
134  bool Save() override;
135 
137  bool SaveAs() override;
138 
140  bool SaveFoldState();
141 
143  bool FixFoldState();
144 
146  void FoldAll();
147 
149  void UnfoldAll();
150 
152  void ToggleAllFolds();
153 
155  void SetFoldingIndicator(int id);
156 
158  void FoldBlockFromLine(int line = -1);
159 
161  void UnfoldBlockFromLine(int line = -1);
162 
164  void ToggleFoldBlockFromLine(int line = -1);
165 
167  void SetColourSet(EditorColourSet* theme);
168 
170  EditorColourSet* GetColourSet() const { return m_pTheme; }
171 
173  void GotoMatchingBrace();
174 
176  void HighlightBraces();
177 
179  int GetLineIndentInSpaces(int line = -1) const;
180 
182  wxString GetLineIndentString(int line = -1) const;
183 
185  wxDateTime GetLastModificationTime() const { return m_LastModified; }
186 
188  void Touch();
189 
191  bool Reload(bool detectEncoding = true);
192 
198  void Print(bool selectionOnly, PrintColourMode pcm, bool line_numbers);
199 
201  void AutoComplete();
202 
206  void GotoLine(int line, bool centerOnScreen = true) override;
207 
212  bool GotoTokenPosition(int line, const wxString& tokenName);
213 
215  bool AddBreakpoint(int line = -1, bool notifyDebugger = true);
216 
218  bool RemoveBreakpoint(int line = -1, bool notifyDebugger = true);
219 
221  virtual void ToggleBreakpoint(int line = -1, bool notifyDebugger = true);
222 
224  virtual bool HasBreakpoint(int line) const;
225 
227  virtual void GotoNextBreakpoint();
228 
230  virtual void GotoPreviousBreakpoint();
231 
233  virtual void RefreshBreakpointMarkers();
234 
236  virtual void ClearAllBookmarks();
237 
239  virtual void ToggleBookmark(int line = -1);
240 
242  virtual bool HasBookmark(int line) const;
243 
245  virtual void GotoNextBookmark();
246 
248  virtual void GotoPreviousBookmark();
249 
251  virtual void SetDebugLine(int line);
252 
254  virtual void SetErrorLine(int line);
255 
258  void Split(SplitType split);
259 
261  void Unsplit();
262 
263  // the following functions, although self-explanatory, are documented
264  // in EditorBase.
265  void Undo() override;
266  void Redo() override;
267  void ClearHistory() override;
268  void GotoNextChanged() override;
269  void GotoPreviousChanged() override;
270  void SetChangeCollection(bool collectChange) override;
271  void Cut() override;
272  void Copy() override;
273  void Paste() override;
274  bool CanUndo() const override;
275  bool CanRedo() const override;
276  bool HasSelection() const override;
277  bool CanPaste() const override;
278  bool IsReadOnly() const override;
279  void SetReadOnly(bool readonly = true) override;
280 
281  bool CanSelectAll() const override;
282  void SelectAll() override;
283 
284  // Workaround for shift-tab bug in wx2.4.2
285  void DoIndent();
286  void DoUnIndent();
287 
288  // misc. functions
289  wxMenu* CreateContextSubMenu(long id) override;
290  void AddToContextMenu(wxMenu* popup,ModuleType type,bool pluginsdone) override; //pecan 2006/03/22
291 
292  HighlightLanguage GetLanguage( ) const { return m_lang; }
298  void SetLanguage(HighlightLanguage lang, bool colourise);
299 
300  wxFontEncoding GetEncoding( ) const;
301  wxString GetEncodingName( ) const;
302  void SetEncoding( wxFontEncoding encoding );
303 
304  bool GetUseBom() const;
305  void SetUseBom( bool bom );
306 
307  void SetZoom(int zoom, bool both = true);
308 
310  static void ApplyStyles(cbStyledTextCtrl* control);
311 
312  void AutoIndentDone();
313 
316  void SetEditorStyle();
317  private:
318  cbEditor(cb_unused const cbEditor& rhs); // prevent copy construction
319 
320  // functions
321  bool LineHasMarker(int marker, int line = -1) const;
322  void MarkerToggle(int marker, int line = -1);
323  void MarkerNext(int marker);
324  void MarkerPrevious(int marker);
325  void MarkLine(int marker, int line);
326 
327  enum class FoldMode : int
328  {
329  contract = 0, // wxSCI_FOLDACTION_CONTRACT
330  expand = 1, // wxSCI_FOLDACTION_EXPAND,
331  toggle = 2, //wxSCI_FOLDACTION_TOGGLE
332  };
333  enum FoldFlags : unsigned
334  {
335  none = 0x0,
336  ensureVisible = 0x2,
337  };
338 
339  void DoFoldAll(FoldMode fold);
340  void DoFoldBlockFromLine(int line, FoldMode fold, unsigned foldFlags);
341  void SetMarkerStyle(int marker, int markerType, wxColor fore, wxColor back);
342  void UnderlineFoldedLines(bool underline);
343  cbStyledTextCtrl* CreateEditor();
344  void ConnectEvents(cbStyledTextCtrl* stc);
345  void SetEditorStyleBeforeFileOpen();
346  void SetEditorStyleAfterFileOpen();
347  static void InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control);
348  static void InternalSetEditorStyleAfterFileOpen(cbStyledTextCtrl* control);
349  bool Open(bool detectEncoding = true);
350  void DoAskForCodeCompletion(); // relevant to code-completion plugins
351  void SetLanguageDependentColours(cbStyledTextCtrl &control);
352  void NotifyPlugins(wxEventType type, int intArg = 0, const wxString& strArg = wxEmptyString, int xArg = 0, int yArg = 0);
353 
354  // events
355  void OnMarginClick(wxScintillaEvent& event);
356  void OnEditorUpdateUI(wxScintillaEvent& event);
357  void OnEditorChange(wxScintillaEvent& event);
358  void OnEditorCharAdded(wxScintillaEvent& event);
359  void OnEditorDwellStart(wxScintillaEvent& event);
360  void OnEditorDwellEnd(wxScintillaEvent& event);
361  void OnEditorModified(wxScintillaEvent& event);
362  void OnUserListSelection(wxScintillaEvent& event);
363  void OnZoom(wxScintillaEvent& event);
369  void OnScintillaEvent(wxScintillaEvent& event);
370  void OnClose(wxCloseEvent& event);
371 
372  // one event handler for all popup menu entries
373  void OnContextMenuEntry(wxCommandEvent& event);
374  bool OnBeforeBuildContextMenu(const wxPoint& position, ModuleType type) override; //pecan 2006/03/22
375  void OnAfterBuildContextMenu(ModuleType type) override; //pecan 2006/03/22
376 
377  void DestroySplitView();
378 
379  void DoInitializations(const wxString& filename, LoaderBase* fileLdr = nullptr);
380 
381  void BreakpointMarkerToggle(int line);
382 
383  // variables
384  bool m_IsOK;
392  int m_Index;
397  wxDateTime m_LastModified; // to check if the file was modified outside the editor
399 
400  // DO NOT ADD ANY MORE VARIABLES HERE!
401  // ADD THEM IN cbEditorInternalData INSTEAD!
402 
403  friend struct cbEditorInternalData; // allow cbEditorInternalData to access cbEditor
405 };
406 
407 #endif // CBEDITOR_H
cbStyledTextCtrl * m_pControl
Definition: cbeditor.h:387
virtual wxMenu * CreateContextSubMenu(long id)
Creates context submenus.
Definition: editorbase.cpp:219
virtual void SetReadOnly(bool=true)
Set the editor read-only.
Definition: editorbase.h:223
virtual bool CanPaste() const
Is there something to paste?
Definition: editorbase.h:211
wxSplitterWindow * m_pSplitter
Definition: cbeditor.h:385
virtual bool HasSelection() const
Is there a selection?
Definition: editorbase.h:205
wxDateTime GetLastModificationTime() const
Returns the last modification time for the file.
Definition: cbeditor.h:185
virtual void AddToContextMenu(cb_optional wxMenu *popup, cb_optional ModuleType type, cb_optional bool pluginsdone)
Creates context menu items, both before and after creating plugins menu items.
Definition: editorbase.h:257
cbEditorInternalData * m_pData
Definition: cbeditor.h:404
bool IsOK() const
Returns true if editor is OK, i.e.
Definition: cbeditor.h:101
virtual void SelectAll()
Select everything in the editor.
Definition: editorbase.h:233
EditorColourSet * m_pTheme
Definition: cbeditor.h:395
virtual bool IsReadOnly() const
Is the editor read-only?
Definition: editorbase.h:217
virtual void Redo()
Redo changes.
Definition: editorbase.h:166
PrintColourMode
virtual void SetChangeCollection(cb_optional bool collectChange)
Enable or disable changebar.
Definition: editorbase.h:178
virtual void Paste()
Paste selected text/object from clipboard.
Definition: editorbase.h:187
cbStyledTextCtrl * m_pControl2
Definition: cbeditor.h:388
bool m_Modified
Definition: cbeditor.h:391
#define _T(string)
virtual bool CanRedo() const
Is there something to redo?
Definition: editorbase.h:199
cbStyledTextCtrl * GetLeftSplitViewControl() const
Returns a pointer to the left (or top) split-view cbStyledTextCtrl.
Definition: cbeditor.h:87
wxFontEncoding
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
virtual void Copy()
Copy selected text/object to clipboard.
Definition: editorbase.h:184
#define DLLIMPORT
Definition: settings.h:16
virtual void SetModified(bool=true)
Set the modification status.
Definition: editorbase.h:73
cbStyledTextCtrl * m_foldBackup
Definition: cbeditor.h:389
wxBoxSizer * m_pSizer
Definition: cbeditor.h:386
bool m_autoIndentDone
Definition: cbeditor.h:398
ModuleType
The type of module offering a context menu.
Definition: globals.h:38
virtual bool SaveAs()
Save editor contents under a different filename.
Definition: editorbase.h:120
EditorColourSet * GetColourSet() const
Get the colour set in use.
Definition: cbeditor.h:170
Base class that all "editors" should inherit from.
Definition: editorbase.h:30
bool m_IsOK
Definition: cbeditor.h:384
const wxString g_EditorModified
Definition: cbeditor.cpp:55
wxTimer m_timerWait
Definition: cbeditor.h:393
virtual void Undo()
Undo changes.
Definition: editorbase.h:163
void operator=(cb_unused const cbEditor &rhs)
Don&#39;t use this.
Definition: cbeditor.h:70
#define cbThrow(message)
Definition: cbexception.h:42
virtual bool GetModified() const
Is it modified?
Definition: editorbase.h:67
HighlightLanguage m_lang
Definition: cbeditor.h:396
SplitType GetSplitType() const
Returns the state of split-view for this editor.
Definition: cbeditor.h:95
A file editor.
Definition: cbeditor.h:43
ProjectFile * m_pProjectFile
Definition: cbeditor.h:394
virtual void ClearHistory()
Clear Undo- (and Changebar-) history.
Definition: editorbase.h:169
SplitType m_SplitType
Definition: cbeditor.h:390
virtual void GotoLine(int, bool=true)
Move the caret at the specified line.
Definition: editorbase.h:160
bool HasBreakpoint(cbDebuggerPlugin &plugin, wxString const &filename, int line)
Definition: cbplugin.cpp:360
ProjectFile * GetProjectFile() const
Read the ProjectFile pointer associated with this editor.
Definition: cbeditor.h:123
int wxEventType
virtual void Cut()
Cut selected text/object to clipboard.
Definition: editorbase.h:181
virtual bool CanSelectAll() const
Can the editor select everything?
Definition: editorbase.h:229
int m_Index
Definition: cbeditor.h:392
cbStyledTextCtrl * GetRightSplitViewControl() const
Returns a pointer to the right (or bottom) split-view cbStyledTextCtrl.
Definition: cbeditor.h:92
HighlightLanguage GetLanguage() const
Definition: cbeditor.h:292
virtual bool CanUndo() const
Is there something to undo?
Definition: editorbase.h:193
virtual bool Save()
Save contents.
Definition: editorbase.h:113
virtual void GotoPreviousChanged()
Goto previous changed line.
Definition: editorbase.h:175
wxDateTime m_LastModified
Definition: cbeditor.h:397
virtual void GotoNextChanged()
Goto next changed line.
Definition: editorbase.h:172