00001 00006 /* 00007 Copyright (C) 2001-2006, William Joseph. 00008 All Rights Reserved. 00009 00010 This file is part of GtkRadiant. 00011 00012 GtkRadiant is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 GtkRadiant is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with GtkRadiant; if not, write to the Free Software 00024 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00025 */ 00026 00027 #if !defined(INCLUDED_IUNDO_H) 00028 #define INCLUDED_IUNDO_H 00029 00030 #include <cstddef> 00031 #include <string> 00032 00033 #include "generic/constant.h" 00034 #include "generic/callbackfwd.h" 00035 00045 class UndoMemento 00046 { 00047 public: 00048 virtual ~UndoMemento () 00049 { 00050 } 00051 }; 00052 00066 class Undoable 00067 { 00068 public: 00069 virtual ~Undoable () 00070 { 00071 } 00076 virtual UndoMemento* exportState () const = 0; 00081 virtual void importState (const UndoMemento* state) = 0; 00082 }; 00083 00084 class UndoObserver 00085 { 00086 public: 00087 virtual ~UndoObserver () 00088 { 00089 } 00090 virtual void save (Undoable* undoable) = 0; 00091 }; 00092 00093 class UndoTracker 00094 { 00095 public: 00096 virtual ~UndoTracker () 00097 { 00098 } 00102 virtual void clear () = 0; 00106 virtual void clearRedo () = 0; 00110 virtual void begin () = 0; 00114 virtual void undo () = 0; 00115 00119 virtual void redo () = 0; 00120 }; 00121 00122 class UndoSystem 00123 { 00124 public: 00125 INTEGER_CONSTANT(Version, 1); 00126 STRING_CONSTANT(Name, "undo"); 00127 00128 virtual ~UndoSystem () 00129 { 00130 } 00131 virtual UndoObserver* observer (Undoable* undoable) = 0; 00132 virtual void release (Undoable* undoable) = 0; 00133 00134 virtual std::size_t size () const = 0; 00135 virtual void start () = 0; 00136 virtual void finish (const std::string& command) = 0; 00137 virtual void undo () = 0; 00138 virtual void redo () = 0; 00139 virtual void clear () = 0; 00140 virtual void clearRedo () = 0; 00141 00142 virtual void trackerAttach (UndoTracker& tracker) = 0; 00143 virtual void trackerDetach (UndoTracker& tracker) = 0; 00144 00145 virtual std::size_t getLevels () const = 0; 00146 }; 00147 00148 #include "modulesystem.h" 00149 00150 template<typename Type> 00151 class GlobalModule; 00152 typedef GlobalModule<UndoSystem> GlobalUndoModule; 00153 00154 template<typename Type> 00155 class GlobalModuleRef; 00156 typedef GlobalModuleRef<UndoSystem> GlobalUndoModuleRef; 00157 00158 inline UndoSystem& GlobalUndoSystem () 00159 { 00160 return GlobalUndoModule::getTable(); 00161 } 00162 00163 class UndoableCommand 00164 { 00165 const std::string _command; 00166 public: 00167 UndoableCommand (const std::string& command) : 00168 _command(command) 00169 { 00170 GlobalUndoSystem().start(); 00171 } 00172 ~UndoableCommand () 00173 { 00174 GlobalUndoSystem().finish(_command); 00175 } 00176 }; 00177 00178 #endif