1
/* This file is part of the KDE libraries
2
Copyright (C) 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#ifndef KATEUNDOMANAGER_H
20
#define KATEUNDOMANAGER_H
22
#include <QtCore/QObject>
24
#include "katepartprivate_export.h"
26
#include <QtCore/QList>
32
namespace KTextEditor {
38
* KateUndoManager implements a document's history. It is in either of the two states:
39
* @li the default state, which allows rolling back and forth the history of a document, and
40
* @li a state in which a new element is being added to the history.
42
* The state of the KateUndomanager can be switched using editStart() and editEnd().
44
class KATEPART_TESTS_EXPORT KateUndoManager : public QObject
50
* Creates a clean undo history.
52
* @param doc the document the KateUndoManager will belong to
54
KateUndoManager (KateDocument *doc);
58
KTextEditor::Document *document();
61
* Returns how many undo() actions can be performed.
63
* @return the number of undo groups which can be undone
65
uint undoCount () const;
68
* Returns how many redo() actions can be performed.
70
* @return the number of undo groups which can be redone
72
uint redoCount () const;
75
* Prevent latest KateUndoGroup from being merged with the next one.
80
* Allows or disallows merging of "complex" undo groups.
82
* When an undo group contains different types of undo items, it is considered
85
* @param allow whether complex merging is allowed
87
void setAllowComplexMerge(bool allow);
89
bool isActive() const { return m_isActive; }
91
void setModified( bool m );
96
* Undo the latest undo group.
98
* Make sure isDefaultState() is true when calling this method.
103
* Redo the latest undo group.
105
* Make sure isDefaultState() is true when calling this method.
113
* Notify KateUndoManager about the beginning of an edit.
118
* Notify KateUndoManager about the end of an edit.
125
void inputMethodStart();
126
void inputMethodEnd();
129
* Notify KateUndoManager that text was inserted.
131
void slotTextInserted(int line, int col, const QString &s);
134
* Notify KateUndoManager that text was removed.
136
void slotTextRemoved(int line, int col, const QString &s);
139
* Notify KateUndoManager that a line was marked as autowrapped.
141
void slotMarkLineAutoWrapped(int line, bool autowrapped);
144
* Notify KateUndoManager that a line was wrapped.
146
void slotLineWrapped(int line, int col, int pos, bool newLine);
149
* Notify KateUndoManager that a line was un-wrapped.
151
void slotLineUnWrapped(int line, int col, int length, bool lineRemoved);
154
* Notify KateUndoManager that a line was inserted.
156
void slotLineInserted(int line, const QString &s);
159
* Notify KateUndoManager that a line was removed.
161
void slotLineRemoved(int line, const QString &s);
165
void undoStart (KTextEditor::Document*);
166
void undoEnd (KTextEditor::Document*);
167
void redoStart (KTextEditor::Document*);
168
void redoEnd (KTextEditor::Document*);
169
void isActiveChanged(bool enabled);
173
* @short Add an undo item to the current undo group.
175
* @param undo undo item to be added, must be non-null
177
void addUndoItem(KateUndo *undo);
179
void setActive(bool active);
181
void updateModified();
184
void viewCreated (KTextEditor::Document *, KTextEditor::View *newView);
187
KTextEditor::View *activeView();
190
KateDocument *m_document;
191
bool m_undoComplexMerge;
193
KateUndoGroup* m_editCurrentUndo;
194
QList<KateUndoGroup*> undoItems;
195
QList<KateUndoGroup*> redoItems;
196
// these two variables are for resetting the document to
197
// non-modified if all changes have been undone...
198
KateUndoGroup* lastUndoGroupWhenSaved;
199
KateUndoGroup* lastRedoGroupWhenSaved;
200
bool docWasSavedWhenUndoWasEmpty;
201
bool docWasSavedWhenRedoWasEmpty;
206
// kate: space-indent on; indent-width 2; replace-tabs on;