]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/iundo.h
ok
[xonotic/netradiant.git] / include / iundo.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #if !defined(INCLUDED_IUNDO_H)
23 #define INCLUDED_IUNDO_H
24
25 /// \file
26 /// \brief The undo-system interface. Uses the 'memento' pattern.
27
28 #include <cstddef>
29 #include "generic/constant.h"
30
31 class UndoMemento
32 {
33 public:
34   virtual void release() = 0;
35 };
36
37 class Undoable
38 {
39 public:
40   virtual UndoMemento* exportState() const = 0;
41   virtual void importState(const UndoMemento* state) = 0;
42 };
43
44 class UndoObserver
45 {
46 public:
47   virtual void save(Undoable* undoable) = 0;
48 };
49
50 class Callback;
51
52 class UndoTracker
53 {
54 public:
55   virtual void clear() = 0;
56   virtual void begin() = 0;
57   virtual void undo() = 0;
58   virtual void redo() = 0;
59 };
60
61 class UndoSystem
62 {
63 public:
64   INTEGER_CONSTANT(Version, 1);
65   STRING_CONSTANT(Name, "undo");
66
67   virtual UndoObserver* observer(Undoable* undoable) = 0;
68   virtual void release(Undoable* undoable) = 0;
69
70   virtual std::size_t size() const = 0;
71   virtual void start() = 0;
72   virtual void finish(const char* command) = 0;
73   virtual void undo() = 0;
74   virtual void redo() = 0;
75   virtual void clear() = 0;
76
77   virtual void trackerAttach(UndoTracker& tracker) = 0;
78   virtual void trackerDetach(UndoTracker& tracker) = 0;
79 };
80
81 #include "modulesystem.h"
82
83 template<typename Type>
84 class GlobalModule;
85 typedef GlobalModule<UndoSystem> GlobalUndoModule;
86
87 template<typename Type>
88 class GlobalModuleRef;
89 typedef GlobalModuleRef<UndoSystem> GlobalUndoModuleRef;
90
91 inline UndoSystem& GlobalUndoSystem()
92 {
93   return GlobalUndoModule::getTable();
94 }
95
96 class UndoableCommand
97 {
98   const char* m_command;
99 public:
100   UndoableCommand(const char* command) : m_command(command)
101   {
102     GlobalUndoSystem().start();
103   }
104   ~UndoableCommand()
105   {
106     GlobalUndoSystem().finish(m_command);
107   }
108 };
109
110
111 #endif