KTextEditor

kateundomanager.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2009-2010 Bernhard Beschow <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef KATEUNDOMANAGER_H
22 #define KATEUNDOMANAGER_H
23 
24 #include <QObject>
25 
26 #include <ktexteditor_export.h>
27 
28 #include <QList>
29 
30 namespace KTextEditor
31 {
32 class DocumentPrivate;
33 }
34 class KateUndo;
35 class KateUndoGroup;
36 
37 namespace KTextEditor
38 {
39 class Document;
40 class View;
41 class Cursor;
42 }
43 
51 class KTEXTEDITOR_EXPORT KateUndoManager : public QObject
52 {
53  Q_OBJECT
54 
55 public:
61  explicit KateUndoManager(KTextEditor::DocumentPrivate *doc);
62 
63  ~KateUndoManager();
64 
65  KTextEditor::Document *document();
66 
72  uint undoCount() const;
73 
79  uint redoCount() const;
80 
84  void undoSafePoint();
85 
94  void setAllowComplexMerge(bool allow);
95 
96  bool isActive() const
97  {
98  return m_isActive;
99  }
100 
101  void setModified(bool modified);
102  void updateConfig();
103  void updateLineModifications();
104 
112  void setUndoRedoCursorsOfLastGroup(const KTextEditor::Cursor &undoCursor, const KTextEditor::Cursor &redoCursor);
113 
118  KTextEditor::Cursor lastRedoCursor() const;
119 
120 public Q_SLOTS:
126  void undo();
127 
133  void redo();
134 
135  void clearUndo();
136  void clearRedo();
137 
141  void editStart();
142 
146  void editEnd();
147 
148  void startUndo();
149  void endUndo();
150 
151  void inputMethodStart();
152  void inputMethodEnd();
153 
157  void slotTextInserted(int line, int col, const QString &s);
158 
162  void slotTextRemoved(int line, int col, const QString &s);
163 
167  void slotMarkLineAutoWrapped(int line, bool autowrapped);
168 
172  void slotLineWrapped(int line, int col, int length, bool newLine);
173 
177  void slotLineUnWrapped(int line, int col, int length, bool lineRemoved);
178 
182  void slotLineInserted(int line, const QString &s);
183 
187  void slotLineRemoved(int line, const QString &s);
188 
189 Q_SIGNALS:
190  void undoChanged();
191  void undoStart(KTextEditor::Document *);
192  void undoEnd(KTextEditor::Document *);
193  void redoStart(KTextEditor::Document *);
194  void redoEnd(KTextEditor::Document *);
195  void isActiveChanged(bool enabled);
196 
197 private Q_SLOTS:
203  void addUndoItem(KateUndo *undo);
204 
205  void setActive(bool active);
206 
207  void updateModified();
208 
209  void undoCancel();
210  void viewCreated(KTextEditor::Document *, KTextEditor::View *newView);
211 
212 private:
213  KTextEditor::View *activeView();
214 
215 private:
216  KTextEditor::DocumentPrivate *m_document = nullptr;
217  bool m_undoComplexMerge = false;
218  bool m_isActive = true;
219  KateUndoGroup *m_editCurrentUndo = nullptr;
220  QList<KateUndoGroup *> undoItems;
221  QList<KateUndoGroup *> redoItems;
222  // these two variables are for resetting the document to
223  // non-modified if all changes have been undone...
224  KateUndoGroup *lastUndoGroupWhenSaved = nullptr;
225  KateUndoGroup *lastRedoGroupWhenSaved = nullptr;
226  bool docWasSavedWhenUndoWasEmpty = true;
227  bool docWasSavedWhenRedoWasEmpty = true;
228 };
229 
230 #endif
KateUndoManager implements a document&#39;s history.
The Cursor represents a position in a Document.
Definition: cursor.h:85
bool editStart()
Enclose editor actions with editStart() and editEnd() to group them.
Class to manage a group of undo items.
Definition: kateundo.h:424
A KParts derived class representing a text document.
Definition: document.h:199
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
bool editEnd()
End a editor operation.
Base class for Kate undo commands.
Definition: kateundo.h:47
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:155
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 6 2020 22:56:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.