diff options
author | David Robillard <d@drobilla.net> | 2009-05-05 01:53:30 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-05-05 01:53:30 +0000 |
commit | 83c27fa88879e20cd7ec8a87865dc2d3d91d1a88 (patch) | |
tree | a807e1ef077257a0c9b1bb7648c8ba60b8f4a0b0 | |
parent | 90c82a97a7f4e3d8eeb3688eaa8a1aca7ac760c2 (diff) |
Support recursive undo events.
Code can now call begin_reversible_command and commit_reversible_command around a region
of code which itself calls those functions (and so on), areas contained within enclosing
regions will be added as sub-commands of the current command (i.e. it's a stack).
Fixes mantix issue #0002558.
git-svn-id: svn://localhost/ardour2/branches/3.0@5051 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/editor_markers.cc | 14 | ||||
-rw-r--r-- | gtk2_ardour/editor_tempodisplay.cc | 8 | ||||
-rw-r--r-- | gtk2_ardour/rhythm_ferret.cc | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 7 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 26 |
5 files changed, 32 insertions, 25 deletions
diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index 6406f04e54..489b6e8cbc 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -400,13 +400,13 @@ Editor::mouse_add_new_marker (nframes64_t where, bool is_cd, bool is_xrun) if (session) { session->locations()->next_available_name(markername, markerprefix); if (!is_xrun && !choose_new_marker_name(markername)) { - return; + return; } Location *location = new Location (where, where, markername, (Location::Flags) flags); session->begin_reversible_command (_("add marker")); - XMLNode &before = session->locations()->get_state(); + XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); - XMLNode &after = session->locations()->get_state(); + XMLNode &after = session->locations()->get_state(); session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after)); session->commit_reversible_command (); @@ -1042,7 +1042,7 @@ Editor::marker_menu_rename () loc = find_location_from_marker (marker, is_start); if (!loc) return; - + ArdourPrompter dialog (true); string txt; @@ -1075,12 +1075,12 @@ Editor::marker_menu_rename () } begin_reversible_command ( _("rename marker") ); - XMLNode &before = session->locations()->get_state(); + XMLNode &before = session->locations()->get_state(); dialog.get_result(txt); loc->set_name (txt); - - XMLNode &after = session->locations()->get_state(); + + XMLNode &after = session->locations()->get_state(); session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after)); commit_reversible_command (); } diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 00d0b94a0e..be7203f2db 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -337,7 +337,7 @@ Editor::edit_tempo_section (TempoSection* section) tempo_dialog.set_position (Gtk::WIN_POS_MOUSE); ensure_float (tempo_dialog); - + switch (tempo_dialog.run ()) { case RESPONSE_ACCEPT: break; @@ -350,16 +350,16 @@ Editor::edit_tempo_section (TempoSection* section) BBT_Time when; tempo_dialog.get_bbt_time(when); bpm = max (0.01, bpm); - + cerr << "Editing tempo section to be at " << when << endl; session->tempo_map().dump (cerr); begin_reversible_command (_("replace tempo mark")); - XMLNode &before = session->tempo_map().get_state(); + XMLNode &before = session->tempo_map().get_state(); session->tempo_map().replace_tempo (*section, Tempo (bpm,nt)); session->tempo_map().dump (cerr); session->tempo_map().move_tempo (*section, when); session->tempo_map().dump (cerr); - XMLNode &after = session->tempo_map().get_state(); + XMLNode &after = session->tempo_map().get_state(); session->add_command (new MementoCommand<TempoMap>(session->tempo_map(), &before, &after)); commit_reversible_command (); } diff --git a/gtk2_ardour/rhythm_ferret.cc b/gtk2_ardour/rhythm_ferret.cc index ecad24e181..62f51c8a65 100644 --- a/gtk2_ardour/rhythm_ferret.cc +++ b/gtk2_ardour/rhythm_ferret.cc @@ -406,8 +406,8 @@ RhythmFerret::do_split_action () i = tmp; } + session->commit_reversible_command (); - } void diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index bc8dcb81f1..8bef24a7e2 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -838,7 +838,8 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable void commit_reversible_command (Command* cmd = 0); void add_command (Command *const cmd) { - current_trans->add_command (cmd); + assert(!_current_trans.empty ()); + _current_trans.top()->add_command (cmd); } std::map<PBD::ID, PBD::StatefulThingWithGoingAway*> registry; @@ -1613,8 +1614,8 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable void reverse_diskstream_buffers (); - UndoHistory _history; - UndoTransaction* current_trans; + UndoHistory _history; + std::stack<UndoTransaction*> _current_trans; GlobalRouteBooleanState get_global_route_boolean (bool (Route::*method)(void) const); GlobalRouteMeterState get_global_route_metering (); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 88259e944f..44e8bb0392 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -205,7 +205,6 @@ Session::first_stage_init (string fullpath, string snapshot_name) _npan_buffers = 0; pending_abort = false; destructive_index = 0; - current_trans = 0; first_file_data_format_reset = true; first_file_header_format_reset = true; butler_thread = (pthread_t) 0; @@ -2251,29 +2250,36 @@ Session::edit_group_by_name (string name) } void -Session::begin_reversible_command (const string& name) +Session::begin_reversible_command(const string& name) { - current_trans = new UndoTransaction; - current_trans->set_name (name); + UndoTransaction* trans = new UndoTransaction(); + trans->set_name(name); + if (!_current_trans.empty()) { + _current_trans.top()->add_command(trans); + } + _current_trans.push(trans); } void -Session::commit_reversible_command (Command *cmd) +Session::commit_reversible_command(Command *cmd) { + assert(!_current_trans.empty()); struct timeval now; if (cmd) { - current_trans->add_command (cmd); + _current_trans.top()->add_command(cmd); } - if (current_trans->empty()) { + if (_current_trans.top()->empty()) { + _current_trans.pop(); return; } - gettimeofday (&now, 0); - current_trans->set_timestamp (now); + gettimeofday(&now, 0); + _current_trans.top()->set_timestamp(now); - _history.add (current_trans); + _history.add(_current_trans.top()); + _current_trans.pop(); } Session::GlobalRouteBooleanState |