Ardour  8.12
undo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 Brett Viren
3  * Copyright (C) 2006-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2006 Hans Fugal <hans@fugal.net>
5  * Copyright (C) 2007-2009 David Robillard <d@drobilla.net>
6  * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef __lib_pbd_undo_h__
24 #define __lib_pbd_undo_h__
25 
26 #include <list>
27 #include <map>
28 #include <string>
29 
30 #include <sigc++/bind.h>
31 #include <sigc++/slot.h>
32 
33 #ifndef COMPILER_MSVC
34 #include <sys/time.h>
35 #else
36 #include <ardourext/misc.h>
37 #endif
38 
39 #include "pbd/command.h"
40 #include "pbd/libpbd_visibility.h"
41 
42 namespace PBD {
43 
44 typedef sigc::slot<void> UndoAction;
45 
47 {
48 public:
51  UndoTransaction& operator= (const UndoTransaction&);
53 
54  void clear ();
55  bool empty () const;
56  bool clearing () const {
57  return _clearing;
58  }
59 
60  void add_command (PBD::Command* const);
62 
63  std::list<PBD::Command*>::size_type size() const { return actions.size(); }
64 
65  void operator() ();
66  void undo ();
67  void redo ();
68 
69  XMLNode& get_state () const;
70 
71  void set_timestamp (struct timeval& t)
72  {
73  _timestamp = t;
74  }
75 
76  const struct timeval& timestamp () const
77  {
78  return _timestamp;
79  }
80 
81 private:
82  std::list<PBD::Command*> actions;
83  struct timeval _timestamp;
84  bool _clearing;
85 
87 };
88 
90 {
91 public:
94 
95  void add (UndoTransaction* ut);
96  void undo (unsigned int n);
97  void redo (unsigned int n);
98 
99  unsigned long undo_depth () const
100  {
101  return UndoList.size ();
102  }
103  unsigned long redo_depth () const
104  {
105  return RedoList.size ();
106  }
107 
108  std::string next_undo () const
109  {
110  return (UndoList.empty () ? std::string () : UndoList.back ()->name ());
111  }
112  std::string next_redo () const
113  {
114  return (RedoList.empty () ? std::string () : RedoList.back ()->name ());
115  }
116 
117  void clear ();
118  void clear_undo ();
119  void clear_redo ();
120 
121  /* returns all or part of the history.
122  * If depth==0 it returns just the top
123  * node. If depth<0, it returns everything.
124  * If depth>0, it returns state for that
125  * many elements of the history, or
126  * the full history, whichever is smaller.
127  */
128 
129  XMLNode& get_state (int32_t depth = 0);
130  void save_state ();
131 
132  void set_depth (uint32_t);
133 
134  PBD::Signal0<void> Changed;
135  PBD::Signal0<void> BeginUndoRedo;
136  PBD::Signal0<void> EndUndoRedo;
137 
138 private:
139  bool _clearing;
140  uint32_t _depth;
141  std::list<UndoTransaction*> UndoList;
142  std::list<UndoTransaction*> RedoList;
143 
145 };
146 
147 } /* namespace */
148 
149 #endif /* __lib_pbd_undo_h__ */
PBD::Signal0< void > EndUndoRedo
Definition: undo.h:136
~UndoHistory()
Definition: undo.h:93
void remove(UndoTransaction *)
unsigned long redo_depth() const
Definition: undo.h:103
PBD::Signal0< void > Changed
Definition: undo.h:134
void redo(unsigned int n)
uint32_t _depth
Definition: undo.h:140
XMLNode & get_state(int32_t depth=0)
void set_depth(uint32_t)
bool _clearing
Definition: undo.h:139
void undo(unsigned int n)
void add(UndoTransaction *ut)
std::list< UndoTransaction * > UndoList
Definition: undo.h:141
std::string next_undo() const
Definition: undo.h:108
std::string next_redo() const
Definition: undo.h:112
PBD::Signal0< void > BeginUndoRedo
Definition: undo.h:135
unsigned long undo_depth() const
Definition: undo.h:99
std::list< UndoTransaction * > RedoList
Definition: undo.h:142
void about_to_explicitly_delete()
void remove_command(PBD::Command *const)
bool clearing() const
Definition: undo.h:56
UndoTransaction(const UndoTransaction &)
void set_timestamp(struct timeval &t)
Definition: undo.h:71
std::list< PBD::Command * >::size_type size() const
Definition: undo.h:63
const struct timeval & timestamp() const
Definition: undo.h:76
bool empty() const
void add_command(PBD::Command *const)
XMLNode & get_state() const
Definition: xml++.h:114
#define LIBPBD_API
Definition: axis_view.h:42
sigc::slot< void > UndoAction
Definition: undo.h:44