File: qeditor_part.h

package info (click to toggle)
kdevelop3 4%3A3.2.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 58,220 kB
  • ctags: 33,997
  • sloc: cpp: 278,404; ansic: 48,238; sh: 23,721; tcl: 19,882; perl: 5,498; makefile: 4,717; ruby: 1,610; python: 1,549; awk: 1,484; xml: 563; java: 359; php: 20; asm: 14; ada: 5; pascal: 4; fortran: 4; haskell: 2; sql: 1
file content (382 lines) | stat: -rw-r--r-- 11,071 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
 *  Copyright (C) 2001 Roberto Raggi (roberto@kdevelop.org)
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.  If not, write to
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *
 */

#ifndef QEDITORPART_H
#define QEDITORPART_H

#include <kdeversion.h>
#include <ktexteditor/editor.h>
#include <ktexteditor/document.h>
#include <ktexteditor/editinterface.h>
#include <ktexteditor/undointerface.h>
#include <ktexteditor/cursorinterface.h>
#include <ktexteditor/selectioninterface.h>
#include <ktexteditor/highlightinginterface.h>
#include <ktexteditor/searchinterface.h>
#include <ktexteditor/markinterface.h>
#include <ktexteditor/configinterface.h>
#if (KDE_VERSION > 305)
# include <ktexteditor/markinterfaceextension.h>
#else
# include "kde30x_markinterfaceextension.h"
#endif
#include <qptrlist.h>

#include "qeditor_factory.h"

class QWidget;
class QPainter;
class KURL;
class QEditorView;
class QEditorIndenter;
class QEditorBrowserExtension;
class KAboutData;
class HLMode;
class KConfig;
class QSourceColorizer;
class KDialogBase;

class QEditorPart:
	public KTextEditor::Document,
	public KTextEditor::EditInterface,
	public KTextEditor::UndoInterface,
	public KTextEditor::CursorInterface,
	public KTextEditor::SelectionInterface,
	public KTextEditor::HighlightingInterface,
	public KTextEditor::SearchInterface,
	public KTextEditor::MarkInterface,
	public KTextEditor::MarkInterfaceExtension,
	public KTextEditor::ConfigInterface
{
    Q_OBJECT
public:
    /**
     * Default constructor
     */
    QEditorPart(QWidget *parentWidget, const char *widgetName,
                QObject *parent, const char *name, const QStringList &args);

    /**
     * Destructor
     */
    virtual ~QEditorPart();

    /**
     * This is a virtual function inherited from KParts::ReadWritePart.
     * A shell will use this to inform this Part if it should act
     * read-only
     */
    virtual void setReadWrite(bool rw);

    /**
     * Reimplemented to disable and enable Save action
     */
    virtual void setModified(bool modified);

    QSourceColorizer* colorizer() const;
    QEditorIndenter* indenter() const;

signals:
    void fileNameChanged();
    void configWidget( KDialogBase* );

// -- ConfigInterface ----------------------------------------------------------------------
public slots:
    /**
      Read/Write the config to the standard place where this editor
      part saves it config, say: read/save default values for that
      editor part
    */
    virtual void readConfig ();
    virtual void writeConfig ();

    /**
      Read/Write the config of the part to a given kconfig object
      to store the settings in a different place than the standard
    */
    virtual void readConfig (KConfig *);
    virtual void writeConfig (KConfig *);

    /**
      Read/Write session config of only this document/view/plugin
    */
    virtual void readSessionConfig (KConfig *);
    virtual void writeSessionConfig (KConfig *);

    /**
      Shows a config dialog for the part
    */
    virtual void configDialog();

// -- MarkInterface ------------------------------------------------------------------------
public:
    virtual uint mark (uint line);

    virtual void setMark (uint line, uint markType);
    virtual void clearMark (uint line);

    virtual void addMark (uint line, uint markType);
    virtual void removeMark (uint line, uint markType);

    virtual QPtrList<KTextEditor::Mark> marks ();
    virtual void clearMarks ();

signals:
    void marksChanged();

// -- MarkInterfaceExtension----------------------------------------------------------------
public:
    virtual void setPixmap(MarkInterface::MarkTypes, const QPixmap &);
    virtual void setDescription(MarkInterface::MarkTypes, const QString &);
    virtual void setMarksUserChangable(uint markMask);

signals:
    virtual void markChanged (KTextEditor::Mark mark,
                              KTextEditor::MarkInterfaceExtension::MarkChangeAction action);

// -- SearchInterface ----------------------------------------------------------------------
public:
    virtual bool searchText (unsigned int startLine, unsigned int startCol,
                             const QString &text, unsigned int *foundAtLine, unsigned int *foundAtCol,
                             unsigned int *matchLen, bool casesensitive = true, bool backwards = false);

    virtual bool searchText (unsigned int startLine, unsigned int startCol,
                             const QRegExp &regexp, unsigned int *foundAtLine,
                             unsigned int *foundAtCol, unsigned int *matchLen, bool backwards = false);

// -- Document ------------------------------------------------------------------------------
public:
    QEditorView* currentView() const { return m_currentView; }

    /**
     * Create a view that will display the document data. You can create as many
     * views as you like. When the user modifies data in one view then all other
     * views will be updated as well.
     */
    virtual KTextEditor::View *createView ( QWidget *parent, const char *name = 0 );



    /*
     * Accessor to the list of views.
     */
    virtual QPtrList<KTextEditor::View> views () const;

// -- HighlightingInterface ---------------------------------------------------------------------
public:
    /**
     * returns the current active highlighting mode
     */
    virtual unsigned int hlMode ();

    /**
     * set the current active highlighting mode
     */
    virtual bool setHlMode (unsigned int mode);

    /**
     * returns the number of available highlightings
     */
    virtual unsigned int hlModeCount ();

    /**
     * returns the name of the highlighting with number "mode"
     */
    virtual QString hlModeName (unsigned int mode);

    /**
     * returns the sectionname of the highlighting with number "mode"
     */
    virtual QString hlModeSectionName (unsigned int mode);

signals:
    void hlChanged ();

private:
    void setupHighlighting();
    int findMode( const QString& );

private:
    QPtrList<HLMode> m_modes;
    unsigned int m_currentMode;

// -- UndoInterface -----------------------------------------------------------------------------
public:
    virtual void clearUndo ();
    virtual void clearRedo ();
    virtual unsigned int undoCount () const;
    virtual unsigned int redoCount () const;
    virtual unsigned int undoSteps () const;
    virtual void setUndoSteps ( unsigned int steps );

public slots:
    virtual void undo ();
    virtual void redo ();

signals:
    void undoChanged ();

// -- EditInterface ----------------------------------------------------------------------
public:
    /**
     * @return the complete document as a single QString
     */
    virtual QString text () const;

    /**
     * @return a QString
     */
    virtual QString text ( unsigned int startLine, unsigned int startCol, unsigned int endLine, unsigned int endCol ) const;

    /**
     * @return All the text from the requested line.
     */
    virtual QString textLine ( unsigned int line ) const;

    /**
     * @return The current number of lines in the document
     */
    virtual unsigned int numLines () const;

    /**
     * @return the number of characters in the document
     */
    virtual unsigned int length () const;

    /**
     * @return the number of characters in the line (-1 if no line "line")
     */
    virtual int lineLength ( unsigned int line ) const;

    /**
     * Set the given text into the view.
     * Warning: This will overwrite any data currently held in this view.
     */
    virtual bool setText ( const QString &text );

    /**
     *  clears the document
     * Warning: This will overwrite any data currently held in this view.
     */
    virtual bool clear ();

    /**
     *  Inserts text at line "line", column "col"
     *  returns true if success
     */
    virtual bool insertText ( unsigned int line, unsigned int col, const QString &text );

    /**
     *  remove text at line "line", column "col"
     *  returns true if success
     */
    virtual bool removeText ( unsigned int startLine, unsigned int startCol, unsigned int endLine, unsigned int endCol );

    /**
     * Insert line(s) at the given line number. If the line number is -1
     * (the default) then the line is added to end of the document
     */
    virtual bool insertLine ( unsigned int line, const QString &text );

    /**
     * Insert line(s) at the given line number. If the line number is -1
     * (the default) then the line is added to end of the document
     */
    virtual bool removeLine ( unsigned int line );

signals:
    void textChanged ();
    void newStatus ();
    void charactersInteractivelyInserted(int ,int ,const QString&);

// -- CursorInterface ------------------------------------------------------------------------
public:
    /**
     * Create a new cursor object
     */
    virtual KTextEditor::Cursor *createCursor ( );

    /*
     * Accessor to the list of views.
     */
    virtual QPtrList<KTextEditor::Cursor> cursors () const;

// -- SelectionInterface ----------------------------------------------------------------------
public:
    /**
     *  @return set the selection from line_start,col_start to line_end,col_end
     */
    virtual bool setSelection ( unsigned int startLine, unsigned int startCol, unsigned int endLine, unsigned int endCol );

    /**
     *  removes the current Selection (not Text)
     */
    virtual bool clearSelection ();

    /**
     *  @return true if there is a selection
     */
    virtual bool hasSelection () const;

    /**
     *  @return a QString for the selected text
     */
    virtual QString selection () const;

    /**
     *  removes the selected Text
     */
    virtual bool removeSelectedText ();

    /**
     *  select the whole text
     */
    virtual bool selectAll();

signals:
    void selectionChanged ();

protected:
    /**
     * This must be implemented by each part
     */
    virtual bool openFile();

    /**
     * This must be implemented by each read-write part
     */
    virtual bool saveFile();

public slots:
    void fileReload();

protected slots:
    void fileOpen();
    void fileSaveAs();

private:
    QEditorView* m_currentView;
    QPtrList<KTextEditor::View> m_views;
    QPtrList<KTextEditor::Cursor> m_cursors;
    QPtrList<KTextEditor::Mark> m_marks;
    QEditorBrowserExtension* m_extension;
};

#endif // QEDITORPART_H