r199@gandalf: fugalh | 2006-07-26 17:22:38 -0600
authorHans Fugal <hans@fugal.net>
Wed, 26 Jul 2006 23:28:54 +0000 (23:28 +0000)
committerHans Fugal <hans@fugal.net>
Wed, 26 Jul 2006 23:28:54 +0000 (23:28 +0000)
 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

gtk2_ardour/audio_time_axis.cc
gtk2_ardour/automation_line.cc
gtk2_ardour/automation_time_axis.cc
gtk2_ardour/editor_mouse.cc
gtk2_ardour/editor_ops.cc
libs/pbd3/pbd/memento_command.h

index 7fbe7c9fd865d201091542718d6c1a0367ab6693..ebc97be77b9ae9125180ba646d45f4d7d5fac228 100644 (file)
@@ -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;
                }
index f5b23f01ae9208e50fff6934220d60c060e6cd11..bd7ed326d8d9f5c86a76680f86b9865c2005051e 100644 (file)
@@ -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 ();
index f4b9aaaf7bada2907105a53d826e5387b68ef377..4680e3a35ffdf4e62e48922ab553112d3cfe7b0d 100644 (file)
@@ -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;
index e4d8ec6ce6be88c2941ac241d2d4c51562420e49..4b17c9e6b059d80f0f36e2b6d39c841800d4b7f2 100644 (file)
@@ -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 ();
 }
index 579b2403c649194e130beef9195edc391d881ee9..815d50ae3e939a787688020613f507ba0a884c39 100644 (file)
@@ -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()));
        }
 }
 
index 8c2ddefcf766f660dfb832ca942eba545956a6aa..1419c904bb650f36d984f268651173810e5fe67c 100644 (file)
@@ -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__