~ubuntu-branches/ubuntu/oneiric/kde4libs/oneiric-proposed

« back to all changes in this revision

Viewing changes to kate/undo/kateundomanager.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 00:08:34 UTC
  • mto: This revision was merged to the branch mainline in revision 247.
  • Revision ID: package-import@ubuntu.com-20110708000834-dr9a8my4iml90qe5
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
3
 
 
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.
7
 
 
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.
12
 
 
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.
17
 
*/
18
 
 
19
 
#ifndef KATEUNDOMANAGER_H
20
 
#define KATEUNDOMANAGER_H
21
 
 
22
 
#include <QtCore/QObject>
23
 
 
24
 
#include "katepartprivate_export.h"
25
 
 
26
 
#include <QtCore/QList>
27
 
 
28
 
class KateDocument;
29
 
class KateUndo;
30
 
class KateUndoGroup;
31
 
 
32
 
namespace KTextEditor {
33
 
  class Document;
34
 
  class View;
35
 
}
36
 
 
37
 
/**
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.
41
 
 *
42
 
 * The state of the KateUndomanager can be switched using editStart() and editEnd().
43
 
 */
44
 
class KATEPART_TESTS_EXPORT KateUndoManager : public QObject
45
 
{
46
 
  Q_OBJECT
47
 
 
48
 
  public:
49
 
    /**
50
 
     * Creates a clean undo history.
51
 
     *
52
 
     * @param doc the document the KateUndoManager will belong to
53
 
     */
54
 
    KateUndoManager (KateDocument *doc);
55
 
 
56
 
    ~KateUndoManager();
57
 
 
58
 
    KTextEditor::Document *document();
59
 
 
60
 
    /**
61
 
     * Returns how many undo() actions can be performed.
62
 
     *
63
 
     * @return the number of undo groups which can be undone
64
 
     */
65
 
    uint undoCount () const;
66
 
 
67
 
    /**
68
 
     * Returns how many redo() actions can be performed.
69
 
     *
70
 
     * @return the number of undo groups which can be redone
71
 
     */
72
 
    uint redoCount () const;
73
 
 
74
 
    /**
75
 
     * Prevent latest KateUndoGroup from being merged with the next one.
76
 
     */
77
 
    void undoSafePoint();
78
 
 
79
 
    /**
80
 
     * Allows or disallows merging of "complex" undo groups.
81
 
     *
82
 
     * When an undo group contains different types of undo items, it is considered
83
 
     * a "complex" group.
84
 
     *
85
 
     * @param allow whether complex merging is allowed
86
 
     */
87
 
    void setAllowComplexMerge(bool allow);
88
 
 
89
 
    bool isActive() const { return m_isActive; }
90
 
 
91
 
    void setModified( bool m );
92
 
    void updateConfig ();
93
 
 
94
 
  public Q_SLOTS:
95
 
    /**
96
 
     * Undo the latest undo group.
97
 
     *
98
 
     * Make sure isDefaultState() is true when calling this method.
99
 
     */
100
 
    void undo ();
101
 
 
102
 
    /**
103
 
     * Redo the latest undo group.
104
 
     *
105
 
     * Make sure isDefaultState() is true when calling this method.
106
 
     */
107
 
    void redo ();
108
 
 
109
 
    void clearUndo ();
110
 
    void clearRedo ();
111
 
 
112
 
    /**
113
 
     * Notify KateUndoManager about the beginning of an edit.
114
 
     */
115
 
    void editStart();
116
 
 
117
 
    /**
118
 
     * Notify KateUndoManager about the end of an edit.
119
 
     */
120
 
    void editEnd();
121
 
 
122
 
    void startUndo();
123
 
    void endUndo();
124
 
 
125
 
    void inputMethodStart();
126
 
    void inputMethodEnd();
127
 
 
128
 
    /**
129
 
     * Notify KateUndoManager that text was inserted.
130
 
     */
131
 
    void slotTextInserted(int line, int col, const QString &s);
132
 
 
133
 
    /**
134
 
     * Notify KateUndoManager that text was removed.
135
 
     */
136
 
    void slotTextRemoved(int line, int col, const QString &s);
137
 
 
138
 
    /**
139
 
     * Notify KateUndoManager that a line was marked as autowrapped.
140
 
     */
141
 
    void slotMarkLineAutoWrapped(int line, bool autowrapped);
142
 
 
143
 
    /**
144
 
     * Notify KateUndoManager that a line was wrapped.
145
 
     */
146
 
    void slotLineWrapped(int line, int col, int pos, bool newLine);
147
 
 
148
 
    /**
149
 
     * Notify KateUndoManager that a line was un-wrapped.
150
 
     */
151
 
    void slotLineUnWrapped(int line, int col, int length, bool lineRemoved);
152
 
 
153
 
    /**
154
 
     * Notify KateUndoManager that a line was inserted.
155
 
     */
156
 
    void slotLineInserted(int line, const QString &s);
157
 
 
158
 
    /**
159
 
     * Notify KateUndoManager that a line was removed.
160
 
     */
161
 
    void slotLineRemoved(int line, const QString &s);
162
 
 
163
 
  Q_SIGNALS:
164
 
    void undoChanged ();
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);
170
 
 
171
 
  private Q_SLOTS:
172
 
    /**
173
 
     * @short Add an undo item to the current undo group.
174
 
     *
175
 
     * @param undo undo item to be added, must be non-null
176
 
     */
177
 
    void addUndoItem(KateUndo *undo);
178
 
 
179
 
    void setActive(bool active);
180
 
 
181
 
    void updateModified();
182
 
 
183
 
    void undoCancel();
184
 
    void viewCreated (KTextEditor::Document *, KTextEditor::View *newView);
185
 
 
186
 
  private:
187
 
    KTextEditor::View *activeView();
188
 
 
189
 
  private:
190
 
    KateDocument *m_document;
191
 
    bool m_undoComplexMerge;
192
 
    bool m_isActive;
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;
202
 
};
203
 
 
204
 
#endif
205
 
 
206
 
// kate: space-indent on; indent-width 2; replace-tabs on;