]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/iundo.h
- Brushplugin Version 2.0, supports multiple collapse modes and a materialignore...
[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 #include "generic/callbackfwd.h"
31
32 class UndoMemento
33 {
34 public:
35   virtual void release() = 0;
36 };
37
38 class Undoable
39 {
40 public:
41   virtual UndoMemento* exportState() const = 0;
42   virtual void importState(const UndoMemento* state) = 0;
43 };
44
45 class UndoObserver
46 {
47 public:
48   virtual void save(Undoable* undoable) = 0;
49 };
50
51 class UndoTracker
52 {
53 public:
54   virtual void clear() = 0;
55   virtual void begin() = 0;
56   virtual void undo() = 0;
57   virtual void redo() = 0;
58 };
59
60 class UndoSystem
61 {
62 public:
63   INTEGER_CONSTANT(Version, 1);
64   STRING_CONSTANT(Name, "undo");
65
66   virtual UndoObserver* observer(Undoable* undoable) = 0;
67   virtual void release(Undoable* undoable) = 0;
68
69   virtual std::size_t size() const = 0;
70   virtual void start() = 0;
71   virtual void finish(const char* command) = 0;
72   virtual void undo() = 0;
73   virtual void redo() = 0;
74   virtual void clear() = 0;
75
76   virtual void trackerAttach(UndoTracker& tracker) = 0;
77   virtual void trackerDetach(UndoTracker& tracker) = 0;
78 };
79
80 #include "modulesystem.h"
81
82 template<typename Type>
83 class GlobalModule;
84 typedef GlobalModule<UndoSystem> GlobalUndoModule;
85
86 template<typename Type>
87 class GlobalModuleRef;
88 typedef GlobalModuleRef<UndoSystem> GlobalUndoModuleRef;
89
90 inline UndoSystem& GlobalUndoSystem()
91 {
92   return GlobalUndoModule::getTable();
93 }
94
95 class UndoableCommand
96 {
97   const char* m_command;
98 public:
99   UndoableCommand(const char* command) : m_command(command)
100   {
101     GlobalUndoSystem().start();
102   }
103   ~UndoableCommand()
104   {
105     GlobalUndoSystem().finish(m_command);
106   }
107 };
108
109
110 #endif