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>
14
#include "cbexception.h"
19
struct EditorBaseInternalData;
21
WX_DECLARE_HASH_MAP(int, SEditorBase*, wxIntegerHash, wxIntegerEqual, SSwitchToMap);
23
/** @brief Base class that all "editors" should inherit from.
25
* @note This class descends from wxPanel, so it provides all wxPanel methods
28
//class DLLIMPORT EditorBase : public wxPanel
29
// ----------------------------------------------------------------------------
30
class SEditorBase : public wxPanel
31
// ----------------------------------------------------------------------------
35
SEditorBase(wxWindow* parent, const wxString& filename);
36
virtual ~SEditorBase();
38
/** Don't use this. It throws an exception if you do. */
39
SEditorBase(const SEditorBase& rhs) { cbThrow(_T("Can't call SEditorBase's copy ctor!!!")); }
41
/** Don't use this. It throws an exception if you do. */
42
virtual void operator=(const SEditorBase& rhs){ cbThrow(_T("Can't assign an SEditorBase* !!!")); }
44
/** @brief Get the editor's filename (if applicable).
46
* @return The editor's filename.
48
virtual const wxString& GetFilename() const { return m_Filename; }
50
/** @brief Sets the editor's filename.
51
* @param filename The filename to set.
53
virtual void SetFilename(const wxString& filename){ m_Filename = filename; }
55
/** @brief Returns the editor's short name.
57
* This is the name displayed on the editor's tab...
59
* Synonym to GetTitle().
61
virtual const wxString& GetShortName() const { return m_Shortname; }
63
/** @brief Is it modified?
65
* @return true If editor is modified, false otherwise.
66
* @note This function should always be overriden by implementations
67
* because the default implementation in SEditorBase always
70
virtual bool GetModified() const { return false; }
72
/** @brief Set the modification status.
74
* @param modified If true, mark as modified. If false, mark as clean (unmodified).
76
virtual void SetModified(bool modified = true) {}
78
/** @brief The editor's title.
80
* @return The editor's title.
82
virtual const wxString& GetTitle();
84
/** @brief Set the editor's title.
86
* @param newTitle The new title to set.
88
virtual void SetTitle(const wxString& newTitle);
90
/** @brief Activate this editor.
92
* Causes this editor to be activated, i.e. brought to front.
94
virtual void Activate();
96
/** @brief Can this be closed (destroyed)?
98
* This is used internally and queries the editor if it is safe to
99
* close it (i.e. it is not modified).
100
* @return True if this editor can be closed.
102
virtual bool QueryClose(){ return true; }
104
/** @brief Close this editor.
106
* The default implementation closes (destroys) the editor and returns true.
107
* @return True if editor closed succesfully
109
virtual bool Close();
111
/** @brief Save contents.
113
* Save the editor's contents. The default implementation does nothing
115
* @return True on success, false otherwise. */
116
virtual bool Save() { return true; }
118
/** @brief Is this a built-in editor?
120
* Query if this is a built-in editor (a.k.a cbEditor).
121
* @return True if it is a cbEditor, false otherwise.
123
virtual bool IsBuiltinEditor() const;
125
/** @brief Are there other editors besides this?
126
* @return True if there are more editors open, false otherwise.
128
virtual bool ThereAreOthers() const;
130
/** @brief Display context menu.
132
* Displays the editor's context menu. This is called automatically
133
* if the user right-clicks in the editor area.
134
* @param position The position to popup the context menu.
135
* @param type The module's type.
137
virtual void DisplayContextMenu(const wxPoint& position, ModuleType type = mtUnknown);
139
/** Should this kind of editor be visible in the open files tree?
141
* There are rare cases where an editor should not be visible in the
142
* open files tree. One such example is the "Start here" page...
144
* @return True if it should be visible in the open files tree, false
147
virtual bool VisibleToTree() const { return true; }
149
/** Move the caret at the specified line.
151
* @param line The line to move the caret to.
152
* @param centerOnScreen If true, the line in question will be in the center
153
* of the editor's area (if possible). If false,
154
* it will be just made visible.
156
virtual void GotoLine(int line, bool centerOnScreen = true){}
158
/** Toggle breakpoint at specified line.
159
* @param line The line to toggle the breakpoint on. If @c line is -1,
161
* @param notifyDebugger If true (and a debugger plugin is loaded),
162
* tell the debugger about this breakpoint.
164
virtual void ToggleBreakpoint(int line = -1, bool notifyDebugger = true){}
166
/** Does @c line has breakpoint?
167
* @param line The line to check for breakpoint existence.
168
* @return True if there is a breakpoint on this line, false if not.
170
virtual bool HasBreakpoint(int line) const { return false; }
172
/** Go to next breakpoint. */
173
virtual void GotoNextBreakpoint(){}
175
/** Go to previous breakpoint. */
176
virtual void GotoPreviousBreakpoint(){}
178
/** Toggle bookmark at specified line.
179
* @param line The line to toggle the bookmark on. If @c line is -1,
182
virtual void ToggleBookmark(int line = -1){}
184
/** Does @c line has bookmark?
185
* @param line The line to check for bookmark existence.
186
* @return True if there is a bookmark on this line, false if not.
188
virtual bool HasBookmark(int line) const { return false; }
190
/** Go to next bookmark. */
191
virtual void GotoNextBookmark(){}
193
/** Go to previous bookmark. */
194
virtual void GotoPreviousBookmark(){}
196
/** @brief Mark the debugger's active line.
198
* Highlight the line the debugger will execute next.
199
* @param line The line in question.
201
virtual void SetDebugLine(int line){}
203
/** @brief Mark line as error.
205
* Highlight the specified line as compiler error.
206
* @param line The line in question.
208
virtual void SetErrorLine(int line){}
211
virtual void Undo(){}
214
virtual void Redo(){}
216
/** Cut selected text/object to clipboard. */
219
/** Copy selected text/object to clipboard. */
220
virtual void Copy(){}
222
/** Paste selected text/object from clipboard. */
223
virtual void Paste(){}
225
/** Is there something to undo?
227
* @return True if there is something to undo, false if not.
229
virtual bool CanUndo() const { return false; }
231
/** Is there something to redo?
233
* @return True if there is something to redo, false if not.
235
virtual bool CanRedo() const { return false; }
237
/** Is there a selection?
239
* @return True if there is text/object selected, false if not.
241
virtual bool HasSelection() const { return false; }
243
/** Is there something to paste?
245
* @return True if there is something to paste, false if not.
247
virtual bool CanPaste() const { return false; }
249
/** Is the editor read-only?
251
* @return True if the editor is read-only, false if not.
253
virtual bool IsReadOnly() const { return false; }
255
virtual void SearchGotoLine();
256
virtual void SearchFind();
257
virtual void SearchFindNext(bool next = true);
258
virtual void OnSearchReplace();
260
// --------------------------------------------------------------
262
// --------------------------------------------------------------
263
/** Initializes filename data.
264
* @param filename The editor's filename for initialization.
266
virtual void InitFilename(const wxString& filename);
268
/** Creates context submenus. See cbEditor code for details.
269
* @param id An event handler's ID.
270
* @return The created submenu or NULL if not applicable.
272
virtual wxMenu* CreateContextSubMenu(int id); // For context menus
274
/** Creates context menu items, both before and after creating plugins menu items.
275
* @param popup The popup menu.
276
* @param type The module's type.
277
* @param pluginsdone True if plugin menus have been created, false if not.
279
virtual void AddToContextMenu(wxMenu* popup, ModuleType type, bool pluginsdone) {}
281
/** Creates unique filename when asking to save the file.
282
* @return A unique filename suggestion.
284
virtual wxString CreateUniqueFilename();
286
/** Informs the editor we 're just about to create a context menu.
287
* Default implementation, just returns true.
288
* @param position specifies the position of the popup menu.
289
* @param type specifies the "ModuleType" popup menu.
290
* @return If the editor returns false, the context menu creation is aborted.
292
virtual bool OnBeforeBuildContextMenu(const wxPoint& position, ModuleType type){ return true; }
294
/** Informs the editor we 're done creating the context menu (just about to display it).
295
* Default implementation does nothing.
296
* @param type specifies the "ModuleType" context popup menu.
298
virtual void OnAfterBuildContextMenu(ModuleType type){}
300
virtual SEditorManager* GetEditorManager() const {return m_pEditorManager;}
301
virtual wxWindow* GetEditorParent(){return m_pParent;}
303
bool m_IsBuiltinEditor; // do not mess with it!
304
wxString m_Shortname;
306
EditorBaseInternalData* m_pData; ///< Use this to add new vars/functions w/out breaking the ABI
309
/** one event handler for all popup menu entries */
310
void OnContextMenuEntry(wxCommandEvent& event);
311
void BasicAddToContextMenu(wxMenu* popup, ModuleType type); //pecan 2006/03/22
312
SSwitchToMap m_SwitchTo;
315
SEditorManager* m_pEditorManager;
319
#endif // SEDITORBASE_H