~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/editor/scbeditor.h

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 SCBEDITOR_H
 
7
#define SCBEDITOR_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 "seditorbase.h"
 
16
#include "printing_types.h"
 
17
 
 
18
extern const wxString g_EditorModified;
 
19
 
 
20
// forward decls
 
21
struct ScbEditorInternalData; // this is the private data struct used by the editor.
 
22
class ScbEditor;
 
23
class ProjectFile;
 
24
class SEditorColourSet;
 
25
class wxSplitterWindow;
 
26
class LoaderBase;
 
27
class cbStyledTextCtrl;
 
28
class wxScintillaEvent;
 
29
class wxBoxSizer;
 
30
 
 
31
 
 
32
/** @brief A file editor
 
33
  *
 
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
 
37
  *
 
38
  * To do this, use SnippetsSearchFrame::GetEditorManager() functions.
 
39
  *
 
40
  * The actual editor component used is Scintilla and it can be accessed through
 
41
  * the member function GetControl().
 
42
  */
 
43
//-class DLLIMPORT cbEditor : public EditorBase
 
44
class ScbEditor : public SEditorBase
 
45
{
 
46
        DECLARE_EVENT_TABLE()
 
47
        friend class SEditorManager;
 
48
 
 
49
    protected:
 
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
 
53
          * new, empty, editor.
 
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>
 
57
          */
 
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. */
 
63
        ~ScbEditor();
 
64
    public:
 
65
        enum SplitType
 
66
        {
 
67
            stNoSplit = 0,
 
68
            stHorizontal,
 
69
            stVertical
 
70
        };
 
71
 
 
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* !!!")); }
 
74
 
 
75
        // properties
 
76
 
 
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
 
80
          * you want to get.
 
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...
 
84
          */
 
85
        cbStyledTextCtrl* GetControl() const;
 
86
 
 
87
        /** Returns a pointer to the left (or top) split-view cbStyledTextCtrl.
 
88
          * This function always returns a valid pointer.
 
89
          */
 
90
        cbStyledTextCtrl* GetLeftSplitViewControl() const { return m_pControl; }
 
91
 
 
92
        /** Returns a pointer to the right (or bottom) split-view cbStyledTextCtrl.
 
93
          * This function may return NULL if the editor is not split.
 
94
          */
 
95
        cbStyledTextCtrl* GetRightSplitViewControl() const { return m_pControl2; }
 
96
 
 
97
        /** Returns the state of split-view for this editor. */
 
98
        SplitType GetSplitType() const { return m_SplitType; }
 
99
 
 
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...
 
103
          */
 
104
        bool IsOK() const { return m_IsOK; }
 
105
 
 
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...
 
108
          */
 
109
        void SetEditorTitle(const wxString& title);
 
110
 
 
111
        /** Returns true if editor is modified, false otherwise */
 
112
        bool GetModified() const;
 
113
 
 
114
        /** Set the editor's modification state to \c modified. */
 
115
        void SetModified(bool modified = true);
 
116
 
 
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.
 
120
          */
 
121
        void SetProjectFile(ProjectFile* project_file,bool preserve_modified = false);
 
122
 
 
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.
 
125
          */
 
126
        ProjectFile* GetProjectFile() const { return m_pProjectFile; }
 
127
 
 
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
 
132
          * closed.
 
133
          */
 
134
        void UpdateProjectFile();
 
135
 
 
136
        /** Save editor contents. Returns true on success, false otherwise. */
 
137
        bool Save();
 
138
 
 
139
        /** Save editor contents under a different filename. Returns true on success, false otherwise. */
 
140
        bool SaveAs();
 
141
 
 
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();
 
144
 
 
145
        /** Fix fold states by comparing foldBackup with m_pControl. This is a temp fix for the Scintilla bug*/
 
146
        bool FixFoldState();
 
147
 
 
148
        /** Fold all editor folds (hides blocks of code). */
 
149
        void FoldAll();
 
150
 
 
151
        /** Unfold all editor folds (shows blocks of code). */
 
152
        void UnfoldAll();
 
153
 
 
154
        /** Toggle all editor folds (inverts the show/hide state of blocks of code). */
 
155
        void ToggleAllFolds();
 
156
 
 
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);
 
159
 
 
160
        /** Folds the block containing \c line. If \c line is -1, folds the block containing the caret. */
 
161
        void FoldBlockFromLine(int line = -1);
 
162
 
 
163
        /** Unfolds the block containing \c line. If \c line is -1, unfolds the block containing the caret. */
 
164
        void UnfoldBlockFromLine(int line = -1);
 
165
 
 
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);
 
168
 
 
169
        /** Set the colour set to use. */
 
170
        void SetColourSet(SEditorColourSet* theme);
 
171
 
 
172
        /** Get the colour set in use. */
 
173
        SEditorColourSet* GetColourSet() const { return m_pTheme; }
 
174
 
 
175
        /** Jumps to the matching brace (if there is one). */
 
176
        void GotoMatchingBrace();
 
177
 
 
178
        /** Highlights the brace pair (one of the braces must be under the cursor) */
 
179
        void HighlightBraces();
 
180
 
 
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;
 
183
 
 
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;
 
186
 
 
187
        /** Returns the last modification time for the file. Used to detect modifications outside the editor. */
 
188
        wxDateTime GetLastModificationTime() const { return m_LastModified; }
 
189
 
 
190
        /** Sets the last modification time for the file to 'now'. Used to detect modifications outside the editor. */
 
191
        void Touch();
 
192
 
 
193
        /** Reloads the file from disk. @return True on success, False on failure. */
 
194
        bool Reload(bool detectEncoding = true);
 
195
 
 
196
        /** Print the file.
 
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.
 
200
          */
 
201
        void Print(bool selectionOnly, PrintColourMode pcm, bool line_numbers);
 
202
 
 
203
        /** Try to auto-complete the current word.
 
204
          *
 
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.
 
207
          *
 
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.
 
211
          *
 
212
          * These keywords/code pairs can be edited in the editor configuration
 
213
          * dialog.
 
214
          */
 
215
        void AutoComplete();
 
216
 
 
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);
 
221
 
 
222
        /** Add debugger breakpoint at specified line. If @c line is -1, use current line. */
 
223
        bool AddBreakpoint(int line = -1, bool notifyDebugger = true);
 
224
 
 
225
        /** Remove debugger breakpoint at specified line. If @c line is -1, use current line. */
 
226
        bool RemoveBreakpoint(int line = -1, bool notifyDebugger = true);
 
227
 
 
228
        /** Toggle debugger breakpoint at specified line. If @c line is -1, use current line. */
 
229
        void ToggleBreakpoint(int line = -1, bool notifyDebugger = true);
 
230
 
 
231
        /** Does @c line has debugger breakpoint? If @c line is -1, use current line. */
 
232
        bool HasBreakpoint(int line) const;
 
233
 
 
234
        /** Go to next debugger breakpoint. */
 
235
        void GotoNextBreakpoint();
 
236
 
 
237
        /** Go to previous debugger breakpoint. */
 
238
        void GotoPreviousBreakpoint();
 
239
 
 
240
        /** Toggle bookmark at specified line. If @c line is -1, use current line. */
 
241
        void ToggleBookmark(int line = -1);
 
242
 
 
243
        /** Does @c line has bookmark? */
 
244
        bool HasBookmark(int line) const;
 
245
 
 
246
        /** Go to next bookmark. */
 
247
        void GotoNextBookmark();
 
248
 
 
249
        /** Go to previous bookmark. */
 
250
        void GotoPreviousBookmark();
 
251
 
 
252
        /** Highlight the line the debugger will execute next. */
 
253
        void SetDebugLine(int line);
 
254
 
 
255
        /** Highlight the specified line as error. */
 
256
        void SetErrorLine(int line);
 
257
 
 
258
        /** Split the editor window.
 
259
          * @param split The type of split: horizontal or vertical. */
 
260
        void Split(SplitType split);
 
261
 
 
262
        /** Unsplit the editor window. */
 
263
        void Unsplit();
 
264
 
 
265
        // the following functions, although self-explanatory, are documented
 
266
        // in SEditorBase.
 
267
        void Undo();
 
268
        void Redo();
 
269
        void Cut();
 
270
        void Copy();
 
271
        void Paste();
 
272
        bool CanUndo() const;
 
273
        bool CanRedo() const;
 
274
        bool HasSelection() const;
 
275
        bool CanPaste() const;
 
276
        bool IsReadOnly() const;
 
277
 
 
278
        // Workaround for shift-tab bug in wx2.4.2
 
279
        void DoIndent(); /// Indents current line/block
 
280
        void DoUnIndent(); /// UnIndents current line/block
 
281
 
 
282
        // misc. functions
 
283
        virtual wxMenu* CreateContextSubMenu(long id);
 
284
        virtual void AddToContextMenu(wxMenu* popup,ModuleType type,bool pluginsdone);  //pecan 2006/03/22
 
285
 
 
286
        HighlightLanguage GetLanguage( ) const { return m_lang; }
 
287
        void SetLanguage( HighlightLanguage lang = HL_AUTO );
 
288
 
 
289
        wxFontEncoding GetEncoding( ) const;
 
290
        wxString GetEncodingName( ) const;
 
291
        void SetEncoding( wxFontEncoding encoding );
 
292
 
 
293
        bool GetUseBom() const;
 
294
        void SetUseBom( bool bom );
 
295
 
 
296
        /// Apply the editor defaults to any (possibly foreign) cbStyledTextCtrl.
 
297
        static void ApplyStyles(cbStyledTextCtrl* control);
 
298
    private:
 
299
        // functions
 
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);
 
305
 
 
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);
 
322
 
 
323
        // events
 
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);
 
335
 
 
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
 
340
 
 
341
        void DestroySplitView();
 
342
 
 
343
        void DoInitializations(const wxString& filename, LoaderBase* fileLdr = 0);
 
344
 
 
345
        // variables
 
346
        bool m_IsOK;
 
347
        wxSplitterWindow* m_pSplitter;
 
348
        wxBoxSizer* m_pSizer;
 
349
        cbStyledTextCtrl* m_pControl;
 
350
        cbStyledTextCtrl* m_pControl2;
 
351
        cbStyledTextCtrl* m_foldBackup;
 
352
        SplitType m_SplitType;
 
353
        int m_ID;
 
354
        bool m_Modified;
 
355
        int m_Index;
 
356
        wxTimer m_timerWait;
 
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
 
361
 
 
362
        // DO NOT ADD ANY MORE VARIABLES HERE!
 
363
        // ADD THEM IN cbEditorInternalData INSTEAD!
 
364
 
 
365
        friend struct ScbEditorInternalData; // allow cbEditorInternalData to access ScbEditor
 
366
        ScbEditorInternalData* m_pData;
 
367
};
 
368
 
 
369
#endif // SCBEDITOR_H