Kate
kateundo.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 00003 Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org> 00004 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00005 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 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 KateUndoManager; 00030 class KateDocument; 00031 00032 namespace KTextEditor { 00033 class View; 00034 } 00035 00039 class KateUndo 00040 { 00041 public: 00046 KateUndo (KateDocument *document); 00047 00051 virtual ~KateUndo(); 00052 00053 public: 00057 enum UndoType 00058 { 00059 editInsertText, 00060 editRemoveText, 00061 editWrapLine, 00062 editUnWrapLine, 00063 editInsertLine, 00064 editRemoveLine, 00065 editMarkLineAutoWrapped, 00066 editInvalid 00067 }; 00068 00069 public: 00075 virtual bool isEmpty() const; 00076 00083 virtual bool mergeWith(const KateUndo* undo); 00084 00088 virtual void undo() = 0; 00089 00093 virtual void redo() = 0; 00094 00099 virtual KateUndo::UndoType type() const = 0; 00100 00101 protected: 00106 inline KateDocument *document() { return m_document; } 00107 00108 private: 00112 KateDocument *m_document; 00113 }; 00114 00115 class KateEditInsertTextUndo : public KateUndo 00116 { 00117 public: 00118 KateEditInsertTextUndo (KateDocument *document, int line, int col, const QString &text) 00119 : KateUndo (document) 00120 , m_line (line) 00121 , m_col (col) 00122 , m_text (text) 00123 {} 00124 00128 bool isEmpty() const; 00129 00133 void undo(); 00134 00138 void redo(); 00139 00143 bool mergeWith (const KateUndo *undo); 00144 00148 KateUndo::UndoType type() const { return KateUndo::editInsertText; } 00149 00150 private: 00151 int len() const { return m_text.length(); } 00152 00153 private: 00154 const int m_line; 00155 const int m_col; 00156 QString m_text; 00157 }; 00158 00159 class KateEditRemoveTextUndo : public KateUndo 00160 { 00161 public: 00162 KateEditRemoveTextUndo (KateDocument *document, int line, int col, const QString &text) 00163 : KateUndo (document) 00164 , m_line (line) 00165 , m_col (col) 00166 , m_text (text) 00167 {} 00168 00172 bool isEmpty() const; 00173 00177 void undo(); 00178 00182 void redo(); 00183 00187 bool mergeWith (const KateUndo *undo); 00188 00192 KateUndo::UndoType type() const { return KateUndo::editRemoveText; } 00193 00194 private: 00195 int len() const { return m_text.length(); } 00196 00197 private: 00198 const int m_line; 00199 int m_col; 00200 QString m_text; 00201 }; 00202 00203 class KateEditMarkLineAutoWrappedUndo : public KateUndo 00204 { 00205 public: 00206 KateEditMarkLineAutoWrappedUndo (KateDocument *document, int line, bool autowrapped) 00207 : KateUndo (document) 00208 , m_line (line) 00209 , m_autowrapped (autowrapped) 00210 {} 00211 00215 void undo(); 00216 00220 void redo(); 00221 00225 KateUndo::UndoType type() const { return KateUndo::editMarkLineAutoWrapped; } 00226 00227 private: 00228 const int m_line; 00229 const bool m_autowrapped; 00230 }; 00231 00232 class KateEditWrapLineUndo : public KateUndo 00233 { 00234 public: 00235 KateEditWrapLineUndo (KateDocument *document, int line, int col, int len, bool newLine) 00236 : KateUndo (document) 00237 , m_line (line) 00238 , m_col (col) 00239 , m_len (len) 00240 , m_newLine (newLine) 00241 {} 00242 00246 void undo(); 00247 00251 void redo(); 00252 00256 KateUndo::UndoType type() const { return KateUndo::editWrapLine; } 00257 00258 private: 00259 const int m_line; 00260 const int m_col; 00261 const int m_len; 00262 const bool m_newLine; 00263 }; 00264 00265 class KateEditUnWrapLineUndo : public KateUndo 00266 { 00267 public: 00268 KateEditUnWrapLineUndo (KateDocument *document, int line, int col, int len, bool removeLine) 00269 : KateUndo (document) 00270 , m_line (line) 00271 , m_col (col) 00272 , m_len (len) 00273 , m_removeLine (removeLine) 00274 {} 00275 00279 void undo(); 00280 00284 void redo(); 00285 00289 KateUndo::UndoType type() const { return KateUndo::editUnWrapLine; } 00290 00291 private: 00292 const int m_line; 00293 const int m_col; 00294 const int m_len; 00295 const bool m_removeLine; 00296 }; 00297 00298 class KateEditInsertLineUndo : public KateUndo 00299 { 00300 public: 00301 KateEditInsertLineUndo (KateDocument *document, int line, const QString &text) 00302 : KateUndo (document) 00303 , m_line (line) 00304 , m_text (text) 00305 {} 00306 00310 void undo(); 00311 00315 void redo(); 00316 00320 KateUndo::UndoType type() const { return KateUndo::editInsertLine; } 00321 00322 private: 00323 const int m_line; 00324 const QString m_text; 00325 }; 00326 00327 class KateEditRemoveLineUndo : public KateUndo 00328 { 00329 public: 00330 KateEditRemoveLineUndo (KateDocument *document, int line, const QString &text) 00331 : KateUndo (document) 00332 , m_line (line) 00333 , m_text (text) 00334 {} 00335 00339 void undo(); 00340 00344 void redo(); 00345 00349 KateUndo::UndoType type() const { return KateUndo::editRemoveLine; } 00350 00351 private: 00352 const int m_line; 00353 const QString m_text; 00354 }; 00355 00359 class KateUndoGroup 00360 { 00361 public: 00366 explicit KateUndoGroup (KateUndoManager *manager, const KTextEditor::Cursor &cursorPosition, const KTextEditor::Range &selectionRange); 00367 00371 ~KateUndoGroup(); 00372 00373 public: 00377 void undo(KTextEditor::View *view); 00378 00382 void redo(KTextEditor::View *view); 00383 00384 void editEnd(const KTextEditor::Cursor &cursorPosition, const KTextEditor::Range selectionRange); 00385 00392 bool merge (KateUndoGroup* newGroup,bool complex); 00393 00397 void safePoint (bool safePoint=true); 00398 00402 bool isEmpty() const { return m_items.isEmpty(); } 00403 00404 private: 00405 KTextEditor::Document *document(); 00406 00411 KateUndo::UndoType singleType() const; 00412 00418 bool isOnlyType(KateUndo::UndoType type) const; 00419 00420 public: 00425 void addItem (KateUndo *u); 00426 00427 private: 00428 KateUndoManager *const m_manager; 00429 00433 QList<KateUndo*> m_items; 00434 00438 bool m_safePoint; 00439 00443 const KTextEditor::Range m_undoSelection; 00444 00448 KTextEditor::Range m_redoSelection; 00449 00453 const KTextEditor::Cursor m_undoCursor; 00454 00458 KTextEditor::Cursor m_redoCursor; 00459 }; 00460 00461 #endif 00462 00463 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference