Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
24 
25 #include <list>
26 #include <map>
27 #include <string>
28 
29 #include <sigc++/bind.h>
30 #include <sigc++/slot.h>
31 
32 #ifndef COMPILER_MSVC
33 #include <sys/time.h>
34 #else
35 #include <ardourext/misc.h>
36 #endif
37 
38 #include "pbd/command.h"
39 #include "pbd/libpbd_visibility.h"
40 
41 namespace PBD {
42 
43 typedef sigc::slot<void> UndoAction;
44 
46 {
47 public:
50  UndoTransaction& operator= (const UndoTransaction&);
52 
53  void clear ();
54  bool empty () const;
55  bool clearing () const {
56  return _clearing;
57  }
58 
59  void add_command (PBD::Command* const);
61 
62  std::list<PBD::Command*>::size_type size() const { return actions.size(); }
63 
64  void operator() ();
65  void undo ();
66  void redo ();
67 
68  XMLNode& get_state () const;
69 
70  void set_timestamp (struct timeval& t)
71  {
72  _timestamp = t;
73  }
74 
75  const struct timeval& timestamp () const
76  {
77  return _timestamp;
78  }
79 
80 private:
81  std::list<PBD::Command*> actions;
82  struct timeval _timestamp;
83  bool _clearing;
84 
86 };
87 
89 {
90 public:
93 
94  void add (UndoTransaction* ut);
95  void undo (unsigned int n);
96  void redo (unsigned int n);
97 
98  unsigned long undo_depth () const
99  {
100  return UndoList.size ();
101  }
102  unsigned long redo_depth () const
103  {
104  return RedoList.size ();
105  }
106 
107  std::string next_undo () const
108  {
109  return (UndoList.empty () ? std::string () : UndoList.back ()->name ());
110  }
111  std::string next_redo () const
112  {
113  return (RedoList.empty () ? std::string () : RedoList.back ()->name ());
114  }
115 
116  void clear ();
117  void clear_undo ();
118  void clear_redo ();
119 
120  /* returns all or part of the history.
121  * If depth==0 it returns just the top
122  * node. If depth<0, it returns everything.
123  * If depth>0, it returns state for that
124  * many elements of the history, or
125  * the full history, whichever is smaller.
126  */
127 
128  XMLNode& get_state (int32_t depth = 0);
129  void save_state ();
130 
131  void set_depth (uint32_t);
132 
136 
137 private:
138  bool _clearing;
139  uint32_t _depth;
140  std::list<UndoTransaction*> UndoList;
141  std::list<UndoTransaction*> RedoList;
142 
144 };
145 
146 } /* namespace */
147 
~UndoHistory()
Definition: undo.h:92
void remove(UndoTransaction *)
PBD::Signal< void()> BeginUndoRedo
Definition: undo.h:134
unsigned long redo_depth() const
Definition: undo.h:102
PBD::Signal< void()> EndUndoRedo
Definition: undo.h:135
void redo(unsigned int n)
uint32_t _depth
Definition: undo.h:139
XMLNode & get_state(int32_t depth=0)
void set_depth(uint32_t)
bool _clearing
Definition: undo.h:138
void undo(unsigned int n)
void add(UndoTransaction *ut)
std::list< UndoTransaction * > UndoList
Definition: undo.h:140
std::string next_undo() const
Definition: undo.h:107
std::string next_redo() const
Definition: undo.h:111
PBD::Signal< void()> Changed
Definition: undo.h:133
unsigned long undo_depth() const
Definition: undo.h:98
std::list< UndoTransaction * > RedoList
Definition: undo.h:141
void about_to_explicitly_delete()
void remove_command(PBD::Command *const)
bool clearing() const
Definition: undo.h:55
UndoTransaction(const UndoTransaction &)
void set_timestamp(struct timeval &t)
Definition: undo.h:70
std::list< PBD::Command * >::size_type size() const
Definition: undo.h:62
const struct timeval & timestamp() const
Definition: undo.h:75
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:43