From: Hans Fugal Date: Wed, 26 Jul 2006 23:28:54 +0000 (+0000) Subject: r199@gandalf: fugalh | 2006-07-26 17:22:38 -0600 X-Git-Tag: 2.0beta4~65^2~20 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=8e301e875aacc4b7d37f6ed552e460511dafb7f2;p=ardour.git 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 --- diff --git a/gtk2_ardour/audio_time_axis.cc b/gtk2_ardour/audio_time_axis.cc index 7fbe7c9fd8..ebc97be77b 100644 --- a/gtk2_ardour/audio_time_axis.cc +++ b/gtk2_ardour/audio_time_axis.cc @@ -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, 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, before, after)); what_we_got->unref (); ret = true; } diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc index f5b23f01ae..bd7ed326d8 100644 --- a/gtk2_ardour/automation_line.cc +++ b/gtk2_ardour/automation_line.cc @@ -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(*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(*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(*this, before, get_state())); trackview.editor.current_session()->commit_reversible_command (); diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index f4b9aaaf7b..4680e3a35f 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -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(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(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(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(alist, before, alist.get_state())); delete what_we_got; what_we_got = 0; ret = true; diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index e4d8ec6ce6..4b17c9e6b0 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -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(*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(*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(*to_playlist, to_playlist->get_state())); } } @@ -3435,7 +3435,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event out: for (set::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(*(*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(*pl, pl->get_state())); } } } @@ -4187,8 +4187,8 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) for (set::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(*(*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(*(region.playlist()), after)); rv.unhide_envelope (); } diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 579b2403c6..815d50ae3e 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -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(*pl, pl->get_state())); } } } @@ -3055,7 +3055,7 @@ Editor::cut_copy_regions (CutCopyOp op) for (set::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) { (*pl)->thaw (); - session->add_redo_no_execute ((*pl)->get_memento()); + session->add_command (MementoRedoCommand(*(*pl), *(*pl)->get_state())); } } diff --git a/libs/pbd3/pbd/memento_command.h b/libs/pbd3/pbd/memento_command.h index 8c2ddefcf7..1419c904bb 100644 --- a/libs/pbd3/pbd/memento_command.h +++ b/libs/pbd3/pbd/memento_command.h @@ -51,4 +51,38 @@ class MementoCommand : public Command XMLNode &before, &after; }; +template +class MementoUndoCommand : public MementoCommand +{ +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 MementoRedoCommand : public MementoCommand +{ +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__