r199@gandalf: fugalh | 2006-07-26 17:22:38 -0600
Memento(Redo|Undo)Command has a noop for the undo or redo respectively, and we don't need both before and after state. This is primarily useful for drag start/finish callbacks, and really only makes sense where wrapped by (begin|commit)_reversible_command (a composite command). Also a few more "normal" MementoCommands. git-svn-id: svn://localhost/ardour2/branches/undo@695 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
b7bffbe7a2
commit
8e301e875a
@ -1739,12 +1739,14 @@ AudioTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
|
||||
}
|
||||
}
|
||||
|
||||
XMLNode &before, &after;
|
||||
switch (op) {
|
||||
case Cut:
|
||||
_session.add_undo (playlist->get_memento());
|
||||
before = playlist->get_state();
|
||||
if ((what_we_got = playlist->cut (time)) != 0) {
|
||||
editor.get_cut_buffer().add (what_we_got);
|
||||
_session.add_redo_no_execute (playlist->get_memento());
|
||||
after = playlist->get_state();
|
||||
_session.add_command (MementoCommand<Playlist>(*playlist, before, after));
|
||||
ret = true;
|
||||
}
|
||||
break;
|
||||
@ -1755,9 +1757,9 @@ AudioTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
|
||||
break;
|
||||
|
||||
case Clear:
|
||||
_session.add_undo (playlist->get_memento());
|
||||
before = playlist->get_state();
|
||||
if ((what_we_got = playlist->cut (time)) != 0) {
|
||||
_session.add_redo_no_execute (playlist->get_memento());
|
||||
_session.add_command(MementoCommand<Playlist>(*playlist, before, after));
|
||||
what_we_got->unref ();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -887,7 +887,7 @@ AutomationLine::start_drag (ControlPoint* cp, float fraction)
|
||||
}
|
||||
|
||||
trackview.editor.current_session()->begin_reversible_command (str);
|
||||
trackview.editor.current_session()->add_undo (get_memento());
|
||||
trackview.editor.current_session()->add_command (MementoUndoCommand<AutomationLine>(*this, get_state()));
|
||||
|
||||
first_drag_fraction = fraction;
|
||||
last_drag_fraction = fraction;
|
||||
@ -936,7 +936,7 @@ AutomationLine::end_drag (ControlPoint* cp)
|
||||
|
||||
update_pending = false;
|
||||
|
||||
trackview.editor.current_session()->add_redo_no_execute (get_memento());
|
||||
trackview.editor.current_session()->add_command (MementoRedoCommand<AutomationLine>(*this, get_state()));
|
||||
trackview.editor.current_session()->commit_reversible_command ();
|
||||
trackview.editor.current_session()->set_dirty ();
|
||||
}
|
||||
@ -1226,7 +1226,6 @@ AutomationLine::clear ()
|
||||
{
|
||||
/* parent must create command */
|
||||
XMLNode &before = get_state();
|
||||
trackview.editor.current_session()->add_undo (get_memento());
|
||||
alist.clear();
|
||||
trackview.editor.current_session()->add_command (MementoCommand<AutomationLine>(*this, before, get_state()));
|
||||
trackview.editor.current_session()->commit_reversible_command ();
|
||||
|
@ -500,13 +500,14 @@ AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& sel
|
||||
AutomationList& alist (line.the_list());
|
||||
bool ret = false;
|
||||
|
||||
_session.add_undo (alist.get_memento());
|
||||
XMLNode &before, &after;
|
||||
before = alist.get_state();
|
||||
|
||||
switch (op) {
|
||||
case Cut:
|
||||
if ((what_we_got = alist.cut (selection.time.front().start, selection.time.front().end)) != 0) {
|
||||
editor.get_cut_buffer().add (what_we_got);
|
||||
_session.add_redo_no_execute (alist.get_memento());
|
||||
_session.add_command(MementoCommand<AutomationList>(alist, before, alist.get_state()));
|
||||
ret = true;
|
||||
}
|
||||
break;
|
||||
@ -518,7 +519,7 @@ AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& sel
|
||||
|
||||
case Clear:
|
||||
if ((what_we_got = alist.cut (selection.time.front().start, selection.time.front().end)) != 0) {
|
||||
_session.add_redo_no_execute (alist.get_memento());
|
||||
_session.add_command(MementoCommand<AutomationList>(alist, before, alist.get_state()));
|
||||
delete what_we_got;
|
||||
what_we_got = 0;
|
||||
ret = true;
|
||||
@ -580,8 +581,9 @@ AutomationTimeAxisView::cut_copy_clear_objects_one (AutomationLine& line, PointS
|
||||
AutomationList* what_we_got = 0;
|
||||
AutomationList& alist (line.the_list());
|
||||
bool ret = false;
|
||||
XMLNode &before, &after;
|
||||
|
||||
_session.add_undo (alist.get_memento());
|
||||
before = alist.get_state();
|
||||
|
||||
for (PointSelection::iterator i = selection.begin(); i != selection.end(); ++i) {
|
||||
|
||||
@ -593,7 +595,7 @@ AutomationTimeAxisView::cut_copy_clear_objects_one (AutomationLine& line, PointS
|
||||
case Cut:
|
||||
if ((what_we_got = alist.cut ((*i).start, (*i).end)) != 0) {
|
||||
editor.get_cut_buffer().add (what_we_got);
|
||||
_session.add_redo_no_execute (alist.get_memento());
|
||||
_session.add_command (MementoCommand<AutomationList>(alist, before, alist.get_state()));
|
||||
ret = true;
|
||||
}
|
||||
break;
|
||||
@ -605,7 +607,7 @@ AutomationTimeAxisView::cut_copy_clear_objects_one (AutomationLine& line, PointS
|
||||
|
||||
case Clear:
|
||||
if ((what_we_got = alist.cut ((*i).start, (*i).end)) != 0) {
|
||||
_session.add_redo_no_execute (alist.get_memento());
|
||||
_session.add_command (MementoCommand<AutomationList>(alist, before, alist.get_state()));
|
||||
delete what_we_got;
|
||||
what_we_got = 0;
|
||||
ret = true;
|
||||
|
@ -2787,7 +2787,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
|
||||
|
||||
insert_result = affected_playlists.insert (to_playlist);
|
||||
if (insert_result.second) {
|
||||
session->add_undo (to_playlist->get_memento ());
|
||||
session->add_command (MementoUndoCommand<Playlist>(*to_playlist, to_playlist->get_state()));
|
||||
}
|
||||
|
||||
latest_regionview = 0;
|
||||
@ -3225,7 +3225,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
|
||||
insert_result = motion_frozen_playlists.insert (pl);
|
||||
if (insert_result.second) {
|
||||
pl->freeze();
|
||||
session->add_undo(pl->get_memento());
|
||||
session->add_command(MementoUndoCommand<Playlist>(*pl, pl->get_state()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3353,7 +3353,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
|
||||
insert_result = motion_frozen_playlists.insert(to_playlist);
|
||||
if (insert_result.second) {
|
||||
to_playlist->freeze();
|
||||
session->add_undo(to_playlist->get_memento());
|
||||
session->add_command(MementoUndoCommand<Playlist>(*to_playlist, to_playlist->get_state()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -3435,7 +3435,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
|
||||
out:
|
||||
for (set<Playlist*>::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) {
|
||||
(*p)->thaw ();
|
||||
session->add_redo_no_execute ((*p)->get_memento());
|
||||
session->add_command (MementoRedoCommand<Playlist>(*(*p), (*p)->get_state()));
|
||||
}
|
||||
|
||||
motion_frozen_playlists.clear ();
|
||||
@ -3997,7 +3997,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
|
||||
Playlist * pl = (*i)->region.playlist();
|
||||
insert_result = motion_frozen_playlists.insert (pl);
|
||||
if (insert_result.second) {
|
||||
session->add_undo (pl->get_memento());
|
||||
session->add_command(MementoUndoCommand<Playlist>(*pl, pl->get_state()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4187,8 +4187,8 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
|
||||
|
||||
for (set<Playlist*>::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) {
|
||||
//(*p)->thaw ();
|
||||
session->add_redo_no_execute ((*p)->get_memento());
|
||||
}
|
||||
session->add_command (MementoRedoCommand<Playlist>(*(*p), (*p)->get_state()));
|
||||
}
|
||||
|
||||
motion_frozen_playlists.clear ();
|
||||
|
||||
@ -4293,7 +4293,8 @@ Editor::thaw_region_after_trim (AudioRegionView& rv)
|
||||
}
|
||||
|
||||
region.thaw (_("trimmed region"));
|
||||
session->add_redo_no_execute (region.playlist()->get_memento());
|
||||
XMLNode &after = region.playlist()->get_state();
|
||||
session->add_command (MementoRedoCommand<Playlist>(*(region.playlist()), after));
|
||||
|
||||
rv.unhide_envelope ();
|
||||
}
|
||||
|
@ -2997,7 +2997,7 @@ Editor::cut_copy_regions (CutCopyOp op)
|
||||
insert_result = freezelist.insert (pl);
|
||||
if (insert_result.second) {
|
||||
pl->freeze ();
|
||||
session->add_undo (pl->get_memento());
|
||||
session->add_command (MementoUndoCommand<Playlist>(*pl, pl->get_state()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3055,7 +3055,7 @@ Editor::cut_copy_regions (CutCopyOp op)
|
||||
|
||||
for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
|
||||
(*pl)->thaw ();
|
||||
session->add_redo_no_execute ((*pl)->get_memento());
|
||||
session->add_command (MementoRedoCommand<Playlist>(*(*pl), *(*pl)->get_state()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,4 +51,38 @@ class MementoCommand : public Command
|
||||
XMLNode &before, &after;
|
||||
};
|
||||
|
||||
template <class obj_T>
|
||||
class MementoUndoCommand : public MementoCommand<obj_T>
|
||||
{
|
||||
public:
|
||||
MementoUndoCommand(obj_T &obj,
|
||||
XMLNode &before)
|
||||
: obj(obj), before(before) {}
|
||||
void operator() () { /* noop */ }
|
||||
void undo() { obj.set_state(before); }
|
||||
virtual XMLNode &serialize()
|
||||
{
|
||||
// obj.id
|
||||
// key is "MementoCommand" or something
|
||||
// before and after mementos
|
||||
}
|
||||
}
|
||||
|
||||
template <class obj_T>
|
||||
class MementoRedoCommand : public MementoCommand<obj_T>
|
||||
{
|
||||
public:
|
||||
MementoUndoCommand(obj_T &obj,
|
||||
XMLNode &after)
|
||||
: obj(obj), after(after) {}
|
||||
void operator() () { obj.set_state(after); }
|
||||
void undo() { /* noop */ }
|
||||
virtual XMLNode &serialize()
|
||||
{
|
||||
// obj.id
|
||||
// key is "MementoCommand" or something
|
||||
// before and after mementos
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __lib_pbd_memento_h__
|
||||
|
Loading…
Reference in New Issue
Block a user