Merged with trunk, and a few trivial GUI updates etc.
[ardour.git] / libs / pbd / pbd / undo.h
1 /* 
2    Copyright (C) 2002 Brett Viren & Paul Davis
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #ifndef __lib_pbd_undo_h__
22 #define __lib_pbd_undo_h__
23
24 #include <string>
25 #include <list>
26 #include <sigc++/slot.h>
27 #include <sys/time.h>
28
29 using std::string;
30 using std::list;
31
32 typedef sigc::slot<void> UndoAction;
33
34 class UndoCommand 
35 {
36   public:
37         UndoCommand ();
38         UndoCommand (const UndoCommand&);
39         UndoCommand& operator= (const UndoCommand&);
40
41         void clear ();
42
43         void add_undo (const UndoAction&);
44         void add_redo (const UndoAction&);
45         void add_redo_no_execute (const UndoAction&);
46
47         void undo();
48         void redo();
49         
50         void set_name (const string& str) {
51                 _name = str;
52         }
53         const string& name() const { return _name; }
54
55         void set_timestamp (struct timeval &t) {
56                 _timestamp = t;
57         }
58
59         const struct timeval& timestamp() const {
60                 return _timestamp;
61         }
62
63   private:
64         list<UndoAction> redo_actions;
65         list<UndoAction> undo_actions;
66         struct timeval   _timestamp;
67         string           _name;
68 };
69
70 class UndoHistory
71 {
72   public:
73         UndoHistory() {}
74         ~UndoHistory() {}
75         
76         void add (UndoCommand uc);
77         void undo (unsigned int n);
78         void redo (unsigned int n);
79         
80         unsigned long undo_depth() const { return UndoList.size(); }
81         unsigned long redo_depth() const { return RedoList.size(); }
82         
83         string next_undo() const { return (UndoList.empty() ? string("") : UndoList.back().name()); }
84         string next_redo() const { return (RedoList.empty() ? string("") : RedoList.back().name()); }
85
86         void clear ();
87         void clear_undo ();
88         void clear_redo ();
89
90   private:
91         list<UndoCommand> UndoList;
92         list<UndoCommand> RedoList;
93 };
94
95
96 #endif /* __lib_pbd_undo_h__ */