Another try at fixing #4301.
[ardour.git] / gtk2_ardour / group_tabs.cc
index 2e35d84809085f238b2d0eccb418f5debbcb6109..8deec1d70af39abee6463da2e2aadb829d7c91f1 100644 (file)
@@ -104,6 +104,7 @@ GroupTabs::on_button_press_event (GdkEventButton* ev)
 
                } else {
                        _dragging_new_tab = false;
+                       _initial_dragging_routes = routes_for_tab (t);
                }
 
                _dragging = t;
@@ -204,12 +205,15 @@ GroupTabs::on_button_release_event (GdkEventButton* ev)
                                boost::shared_ptr<RouteList> r = _session->get_routes ();
                                for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
 
-                                       if (find (routes.begin(), routes.end(), *i) == routes.end()) {
-                                               /* this route is not on the list of those that should be in _dragging's group */
-                                               if ((*i)->route_group() == _dragging->group) {
-                                                       _dragging->group->remove (*i);
-                                               }
-                                       } else {
+                                       bool const was_in_tab = find (
+                                               _initial_dragging_routes.begin(), _initial_dragging_routes.end(), *i
+                                               ) != _initial_dragging_routes.end ();
+
+                                       bool const now_in_tab = find (routes.begin(), routes.end(), *i) != routes.end();
+
+                                       if (was_in_tab && !now_in_tab) {
+                                               _dragging->group->remove (*i);
+                                       } else if (!was_in_tab && now_in_tab) {
                                                _dragging->group->add (*i);
                                        }
                                }
@@ -221,6 +225,7 @@ GroupTabs::on_button_release_event (GdkEventButton* ev)
        }
 
        _dragging = 0;
+       _initial_dragging_routes.clear ();
 
        return true;
 }