00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef kate_undo_h
00023 #define kate_undo_h
00024
00025 #include <QtCore/QList>
00026
00027 #include <ktexteditor/range.h>
00028
00029 class KateDocument;
00030 class KateView;
00031
00035 class KateUndo
00036 {
00037 public:
00042 KateUndo (KateDocument *document);
00043
00047 virtual ~KateUndo();
00048
00049 public:
00053 enum UndoType
00054 {
00055 editInsertText,
00056 editRemoveText,
00057 editWrapLine,
00058 editUnWrapLine,
00059 editInsertLine,
00060 editRemoveLine,
00061 editMarkLineAutoWrapped,
00062 editInvalid
00063 };
00064
00065 public:
00071 virtual bool isEmpty() const;
00072
00079 virtual bool mergeWith(const KateUndo* undo);
00080
00084 virtual void undo() = 0;
00085
00089 virtual void redo() = 0;
00090
00095 virtual KateUndo::UndoType type() const = 0;
00096
00097 protected:
00102 inline KateDocument *document() { return m_document; }
00103
00104 private:
00108 KateDocument *m_document;
00109 };
00110
00111 class KateEditInsertTextUndo : public KateUndo
00112 {
00113 public:
00114 KateEditInsertTextUndo (KateDocument *document, int line, int col, const QString &text)
00115 : KateUndo (document)
00116 , m_line (line)
00117 , m_col (col)
00118 , m_text (text)
00119 {}
00120
00124 bool isEmpty() const;
00125
00129 void undo();
00130
00134 void redo();
00135
00139 bool mergeWith (const KateUndo *undo);
00140
00144 KateUndo::UndoType type() const { return KateUndo::editInsertText; }
00145
00146 private:
00147 int len() const { return m_text.length(); }
00148
00149 private:
00150 const int m_line;
00151 const int m_col;
00152 QString m_text;
00153 };
00154
00155 class KateEditRemoveTextUndo : public KateUndo
00156 {
00157 public:
00158 KateEditRemoveTextUndo (KateDocument *document, int line, int col, const QString &text)
00159 : KateUndo (document)
00160 , m_line (line)
00161 , m_col (col)
00162 , m_text (text)
00163 {}
00164
00168 bool isEmpty() const;
00169
00173 void undo();
00174
00178 void redo();
00179
00183 bool mergeWith (const KateUndo *undo);
00184
00188 KateUndo::UndoType type() const { return KateUndo::editRemoveText; }
00189
00190 private:
00191 int len() const { return m_text.length(); }
00192
00193 private:
00194 const int m_line;
00195 int m_col;
00196 QString m_text;
00197 };
00198
00199 class KateEditMarkLineAutoWrappedUndo : public KateUndo
00200 {
00201 public:
00202 KateEditMarkLineAutoWrappedUndo (KateDocument *document, int line, bool autowrapped)
00203 : KateUndo (document)
00204 , m_line (line)
00205 , m_autowrapped (autowrapped)
00206 {}
00207
00211 void undo();
00212
00216 void redo();
00217
00221 KateUndo::UndoType type() const { return KateUndo::editMarkLineAutoWrapped; }
00222
00223 private:
00224 const int m_line;
00225 const bool m_autowrapped;
00226 };
00227
00228 class KateEditWrapLineUndo : public KateUndo
00229 {
00230 public:
00231 KateEditWrapLineUndo (KateDocument *document, int line, int col, int len, bool newLine)
00232 : KateUndo (document)
00233 , m_line (line)
00234 , m_col (col)
00235 , m_len (len)
00236 , m_newLine (newLine)
00237 {}
00238
00242 void undo();
00243
00247 void redo();
00248
00252 KateUndo::UndoType type() const { return KateUndo::editWrapLine; }
00253
00254 private:
00255 const int m_line;
00256 const int m_col;
00257 const int m_len;
00258 const bool m_newLine;
00259 };
00260
00261 class KateEditUnWrapLineUndo : public KateUndo
00262 {
00263 public:
00264 KateEditUnWrapLineUndo (KateDocument *document, int line, int col, int len, bool removeLine)
00265 : KateUndo (document)
00266 , m_line (line)
00267 , m_col (col)
00268 , m_len (len)
00269 , m_removeLine (removeLine)
00270 {}
00271
00275 void undo();
00276
00280 void redo();
00281
00285 KateUndo::UndoType type() const { return KateUndo::editUnWrapLine; }
00286
00287 private:
00288 const int m_line;
00289 const int m_col;
00290 const int m_len;
00291 const bool m_removeLine;
00292 };
00293
00294 class KateEditInsertLineUndo : public KateUndo
00295 {
00296 public:
00297 KateEditInsertLineUndo (KateDocument *document, int line, const QString &text)
00298 : KateUndo (document)
00299 , m_line (line)
00300 , m_text (text)
00301 {}
00302
00306 void undo();
00307
00311 void redo();
00312
00316 KateUndo::UndoType type() const { return KateUndo::editInsertLine; }
00317
00318 private:
00319 const int m_line;
00320 const QString m_text;
00321 };
00322
00323 class KateEditRemoveLineUndo : public KateUndo
00324 {
00325 public:
00326 KateEditRemoveLineUndo (KateDocument *document, int line, const QString &text)
00327 : KateUndo (document)
00328 , m_line (line)
00329 , m_text (text)
00330 {}
00331
00335 void undo();
00336
00340 void redo();
00341
00345 KateUndo::UndoType type() const { return KateUndo::editRemoveLine; }
00346
00347 private:
00348 const int m_line;
00349 const QString m_text;
00350 };
00351
00355 class KateUndoGroup
00356 {
00357 public:
00362 explicit KateUndoGroup (KateDocument *document);
00363
00367 ~KateUndoGroup();
00368
00369 public:
00373 void undo();
00374
00378 void redo();
00379
00380 void editEnd();
00381
00388 bool merge (KateUndoGroup* newGroup,bool complex);
00389
00393 void safePoint (bool safePoint=true);
00394
00398 bool isEmpty() const { return m_items.isEmpty(); }
00399
00400 private:
00401 KateView *activeKateView();
00402
00407 KateUndo::UndoType singleType() const;
00408
00414 bool isOnlyType(KateUndo::UndoType type) const;
00415
00416 public:
00421 void addItem (KateUndo *u);
00422
00423 private:
00424 KateDocument *const m_document;
00425
00429 QList<KateUndo*> m_items;
00430
00434 bool m_safePoint;
00435
00439 KTextEditor::Range m_undoSelection;
00440
00444 KTextEditor::Range m_redoSelection;
00445
00449 KTextEditor::Cursor m_undoCursor;
00450
00454 KTextEditor::Cursor m_redoCursor;
00455 };
00456
00457 #endif
00458
00459