2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_IUNDO_H )
23 #define INCLUDED_IUNDO_H
26 /// \brief The undo-system interface. Uses the 'memento' pattern.
29 #include "generic/constant.h"
30 #include "generic/callback.h"
35 virtual void release() = 0;
36 virtual ~UndoMemento() {
43 virtual UndoMemento* exportState() const = 0;
44 virtual void importState( const UndoMemento* state ) = 0;
52 virtual void save( Undoable* undoable ) = 0;
53 virtual ~UndoObserver() {
60 virtual void clear() = 0;
61 virtual void begin() = 0;
62 virtual void undo() = 0;
63 virtual void redo() = 0;
64 virtual ~UndoTracker() {
71 INTEGER_CONSTANT( Version, 1 );
72 STRING_CONSTANT( Name, "undo" );
74 virtual UndoObserver* observer( Undoable* undoable ) = 0;
75 virtual void release( Undoable* undoable ) = 0;
77 virtual std::size_t size() const = 0;
78 virtual void start() = 0;
79 virtual void finish( const char* command ) = 0;
80 virtual void undo() = 0;
81 virtual void redo() = 0;
82 virtual void clear() = 0;
84 virtual void trackerAttach( UndoTracker& tracker ) = 0;
85 virtual void trackerDetach( UndoTracker& tracker ) = 0;
87 virtual ~UndoSystem() {
91 #include "modulesystem.h"
93 template<typename Type>
95 typedef GlobalModule<UndoSystem> GlobalUndoModule;
97 template<typename Type>
98 class GlobalModuleRef;
99 typedef GlobalModuleRef<UndoSystem> GlobalUndoModuleRef;
101 inline UndoSystem& GlobalUndoSystem(){
102 return GlobalUndoModule::getTable();
105 class UndoableCommand
107 const char* m_command;
109 UndoableCommand( const char* command ) : m_command( command ){
110 GlobalUndoSystem().start();
113 GlobalUndoSystem().finish( m_command );