]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - include/iundo.h
Merge branch 'gamepackdeps' into 'master'
[xonotic/netradiant.git] / include / iundo.h
index d5194b520b620af2d76812b93a41c8c72c28ff09..eb1e8681c9c16a7882d240306dc20bff43daafb0 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-#ifndef _IUNDO_H_\r
-#define _IUNDO_H_\r
-\r
-#define UNDO_MAJOR "undo"\r
-\r
-//start operation\r
-typedef void (*PFN_UNDOSTART) (char *operation);\r
-//end operation\r
-typedef void (*PFN_UNDOEND) (void);\r
-//add brush to the undo\r
-typedef void (*PFN_UNDOADDBRUSH) (brush_t *pBrush);\r
-//end a brush after the operation is performed\r
-typedef void (*PFN_UNDOENDBRUSH) (brush_t *pBrush);\r
-//add a list with brushes to the undo\r
-typedef void (*PFN_UNDOADDBRUSHLIST) (brush_t *brushlist);\r
-//end a list with brushes after the operation is performed\r
-typedef void (*PFN_UNDOENDBRUSHLIST) (brush_t *brushlist);\r
-//add entity to undo\r
-typedef void (*PFN_UNDOADDENTITY) (entity_t *entity);\r
-//end an entity after the operation is performed\r
-typedef void (*PFN_UNDOENDENTITY) (entity_t *entity);\r
-//undo last operation (bSilent == true -> will not print the "undone blah blah message")\r
-typedef void (*PFN_UNDO) (unsigned char bSilent);\r
-//redo last undone operation\r
-typedef void (*PFN_REDO) (void);\r
-//get the undo Id of the next undo (0 if none available)\r
-typedef int (*PFN_GETUNDOID) (void);\r
-//returns true if there is something to be undone available\r
-typedef int  (*PFN_UNDOAVAILABLE) (void);\r
-//returns true if there is something to redo available\r
-typedef int  (*PFN_REDOAVAILABLE) (void);\r
-\r
-struct _QERUndoTable\r
-{\r
-  int m_nSize;\r
-  PFN_UNDOSTART m_pfnUndo_Start;\r
-  PFN_UNDOEND m_pfnUndo_End;\r
-  PFN_UNDOADDBRUSH m_pfnUndo_AddBrush;\r
-  PFN_UNDOENDBRUSH m_pfnUndo_EndBrush;\r
-  PFN_UNDOADDBRUSHLIST m_pfnUndo_AddBrushList;\r
-  PFN_UNDOENDBRUSHLIST m_pfnUndo_EndBrushList;\r
-  PFN_UNDOADDENTITY m_pfnUndo_AddEntity;\r
-  PFN_UNDOENDENTITY m_pfnUndo_EndEntity;\r
-  PFN_UNDO m_pfnUndo_Undo;\r
-  PFN_REDO m_pfnUndo_Redo;\r
-  PFN_GETUNDOID m_pfnUndo_GetUndoId;\r
-  PFN_UNDOAVAILABLE m_pfnUndo_UndoAvailable;\r
-  PFN_REDOAVAILABLE m_pfnUndo_RedoAvailable;\r
-};\r
-\r
-#ifdef USE_UNDOTABLE_DEFINE\r
-#ifndef __UNDOTABLENAME\r
-#define __UNDOTABLENAME g_UndoTable\r
-#endif\r
-#define Undo_Start __UNDOTABLENAME.m_pfnUndo_Start\r
-#define Undo_End __UNDOTABLENAME.m_pfnUndo_End\r
-#define Undo_AddBrush __UNDOTABLENAME.m_pfnUndo_AddBrush\r
-#define Undo_EndBrush __UNDOTABLENAME.m_pfnUndo_EndBrush\r
-#define Undo_AddBrushList __UNDOTABLENAME.m_pfnUndo_AddBrushList\r
-#define Undo_EndBrushList __UNDOTABLENAME.m_pfnUndo_EndBrushList\r
-#define Undo_AddEntity __UNDOTABLENAME.m_pfnUndo_AddEntity\r
-#define Undo_EndEntity __UNDOTABLENAME.m_pfnUndo_EndEntity\r
-#endif\r
-\r
-#endif // _IUNDO_H_\r
-\r
+/*
+   Copyright (C) 2001-2006, William Joseph.
+   All Rights Reserved.
+
+   This file is part of GtkRadiant.
+
+   GtkRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   GtkRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GtkRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if !defined( INCLUDED_IUNDO_H )
+#define INCLUDED_IUNDO_H
+
+/// \file
+/// \brief The undo-system interface. Uses the 'memento' pattern.
+
+#include <cstddef>
+#include "generic/constant.h"
+#include "generic/callbackfwd.h"
+
+class UndoMemento
+{
+public:
+virtual void release() = 0;
+virtual ~UndoMemento() {
+}
+};
+
+class Undoable
+{
+public:
+virtual UndoMemento* exportState() const = 0;
+virtual void importState( const UndoMemento* state ) = 0;
+virtual ~Undoable() {
+}
+};
+
+class UndoObserver
+{
+public:
+virtual void save( Undoable* undoable ) = 0;
+virtual ~UndoObserver() {
+}
+};
+
+class UndoTracker
+{
+public:
+virtual void clear() = 0;
+virtual void begin() = 0;
+virtual void undo() = 0;
+virtual void redo() = 0;
+virtual ~UndoTracker() {
+}
+};
+
+class UndoSystem
+{
+public:
+INTEGER_CONSTANT( Version, 1 );
+STRING_CONSTANT( Name, "undo" );
+
+virtual UndoObserver* observer( Undoable* undoable ) = 0;
+virtual void release( Undoable* undoable ) = 0;
+
+virtual std::size_t size() const = 0;
+virtual void start() = 0;
+virtual void finish( const char* command ) = 0;
+virtual void undo() = 0;
+virtual void redo() = 0;
+virtual void clear() = 0;
+
+virtual void trackerAttach( UndoTracker& tracker ) = 0;
+virtual void trackerDetach( UndoTracker& tracker ) = 0;
+
+virtual ~UndoSystem() {
+}
+};
+
+#include "modulesystem.h"
+
+template<typename Type>
+class GlobalModule;
+typedef GlobalModule<UndoSystem> GlobalUndoModule;
+
+template<typename Type>
+class GlobalModuleRef;
+typedef GlobalModuleRef<UndoSystem> GlobalUndoModuleRef;
+
+inline UndoSystem& GlobalUndoSystem(){
+       return GlobalUndoModule::getTable();
+}
+
+class UndoableCommand
+{
+const char* m_command;
+public:
+UndoableCommand( const char* command ) : m_command( command ){
+       GlobalUndoSystem().start();
+}
+~UndoableCommand(){
+       GlobalUndoSystem().finish( m_command );
+}
+};
+
+
+#endif