4
#include <wx/hashmap.h>
5
#include <wx/datetime.h>
6
#include <wx/fontmap.h>
8
#include "wx/wxscintilla.h"
10
#include "editorbase.h"
11
#include "printing_types.h"
13
extern const wxString g_EditorModified;
16
struct cbEditorInternalData; // this is the private data struct used by the editor.
19
class EditorColourSet;
20
class wxSplitterWindow;
22
class cbStyledTextCtrl : public wxScintilla
25
cbStyledTextCtrl(wxWindow* pParent, int id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
26
virtual ~cbStyledTextCtrl();
28
void OnContextMenu(wxContextMenuEvent& event);
29
void OnKillFocus(wxFocusEvent& event);
30
void OnGPM(wxMouseEvent& event);
36
/** @brief A file editor
38
* This class represents one builtin editor in Code::Blocks. It holds all the necessary
39
* information about an editor. When you want to access a Code::Blocks editor,
40
* this is the class you want to get at ;)\n
42
* To do this, use Manager::Get()->GetEditorManager() functions.
44
* The actual editor component used is Scintilla and it can be accessed through
45
* the member function GetControl().
47
class DLLIMPORT cbEditor : public EditorBase
50
friend class EditorManager;
53
/** cbEditor constructor.
54
* @param parent the parent notebook - you should use EditorManager::Get()
55
* @param filename the filename to open. If filename is empty, it creates a
57
* @param theme the initial colour set to use\n
58
* <em>Note: you cannot create a cbEditor object directly. Instead
59
* use EditorManager's methods to do it...</em>
61
cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme = 0L);
62
/** Don't use this. It throws an exception if you do. */
63
cbEditor(const cbEditor& rhs) : EditorBase(rhs) { cbThrow(_T("Can't call cbEditor's copy ctor!!!")); }
64
/** cbEditor destructor. */
74
/** Don't use this. It throws an exception if you do. */
75
virtual void operator=(const cbEditor& rhs){ cbThrow(_T("Can't assign an cbEditor* !!!")); }
79
/** Returns a pointer to the underlying cbStyledTextCtrl object (which
80
* itself is the wxWindows implementation of Scintilla). If you want
81
* to mess with the actual contents of an editor, this is the object
83
* @remarks If the editor is split, this function returns the control
84
* which currently has the keyboard focus. Don't save this pointer
85
* because it might be invalid at any later time...
87
cbStyledTextCtrl* GetControl() const;
89
/** Returns a pointer to the left (or top) split-view cbStyledTextCtrl.
90
* This function always returns a valid pointer.
92
cbStyledTextCtrl* GetLeftSplitViewControl() const { return m_pControl; }
94
/** Returns a pointer to the right (or bottom) split-view cbStyledTextCtrl.
95
* This function may return NULL if the editor is not split.
97
cbStyledTextCtrl* GetRightSplitViewControl() const { return m_pControl2; }
99
/** Returns the state of split-view for this editor. */
100
SplitType GetSplitType() const { return m_SplitType; }
102
/** Returns true if editor is OK, i.e. constructor was called with a filename
103
* parameter and file was opened succesfully. If it returns false, you
104
* should delete the editor...
106
bool IsOK() const { return m_IsOK; }
108
/** Sets the editor title. For tabbed interface, it sets the corresponding
109
* tab text, while for MDI interface it sets the MDI window title...
111
void SetEditorTitle(const wxString& title);
113
/** Returns true if editor is modified, false otherwise */
114
bool GetModified() const;
116
/** Set the editor's modification state to \c modified. */
117
void SetModified(bool modified = true);
119
/** Set the ProjectFile pointer associated with this editor. All editors
120
* which belong to a project file, should have this set. All others should return NULL.
121
* Optionally you can preserve the "modified" flag of the file.
123
void SetProjectFile(ProjectFile* project_file,bool preserve_modified = false);
125
/** Read the ProjectFile pointer associated with this editor. All editors
126
* which belong to a project file, have this set. All others return NULL.
128
ProjectFile* GetProjectFile() const { return m_pProjectFile; }
130
/** Updates the associated ProjectFile object with the editor's caret
131
* position, top visible line and its open state. Used in devProject
132
* layout information, so that each time the user opens a project
133
* file in the IDE, it opens exactly in the same state it was when last
136
void UpdateProjectFile();
138
/** Save editor contents. Returns true on success, false otherwise. */
141
/** Save editor contents under a different filename. Returns true on success, false otherwise. */
145
bool RenameTo(const wxString& filename, bool deleteOldFromDisk = false);
147
/** Save fold states within a new cbStyledTextCtrl. This saves the whole document, thus saving the fold states before the Fold Options Change*/
148
bool SaveFoldState();
150
/** Fix fold states by comparing foldBackup with m_pControl. This is a temp fix for the Scintilla bug*/
153
/** Fold all editor folds (hides blocks of code). */
156
/** Unfold all editor folds (shows blocks of code). */
159
/** Toggle all editor folds (inverts the show/hide state of blocks of code). */
160
void ToggleAllFolds();
162
/** Folds the block containing \c line. If \c line is -1, folds the block containing the caret. */
163
void FoldBlockFromLine(int line = -1);
165
/** Unfolds the block containing \c line. If \c line is -1, unfolds the block containing the caret. */
166
void UnfoldBlockFromLine(int line = -1);
168
/** Toggles folding of the block containing \c line. If \c line is -1, toggles folding of the block containing the caret. */
169
void ToggleFoldBlockFromLine(int line = -1);
171
/** Set the colour set to use. */
172
void SetColourSet(EditorColourSet* theme);
174
/** Get the colour set in use. */
175
EditorColourSet* GetColourSet() const { return m_pTheme; }
177
/** Jumps to the matching brace (if there is one). */
178
void GotoMatchingBrace();
180
/** Highlights the brace pair (one of the braces must be under the cursor) */
181
void HighlightBraces();
183
/** Returns the specified line's (0-based) indentation (whitespace) in spaces. If line is -1, it uses the current line */
184
int GetLineIndentInSpaces(int line = -1) const;
186
/** Returns the specified line's (0-based) indentation (whitespace) string. If line is -1, it uses the current line */
187
wxString GetLineIndentString(int line = -1) const;
189
/** Returns the last modification time for the file. Used to detect modifications outside the editor. */
190
wxDateTime GetLastModificationTime() const { return m_LastModified; }
192
/** Sets the last modification time for the file to 'now'. Used to detect modifications outside the editor. */
195
/** Reloads the file from disk. @return True on success, False on failure. */
196
bool Reload(bool detectEncoding = true);
199
* @param selectionOnly Should the selected text be printed only?
200
* @param pcm The colour mode to use when printing
201
* @param line_numbers Print the line numbers of file, too.
203
void Print(bool selectionOnly, PrintColourMode pcm, bool line_numbers);
205
/** Try to auto-complete the current word.
207
* This has nothing to do with code-completion plugins. Editor auto-completion
208
* is a feature that saves typing common blocks of code, e.g.
210
* If you have typed "forb" (no quotes) and select auto-complete, then
211
* it will convert "forb" to "for ( ; ; ){ }".
212
* If the word up to the caret position is an unknown keyword, nothing happens.
214
* These keywords/code pairs can be edited in the editor configuration
219
/** Move the caret at the specified line.
220
* @param line Line to move caret to.
221
* @param centerOnScreen If true (default), tries to bring the specified line to the centre of the editor.*/
222
void GotoLine(int line, bool centerOnScreen = true);
224
/** Add debugger breakpoint at specified line. If @c line is -1, use current line. */
225
bool AddBreakpoint(int line = -1, bool notifyDebugger = true);
227
/** Remove debugger breakpoint at specified line. If @c line is -1, use current line. */
228
bool RemoveBreakpoint(int line = -1, bool notifyDebugger = true);
230
/** Toggle debugger breakpoint at specified line. If @c line is -1, use current line. */
231
void ToggleBreakpoint(int line = -1, bool notifyDebugger = true);
233
/** Does @c line has debugger breakpoint? If @c line is -1, use current line. */
234
bool HasBreakpoint(int line) const;
236
/** Go to next debugger breakpoint. */
237
void GotoNextBreakpoint();
239
/** Go to previous debugger breakpoint. */
240
void GotoPreviousBreakpoint();
242
/** Toggle bookmark at specified line. If @c line is -1, use current line. */
243
void ToggleBookmark(int line = -1);
245
/** Does @c line has bookmark? */
246
bool HasBookmark(int line) const;
248
/** Go to next bookmark. */
249
void GotoNextBookmark();
251
/** Go to previous bookmark. */
252
void GotoPreviousBookmark();
254
/** Highlight the line the debugger will execute next. */
255
void SetDebugLine(int line);
257
/** Highlight the specified line as error. */
258
void SetErrorLine(int line);
260
/** Split the editor window.
261
* @param split The type of split: horizontal or vertical. */
262
void Split(SplitType split);
264
/** Unsplit the editor window. */
267
// the following functions, although self-explanatory, are documented
274
bool CanUndo() const;
275
bool CanRedo() const;
276
bool HasSelection() const;
277
bool CanPaste() const;
279
// Workaround for shift-tab bug in wx2.4.2
280
void DoIndent(); /// Indents current line/block
281
void DoUnIndent(); /// UnIndents current line/block
284
virtual wxMenu* CreateContextSubMenu(long id);
285
virtual void AddToContextMenu(wxMenu* popup,ModuleType type,bool pluginsdone); //pecan 2006/03/22
287
HighlightLanguage GetLanguage( ) const { return m_lang; }
288
void SetLanguage( HighlightLanguage lang = HL_AUTO );
290
wxFontEncoding GetEncoding( ) const;
291
wxString GetEncodingName( ) const;
292
void SetEncoding( wxFontEncoding encoding );
294
bool GetUseBom() const;
295
void SetUseBom( bool bom );
297
/// Apply the editor defaults to any (possibly foreign) cbStyledTextCtrl.
298
static void ApplyStyles(cbStyledTextCtrl* control);
301
bool LineHasMarker(int marker, int line = -1) const;
302
void MarkerToggle(int marker, int line = -1);
303
void MarkerNext(int marker);
304
void MarkerPrevious(int marker);
305
void MarkLine(int marker, int line);
307
void DoFoldAll(int fold); // 0=unfold, 1=fold, 2=toggle
308
void DoFoldBlockFromLine(int line, int fold); // 0=unfold, 1=fold, 2=toggle
309
bool DoFoldLine(int line, int fold); // 0=unfold, 1=fold, 2=toggle
310
cbStyledTextCtrl* CreateEditor();
311
void SetEditorStyle();
312
void SetEditorStyleBeforeFileOpen();
313
void SetEditorStyleAfterFileOpen();
314
static void InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control);
315
static void InternalSetEditorStyleAfterFileOpen(cbStyledTextCtrl* control);
316
void DetectEncoding();
317
bool Open(bool detectEncoding = true);
318
void DoAskForCodeCompletion(); // relevant to code-completion plugins
319
static wxColour GetOptionColour(const wxString& option, const wxColour _default);
320
void NotifyPlugins(wxEventType type, int intArg = 0, const wxString& strArg = wxEmptyString, int xArg = 0, int yArg = 0);
323
void OnMarginClick(wxScintillaEvent& event);
324
void OnEditorUpdateUI(wxScintillaEvent& event);
325
void OnEditorChange(wxScintillaEvent& event);
326
void OnEditorCharAdded(wxScintillaEvent& event);
327
void OnEditorDwellStart(wxScintillaEvent& event);
328
void OnEditorDwellEnd(wxScintillaEvent& event);
329
void OnEditorModified(wxScintillaEvent& event);
330
void OnUserListSelection(wxScintillaEvent& event);
331
void OnZoom(wxScintillaEvent& event);
332
void OnScintillaEvent(wxScintillaEvent& event);
333
void OnClose(wxCloseEvent& event);
335
// one event handler for all popup menu entries
336
void OnContextMenuEntry(wxCommandEvent& event);
337
bool OnBeforeBuildContextMenu(const wxPoint& position, ModuleType type); //pecan 2006/03/22
338
void OnAfterBuildContextMenu(ModuleType type); //pecan 2006/03/22
340
void DestroySplitView();
344
wxSplitterWindow* m_pSplitter;
345
wxBoxSizer* m_pSizer;
346
cbStyledTextCtrl* m_pControl;
347
cbStyledTextCtrl* m_pControl2;
348
cbStyledTextCtrl* m_foldBackup;
349
SplitType m_SplitType;
354
ProjectFile* m_pProjectFile;
355
EditorColourSet* m_pTheme;
356
HighlightLanguage m_lang;
357
wxDateTime m_LastModified; // to check if the file was modified outside the editor
359
// DO NOT ADD ANY MORE VARIABLES HERE!
360
// ADD THEM IN cbEditorInternalData INSTEAD!
362
friend struct cbEditorInternalData; // allow cbEditorInternalData to access cbEditor
363
cbEditorInternalData* m_pData;