From 69af0e69648d80147fd1e27edc2c544d2b3a8e6b Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Tue, 15 Jun 2021 12:41:25 -0500 Subject: [PATCH] Abort a copy-drag in the case where it would result in a copy at the same location also code cleanup: clear_draggingview_list() avoids duplicated code --- gtk2_ardour/editor_drag.cc | 52 +++++++++++++++++++------------------- gtk2_ardour/editor_drag.h | 2 ++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 4a60a08634..3b7acdbf4f 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -1604,7 +1604,19 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr region, } void -RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, MusicSample last_position, int32_t const ev_state) +RegionMoveDrag::clear_draggingview_list () +{ + for (list::const_iterator i = _views.begin(); i != _views.end();) { + list::const_iterator next = i; + ++next; + delete i->view; + i = next; + } + _views.clear(); +} + +void +RegionMoveDrag::finished_copy (bool const changed_position, bool const changed_tracks, MusicSample last_position, int32_t const ev_state) { RegionSelection new_views; PlaylistSet modified_playlists; @@ -1617,20 +1629,23 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed if (_brushing) { /* all changes were made during motion event handlers */ - - for (list::iterator i = _views.begin(); i != _views.end(); ++i) { - delete i->view; - } - + clear_draggingview_list(); _editor->commit_reversible_command (); return; } + /*x_contrained on the same track: this will just make a duplicate region in the same place: abort the operation */ + if (_x_constrained && !changed_tracks) { + clear_draggingview_list(); + _editor->abort_reversible_command (); + return; + } + typedef map, RouteTimeAxisView*> PlaylistMapping; PlaylistMapping playlist_mapping; /* insert the regions into their new playlists */ - for (list::const_iterator i = _views.begin(); i != _views.end();) { + for (list::const_iterator i = _views.begin(); i != _views.end(); i++) { RouteTimeAxisView* dest_rtv = 0; @@ -1693,17 +1708,11 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed new_views.push_back (new_view); } } - - /* Delete the copy of the view that was used for dragging. Need to play safe with the iterator - since deletion will automagically remove it from _views, thus invalidating i as an iterator. - */ - - list::const_iterator next = i; - ++next; - delete i->view; - i = next; } + /* in the past this was done in the main iterator loop; no need */ + clear_draggingview_list(); + /* If we've created new regions either by copying or moving to a new track, we want to replace the old selection with the new ones */ @@ -2052,16 +2061,7 @@ void RegionMoveDrag::aborted (bool movement_occurred) { if (_copy) { - - for (list::const_iterator i = _views.begin(); i != _views.end();) { - list::const_iterator next = i; - ++next; - delete i->view; - i = next; - } - - _views.clear (); - + clear_draggingview_list(); } else { RegionMotionDrag::aborted (movement_occurred); } diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index c96cca672c..0c29cf36ed 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -434,6 +434,8 @@ public: void finished (GdkEvent *, bool); void aborted (bool); + void clear_draggingview_list (); + bool regions_came_from_canvas () const { return true; }