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