2 Copyright (C) 2002 Brett Viren & Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __lib_pbd_undo_h__
21 #define __lib_pbd_undo_h__
26 #include <sigc++/slot.h>
27 #include <sigc++/bind.h>
31 #include <ardourext/misc.h>
34 #include "pbd/libpbd_visibility.h"
35 #include "pbd/command.h"
37 typedef sigc::slot<void> UndoAction;
39 class LIBPBD_API UndoTransaction : public Command
43 UndoTransaction (const UndoTransaction&);
44 UndoTransaction& operator= (const UndoTransaction&);
49 bool clearing () const { return _clearing; }
51 void add_command (Command* const);
52 void remove_command (Command* const);
60 void set_timestamp (struct timeval &t) {
64 const struct timeval& timestamp() const {
69 std::list<Command*> actions;
70 struct timeval _timestamp;
73 friend void command_death (UndoTransaction*, Command *);
75 void about_to_explicitly_delete ();
78 class LIBPBD_API UndoHistory : public PBD::ScopedConnectionList
84 void add (UndoTransaction* ut);
85 void undo (unsigned int n);
86 void redo (unsigned int n);
88 unsigned long undo_depth() const { return UndoList.size(); }
89 unsigned long redo_depth() const { return RedoList.size(); }
91 std::string next_undo() const { return (UndoList.empty() ? std::string() : UndoList.back()->name()); }
92 std::string next_redo() const { return (RedoList.empty() ? std::string() : RedoList.back()->name()); }
98 /* returns all or part of the history.
99 If depth==0 it returns just the top
100 node. If depth<0, it returns everything.
101 If depth>0, it returns state for that
102 many elements of the history, or
103 the full history, whichever is smaller.
106 XMLNode &get_state(int32_t depth = 0);
109 void set_depth (uint32_t);
111 PBD::Signal0<void> Changed;
112 PBD::Signal0<void> BeginUndoRedo;
113 PBD::Signal0<void> EndUndoRedo;
118 std::list<UndoTransaction*> UndoList;
119 std::list<UndoTransaction*> RedoList;
121 void remove (UndoTransaction*);
125 #endif /* __lib_pbd_undo_h__ */