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
9
#include <wx/hashmap.h>
10
#include <wx/datetime.h>
11
#include <wx/fontmap.h>
15
#include "seditorbase.h"
16
#include "printing_types.h"
18
extern const wxString g_EditorModified;
21
struct ScbEditorInternalData; // this is the private data struct used by the editor.
24
class SEditorColourSet;
25
class wxSplitterWindow;
27
class cbStyledTextCtrl;
28
class wxScintillaEvent;
32
/** @brief A file editor
34
* This class represents one builtin editor in Code::Blocks. It holds all the necessary
35
* information about an editor. When you want to access a Code::Blocks editor,
36
* this is the class you want to get at ;)\n
38
* To do this, use SnippetsSearchFrame::GetEditorManager() functions.
40
* The actual editor component used is Scintilla and it can be accessed through
41
* the member function GetControl().
43
//-class DLLIMPORT cbEditor : public EditorBase
44
class ScbEditor : public SEditorBase
47
friend class SEditorManager;
50
/** ScbEditor constructor.
51
* @param parent the parent notebook - you should use EditorManager::Get()
52
* @param filename the filename to open. If filename is empty, it creates a
54
* @param theme the initial colour set to use\n
55
* <em>Note: you cannot create a ScbEditor object directly. Instead
56
* use EditorManager's methods to do it...</em>
58
ScbEditor(wxWindow* parent, const wxString& filename, SEditorColourSet* theme = 0L);
59
ScbEditor(wxWindow* parent, LoaderBase* fileLdr, const wxString& filename, SEditorColourSet* theme = 0L);
60
/** Don't use this. It throws an exception if you do. */
61
ScbEditor(const ScbEditor& rhs) : SEditorBase(rhs) { cbThrow(_T("Can't call ScbEditor's copy ctor!!!")); }
62
/** ScbEditor destructor. */
72
/** Don't use this. It throws an exception if you do. */
73
virtual void operator=(const ScbEditor& rhs){ cbThrow(_T("Can't assign an ScbEditor* !!!")); }
77
/** Returns a pointer to the underlying cbStyledTextCtrl object (which
78
* itself is the wxWindows implementation of Scintilla). If you want
79
* to mess with the actual contents of an editor, this is the object
81
* @remarks If the editor is split, this function returns the control
82
* which currently has the keyboard focus. Don't save this pointer
83
* because it might be invalid at any later time...
85
cbStyledTextCtrl* GetControl() const;
87
/** Returns a pointer to the left (or top) split-view cbStyledTextCtrl.
88
* This function always returns a valid pointer.
90
cbStyledTextCtrl* GetLeftSplitViewControl() const { return m_pControl; }
92
/** Returns a pointer to the right (or bottom) split-view cbStyledTextCtrl.
93
* This function may return NULL if the editor is not split.
95
cbStyledTextCtrl* GetRightSplitViewControl() const { return m_pControl2; }
97
/** Returns the state of split-view for this editor. */
98
SplitType GetSplitType() const { return m_SplitType; }
100
/** Returns true if editor is OK, i.e. constructor was called with a filename
101
* parameter and file was opened succesfully. If it returns false, you
102
* should delete the editor...
104
bool IsOK() const { return m_IsOK; }
106
/** Sets the editor title. For tabbed interface, it sets the corresponding
107
* tab text, while for MDI interface it sets the MDI window title...
109
void SetEditorTitle(const wxString& title);
111
/** Returns true if editor is modified, false otherwise */
112
bool GetModified() const;
114
/** Set the editor's modification state to \c modified. */
115
void SetModified(bool modified = true);
117
/** Set the ProjectFile pointer associated with this editor. All editors
118
* which belong to a project file, should have this set. All others should return NULL.
119
* Optionally you can preserve the "modified" flag of the file.
121
void SetProjectFile(ProjectFile* project_file,bool preserve_modified = false);
123
/** Read the ProjectFile pointer associated with this editor. All editors
124
* which belong to a project file, have this set. All others return NULL.
126
ProjectFile* GetProjectFile() const { return m_pProjectFile; }
128
/** Updates the associated ProjectFile object with the editor's caret
129
* position, top visible line and its open state. Used in devProject
130
* layout information, so that each time the user opens a project
131
* file in the IDE, it opens exactly in the same state it was when last
134
void UpdateProjectFile();
136
/** Save editor contents. Returns true on success, false otherwise. */
139
/** Save editor contents under a different filename. Returns true on success, false otherwise. */
142
/** Save fold states within a new cbStyledTextCtrl. This saves the whole document, thus saving the fold states before the Fold Options Change*/
143
bool SaveFoldState();
145
/** Fix fold states by comparing foldBackup with m_pControl. This is a temp fix for the Scintilla bug*/
148
/** Fold all editor folds (hides blocks of code). */
151
/** Unfold all editor folds (shows blocks of code). */
154
/** Toggle all editor folds (inverts the show/hide state of blocks of code). */
155
void ToggleAllFolds();
157
/** Sets the type of folding indicator where id is one of the following: 0->Arrow, 1->Circle, 2->Square, 3->simple */
158
void SetFoldingIndicator(int id);
160
/** Folds the block containing \c line. If \c line is -1, folds the block containing the caret. */
161
void FoldBlockFromLine(int line = -1);
163
/** Unfolds the block containing \c line. If \c line is -1, unfolds the block containing the caret. */
164
void UnfoldBlockFromLine(int line = -1);
166
/** Toggles folding of the block containing \c line. If \c line is -1, toggles folding of the block containing the caret. */
167
void ToggleFoldBlockFromLine(int line = -1);
169
/** Set the colour set to use. */
170
void SetColourSet(SEditorColourSet* theme);
172
/** Get the colour set in use. */
173
SEditorColourSet* GetColourSet() const { return m_pTheme; }
175
/** Jumps to the matching brace (if there is one). */
176
void GotoMatchingBrace();
178
/** Highlights the brace pair (one of the braces must be under the cursor) */
179
void HighlightBraces();
181
/** Returns the specified line's (0-based) indentation (whitespace) in spaces. If line is -1, it uses the current line */
182
int GetLineIndentInSpaces(int line = -1) const;
184
/** Returns the specified line's (0-based) indentation (whitespace) string. If line is -1, it uses the current line */
185
wxString GetLineIndentString(int line = -1) const;
187
/** Returns the last modification time for the file. Used to detect modifications outside the editor. */
188
wxDateTime GetLastModificationTime() const { return m_LastModified; }
190
/** Sets the last modification time for the file to 'now'. Used to detect modifications outside the editor. */
193
/** Reloads the file from disk. @return True on success, False on failure. */
194
bool Reload(bool detectEncoding = true);
197
* @param selectionOnly Should the selected text be printed only?
198
* @param pcm The colour mode to use when printing
199
* @param line_numbers Print the line numbers of file, too.
201
void Print(bool selectionOnly, PrintColourMode pcm, bool line_numbers);
203
/** Try to auto-complete the current word.
205
* This has nothing to do with code-completion plugins. Editor auto-completion
206
* is a feature that saves typing common blocks of code, e.g.
208
* If you have typed "forb" (no quotes) and select auto-complete, then
209
* it will convert "forb" to "for ( ; ; ){ }".
210
* If the word up to the caret position is an unknown keyword, nothing happens.
212
* These keywords/code pairs can be edited in the editor configuration
217
/** Move the caret at the specified line.
218
* @param line Line to move caret to.
219
* @param centerOnScreen If true (default), tries to bring the specified line to the centre of the editor.*/
220
void GotoLine(int line, bool centerOnScreen = true);
222
/** Add debugger breakpoint at specified line. If @c line is -1, use current line. */
223
bool AddBreakpoint(int line = -1, bool notifyDebugger = true);
225
/** Remove debugger breakpoint at specified line. If @c line is -1, use current line. */
226
bool RemoveBreakpoint(int line = -1, bool notifyDebugger = true);
228
/** Toggle debugger breakpoint at specified line. If @c line is -1, use current line. */
229
void ToggleBreakpoint(int line = -1, bool notifyDebugger = true);
231
/** Does @c line has debugger breakpoint? If @c line is -1, use current line. */
232
bool HasBreakpoint(int line) const;
234
/** Go to next debugger breakpoint. */
235
void GotoNextBreakpoint();
237
/** Go to previous debugger breakpoint. */
238
void GotoPreviousBreakpoint();
240
/** Toggle bookmark at specified line. If @c line is -1, use current line. */
241
void ToggleBookmark(int line = -1);
243
/** Does @c line has bookmark? */
244
bool HasBookmark(int line) const;
246
/** Go to next bookmark. */
247
void GotoNextBookmark();
249
/** Go to previous bookmark. */
250
void GotoPreviousBookmark();
252
/** Highlight the line the debugger will execute next. */
253
void SetDebugLine(int line);
255
/** Highlight the specified line as error. */
256
void SetErrorLine(int line);
258
/** Split the editor window.
259
* @param split The type of split: horizontal or vertical. */
260
void Split(SplitType split);
262
/** Unsplit the editor window. */
265
// the following functions, although self-explanatory, are documented
272
bool CanUndo() const;
273
bool CanRedo() const;
274
bool HasSelection() const;
275
bool CanPaste() const;
276
bool IsReadOnly() const;
278
// Workaround for shift-tab bug in wx2.4.2
279
void DoIndent(); /// Indents current line/block
280
void DoUnIndent(); /// UnIndents current line/block
283
virtual wxMenu* CreateContextSubMenu(long id);
284
virtual void AddToContextMenu(wxMenu* popup,ModuleType type,bool pluginsdone); //pecan 2006/03/22
286
HighlightLanguage GetLanguage( ) const { return m_lang; }
287
void SetLanguage( HighlightLanguage lang = HL_AUTO );
289
wxFontEncoding GetEncoding( ) const;
290
wxString GetEncodingName( ) const;
291
void SetEncoding( wxFontEncoding encoding );
293
bool GetUseBom() const;
294
void SetUseBom( bool bom );
296
/// Apply the editor defaults to any (possibly foreign) cbStyledTextCtrl.
297
static void ApplyStyles(cbStyledTextCtrl* control);
300
bool LineHasMarker(int marker, int line = -1) const;
301
void MarkerToggle(int marker, int line = -1);
302
void MarkerNext(int marker);
303
void MarkerPrevious(int marker);
304
void MarkLine(int marker, int line);
306
void DoFoldAll(int fold); // 0=unfold, 1=fold, 2=toggle
307
void DoFoldBlockFromLine(int line, int fold); // 0=unfold, 1=fold, 2=toggle
308
bool DoFoldLine(int line, int fold); // 0=unfold, 1=fold, 2=toggle
309
void SetMarkerStyle(int marker, int markerType, wxColor fore, wxColor back);
310
void UnderlineFoldedLines(bool underline);
311
cbStyledTextCtrl* CreateEditor();
312
void SetEditorStyle();
313
void SetEditorStyleBeforeFileOpen();
314
void SetEditorStyleAfterFileOpen();
315
static void InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control);
316
static void InternalSetEditorStyleAfterFileOpen(cbStyledTextCtrl* control);
317
void DetectEncoding();
318
bool Open(bool detectEncoding = true);
319
void DoAskForCodeCompletion(); // relevant to code-completion plugins
320
static wxColour GetOptionColour(const wxString& option, const wxColour _default);
321
void NotifyPlugins(wxEventType type, int intArg = 0, const wxString& strArg = wxEmptyString, int xArg = 0, int yArg = 0);
324
void OnMarginClick(wxScintillaEvent& event);
325
void OnEditorUpdateUI(wxScintillaEvent& event);
326
void OnEditorChange(wxScintillaEvent& event);
327
void OnEditorCharAdded(wxScintillaEvent& event);
328
void OnEditorDwellStart(wxScintillaEvent& event);
329
void OnEditorDwellEnd(wxScintillaEvent& event);
330
void OnEditorModified(wxScintillaEvent& event);
331
void OnUserListSelection(wxScintillaEvent& event);
332
void OnZoom(wxScintillaEvent& event);
333
void OnScintillaEvent(wxScintillaEvent& event);
334
void OnClose(wxCloseEvent& event);
336
// one event handler for all popup menu entries
337
void OnContextMenuEntry(wxCommandEvent& event);
338
bool OnBeforeBuildContextMenu(const wxPoint& position, ModuleType type); //pecan 2006/03/22
339
void OnAfterBuildContextMenu(ModuleType type); //pecan 2006/03/22
341
void DestroySplitView();
343
void DoInitializations(const wxString& filename, LoaderBase* fileLdr = 0);
347
wxSplitterWindow* m_pSplitter;
348
wxBoxSizer* m_pSizer;
349
cbStyledTextCtrl* m_pControl;
350
cbStyledTextCtrl* m_pControl2;
351
cbStyledTextCtrl* m_foldBackup;
352
SplitType m_SplitType;
357
ProjectFile* m_pProjectFile;
358
SEditorColourSet* m_pTheme;
359
HighlightLanguage m_lang;
360
wxDateTime m_LastModified; // to check if the file was modified outside the editor
362
// DO NOT ADD ANY MORE VARIABLES HERE!
363
// ADD THEM IN cbEditorInternalData INSTEAD!
365
friend struct ScbEditorInternalData; // allow cbEditorInternalData to access ScbEditor
366
ScbEditorInternalData* m_pData;
369
#endif // SCBEDITOR_H