ardour
undo.h
Go to the documentation of this file.
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 */
19 
20 #ifndef __lib_pbd_undo_h__
21 #define __lib_pbd_undo_h__
22 
23 #include <string>
24 #include <list>
25 #include <map>
26 #include <sigc++/slot.h>
27 #include <sigc++/bind.h>
28 #ifndef COMPILER_MSVC
29 #include <sys/time.h>
30 #else
31 #include <ardourext/misc.h>
32 #endif
33 
34 #include "pbd/libpbd_visibility.h"
35 #include "pbd/command.h"
36 
37 typedef sigc::slot<void> UndoAction;
38 
40 {
41  public:
42  UndoTransaction ();
44  UndoTransaction& operator= (const UndoTransaction&);
45  ~UndoTransaction ();
46 
47  void clear ();
48  bool empty() const;
49  bool clearing () const { return _clearing; }
50 
51  void add_command (Command* const);
52  void remove_command (Command* const);
53 
54  void operator() ();
55  void undo();
56  void redo();
57 
58  XMLNode &get_state();
59 
60  void set_timestamp (struct timeval &t) {
61  _timestamp = t;
62  }
63 
64  const struct timeval& timestamp() const {
65  return _timestamp;
66  }
67 
68  private:
69  std::list<Command*> actions;
70  struct timeval _timestamp;
71  bool _clearing;
72 
73  friend void command_death (UndoTransaction*, Command *);
74 
75  void about_to_explicitly_delete ();
76 };
77 
79 {
80  public:
81  UndoHistory();
83 
84  void add (UndoTransaction* ut);
85  void undo (unsigned int n);
86  void redo (unsigned int n);
87 
88  unsigned long undo_depth() const { return UndoList.size(); }
89  unsigned long redo_depth() const { return RedoList.size(); }
90 
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()); }
93 
94  void clear ();
95  void clear_undo ();
96  void clear_redo ();
97 
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.
104  */
105 
106  XMLNode &get_state(int32_t depth = 0);
107  void save_state();
108 
109  void set_depth (uint32_t);
110 
111  PBD::Signal0<void> Changed;
112  PBD::Signal0<void> BeginUndoRedo;
113  PBD::Signal0<void> EndUndoRedo;
114 
115  private:
116  bool _clearing;
117  uint32_t _depth;
118  std::list<UndoTransaction*> UndoList;
119  std::list<UndoTransaction*> RedoList;
120 
121  void remove (UndoTransaction*);
122 };
123 
124 
125 #endif /* __lib_pbd_undo_h__ */
std::list< Command * > actions
Definition: undo.h:69
virtual void undo()=0
PBD::Signal0< void > Changed
Definition: undo.h:111
uint32_t _depth
Definition: undo.h:117
virtual void operator()()=0
#define LIBPBD_API
unsigned long redo_depth() const
Definition: undo.h:89
void command_death(UndoTransaction *ut, Command *c)
Definition: undo.cc:55
bool _clearing
Definition: undo.h:116
bool clearing() const
Definition: undo.h:49
sigc::slot< void > UndoAction
Definition: undo.h:37
PBD::Signal0< void > EndUndoRedo
Definition: undo.h:113
void set_timestamp(struct timeval &t)
Definition: undo.h:60
std::string next_redo() const
Definition: undo.h:92
virtual void redo()
Definition: command.h:42
PBD::Signal0< void > BeginUndoRedo
Definition: undo.h:112
~UndoHistory()
Definition: undo.h:82
unsigned long undo_depth() const
Definition: undo.h:88
std::list< UndoTransaction * > UndoList
Definition: undo.h:118
bool _clearing
Definition: undo.h:71
virtual bool empty() const
Definition: command.h:47
const struct timeval & timestamp() const
Definition: undo.h:64
Definition: xml++.h:95
std::string next_undo() const
Definition: undo.h:91
virtual XMLNode & get_state()
Definition: command.cc:23
std::list< UndoTransaction * > RedoList
Definition: undo.h:119