From b20f4eaf8cbfc179000b3676c07e17ac9fcac898 Mon Sep 17 00:00:00 2001 From: VKamyshniy Date: Thu, 19 Feb 2015 01:50:10 +0200 Subject: [PATCH] [Summary] Introducing the reworks in part of editor's command to keep implementation of undoable commands in form of special methods. Intention is to keep the code easy to maintain and "implement new things". As well all the command names for Undo/Redo menu items should be assured in terms of TRACKs. --- gtk2_ardour/editor.h | 4 ++ gtk2_ardour/editor_drag.cc | 27 +---------- gtk2_ardour/editor_drag.h | 20 ++++++-- gtk2_ardour/editor_undoable.cc | 86 ++++++++++++++++++++++++++++++++++ gtk2_ardour/wscript | 1 + 5 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 gtk2_ardour/editor_undoable.cc diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index b5f42f89a6..00e3ab22b9 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -174,6 +174,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void undo (uint32_t n = 1); void redo (uint32_t n = 1); + + // UNDOable commands: + + void move_markers_command (std::list&, const std::list&); XMLNode& get_state (); int set_state (const XMLNode&, int version); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 9b8d86ea90..b1a27e7ec4 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3710,32 +3710,7 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) } _editor->_dragging_edit_point = false; - - XMLNode &before = _editor->session()->locations()->get_state(); - - MarkerSelection::iterator i; - CopiedLocationInfo::iterator x; - - for (i = _editor->selection->markers.begin(), x = _copied_locations.begin(); - x != _copied_locations.end() && i != _editor->selection->markers.end(); - ++i, ++x) { - - Location* location = (*i)->location (); - Location* copy = (*x).location; - - if (location && !location->locked()) { - if (location->is_mark()) { - location->set_start (copy->start()); - } else { - location->set (copy->start(), copy->end()); - } - } - } - - _editor->begin_reversible_command ( _("move marker") ); - XMLNode &after = _editor->session()->locations()->get_state(); - _editor->session()->add_command(new MementoCommand(*(_editor->session()->locations()), &before, &after)); - _editor->commit_reversible_command (); + _editor->move_markers_command (_editor->selection->markers, _copied_locations.locations ()); } void diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index c9d15d1983..84babecca0 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -814,12 +814,24 @@ private: CopiedLocationMarkerInfo (ARDOUR::Location* l, Marker* m); }; - typedef std::list CopiedLocationInfo; - CopiedLocationInfo _copied_locations; + class CopiedLocationInfo : public std::list + { + public: + std::list locations () { + std::list result; + for (std::list::iterator i = begin (); + i != end (); + ++i) { + result.push_back ((*i).location); + } + return result; + } + }; + CopiedLocationInfo _copied_locations; - void show_drag_text (ARDOUR::Location*) const; + void show_drag_text (ARDOUR::Location*) const; - static sigc::connection timeout_connection; + static sigc::connection timeout_connection; }; /** Control point drag */ diff --git a/gtk2_ardour/editor_undoable.cc b/gtk2_ardour/editor_undoable.cc new file mode 100644 index 0000000000..aebe4f246f --- /dev/null +++ b/gtk2_ardour/editor_undoable.cc @@ -0,0 +1,86 @@ +/* + Copyright (C) 2000-2015 Waves Audio Ltd. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include + +#include "pbd/memento_command.h" +#include "pbd/file_utils.h" +#include "gtkmm2ext/utils.h" + +#include "ardour/filesystem_paths.h" +#include "ardour/profile.h" +#include "ardour/session.h" +#include "ardour/types.h" + +#include "canvas/canvas.h" +#include "canvas/pixbuf.h" + +#include "actions.h" +#include "ardour_ui.h" +#include "editing.h" +#include "editor.h" +#include "gui_thread.h" +#include "time_axis_view.h" +#include "utils.h" +#include "i18n.h" + +void +Editor::move_markers_command (std::list&markers, const std::list& locations) +{ + const size_t markers_count = markers.size (); + if (markers_count != locations.size ()) { + WavesMessageDialog (_("Move Markers"), _("MOVE MARKERS: Invalid argument!")).run (); + return; + } + + std::list::iterator mi; + std::list::const_iterator li; + + for (mi = markers.begin (); mi != markers.end (); ++mi) { + ARDOUR::Location* location = (*mi)->location (); + if (location && !location->locked ()) { + break; + } + } + + if (mi == markers.end ()) { + return; + } + + begin_reversible_command (_("move marker")); + XMLNode &before = session()->locations()->get_state(); + + for (mi = markers.begin (), li = locations.begin (); mi != markers.end (); ++mi, ++li) { + ARDOUR::Location* location = (*mi)->location (); + ARDOUR::Location* copy = (*li); + + if (location && !location->locked()) { + if (location->is_mark()) { + location->set_start (copy->start()); + } else { + location->set (copy->start(), copy->end()); + } + } + } + + XMLNode &after = session()->locations()->get_state(); + session()->add_command(new MementoCommand(*(session()->locations()), &before, &after)); + commit_reversible_command (); +} diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 60f8e8fcb7..00357da9ea 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -95,6 +95,7 @@ gtk2_ardour_sources = [ 'edit_note_dialog.cc', 'editing.cc', 'editor.cc', + 'editor_undoable.cc', 'editor_actions.cc', 'editor_audio_import.cc', 'editor_audiotrack.cc',