1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
4 *
5 * Based on code of the SmartCursor/Range by:
6 * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24#ifndef KDELIBS_KTEXTEDITOR_MOVINGINTERFACE_H
25#define KDELIBS_KTEXTEDITOR_MOVINGINTERFACE_H
26
27#include <ktexteditor/ktexteditor_export.h>
28#include <ktexteditor/movingcursor.h>
29#include <ktexteditor/movingrange.h>
30#include <ktexteditor/movingrangefeedback.h>
31
32namespace KTextEditor
33{
34
35/**
36 * \brief Document interface for MovingCursor%s and MovingRange%s.
37 *
38 * \ingroup kte_group_doc_extensions
39 * \ingroup kte_group_moving_classes
40 *
41 * This class provides the interface for KTextEditor::Documents to create MovingCursors/Ranges.
42 *
43 * \author Christoph Cullmann \<cullmann@kde.org\>
44 *
45 * \since 4.5
46 */
47class KTEXTEDITOR_EXPORT MovingInterface
48{
49 //
50 // Constructor/Destructor
51 //
52 public:
53 /**
54 * Default constructor
55 */
56 MovingInterface ();
57
58 /**
59 * Virtual destructor
60 */
61 virtual ~MovingInterface ();
62
63 //
64 // Normal API
65 //
66 public:
67 /**
68 * Create a new moving cursor for this document.
69 * @param position position of the moving cursor to create
70 * @param insertBehavior insertion behavior
71 * @return new moving cursor for the document
72 */
73 virtual MovingCursor *newMovingCursor (const Cursor &position, MovingCursor::InsertBehavior insertBehavior = MovingCursor::MoveOnInsert) = 0;
74
75 /**
76 * Create a new moving range for this document.
77 * @param range range of the moving range to create
78 * @param insertBehaviors insertion behaviors
79 * @param emptyBehavior behavior on becoming empty
80 * @return new moving range for the document
81 */
82 virtual MovingRange *newMovingRange (const Range &range, MovingRange::InsertBehaviors insertBehaviors = MovingRange::DoNotExpand
83 , MovingRange::EmptyBehavior emptyBehavior = MovingRange::AllowEmpty) = 0;
84
85 /**
86 * Current revision
87 * @return current revision
88 */
89 virtual qint64 revision () const = 0;
90
91 /**
92 * Last revision the buffer got successful saved
93 * @return last revision buffer got saved, -1 if none
94 */
95 virtual qint64 lastSavedRevision () const = 0;
96
97 /**
98 * Lock a revision, this will keep it around until released again.
99 * But all revisions will always be cleared on buffer clear() (and therefor load())
100 * @param revision revision to lock
101 */
102 virtual void lockRevision (qint64 revision) = 0;
103
104 /**
105 * Release a revision.
106 * @param revision revision to release
107 */
108 virtual void unlockRevision (qint64 revision) = 0;
109
110 /**
111 * Transform a cursor from one revision to an other.
112 * @param cursor cursor to transform
113 * @param insertBehavior behavior of this cursor on insert of text at its position
114 * @param fromRevision from this revision we want to transform
115 * @param toRevision to this revision we want to transform, default of -1 is current revision
116 */
117 virtual void transformCursor (KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) = 0;
118
119 /**
120 * Transform a cursor from one revision to an other.
121 * @param line line number of the cursor to transform
122 * @param column column number of the cursor to transform
123 * @param insertBehavior behavior of this cursor on insert of text at its position
124 * @param fromRevision from this revision we want to transform
125 * @param toRevision to this revision we want to transform, default of -1 is current revision
126 */
127 virtual void transformCursor (int& line, int& column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) = 0;
128
129 /**
130 * Transform a range from one revision to an other.
131 * @param range range to transform
132 * @param insertBehaviors behavior of this range on insert of text at its position
133 * @param emptyBehavior behavior on becoming empty
134 * @param fromRevision from this revision we want to transform
135 * @param toRevision to this revision we want to transform, default of -1 is current revision
136 */
137 virtual void transformRange (KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision = -1) = 0;
138
139 //
140 // Signals
141 //
142 public:
143 /**
144 * This signal is emitted before the cursors/ranges/revisions of a document are destroyed as the document is deleted.
145 * @param document the document which the interface belongs too which is in the process of being deleted
146 */
147 void aboutToDeleteMovingInterfaceContent (KTextEditor::Document *document);
148
149 /**
150 * This signal is emitted before the ranges of a document are invalidated and the revisions are deleted as the document is cleared (for example on load/reload).
151 * While this signal is emitted, still the old document content is around before the clear.
152 * @param document the document which the interface belongs too which will invalidate its data
153 */
154 void aboutToInvalidateMovingInterfaceContent (KTextEditor::Document *document);
155
156 private:
157 /**
158 * private d-pointer
159 */
160 class MovingInterfacePrivate * const d;
161};
162
163}
164
165Q_DECLARE_INTERFACE(KTextEditor::MovingInterface, "org.kde.KTextEditor.MovingInterface")
166
167#endif
168
169// kate: space-indent on; indent-width 2; replace-tabs on;
170