Insert new LocationEditRow on location add, rather than rebuilding the whole VBox...
authorCarl Hetherington <carl@carlh.net>
Wed, 14 Jul 2010 21:18:25 +0000 (21:18 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 14 Jul 2010 21:18:25 +0000 (21:18 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7416 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/location_ui.cc
libs/ardour/ardour/location.h

index 9613aaccb50d193e42e063479e8204daf9d3a0e3..fda29be193a336d4ecd87b44b589c32d12765313 100644 (file)
@@ -703,6 +703,12 @@ LocationUI::location_redraw_ranges ()
        range_rows.show();
 }
 
+struct LocationSortByStart {
+    bool operator() (Location *a, Location *b) {
+           return a->start() < b->start();
+    }
+};
+
 void
 LocationUI::location_added (Location* location)
 {
@@ -712,8 +718,39 @@ LocationUI::location_added (Location* location)
                punch_edit_row.set_location(location);
        } else if (location->is_auto_loop()) {
                loop_edit_row.set_location(location);
-       } else {
-               refresh_location_list ();
+       } else if (location->is_range_marker() || location->is_mark()) {
+               Locations::LocationList loc = _session->locations()->list ();
+               loc.sort (LocationSortByStart ());
+
+               LocationEditRow* erow = manage (new LocationEditRow (_session, location));
+               erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
+               Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
+
+               /* Step through the location list and the GUI list to find the place to insert */
+               Locations::LocationList::iterator i = loc.begin ();
+               Box_Helpers::BoxList::iterator j = children.begin ();
+               while (i != loc.end()) {
+
+                       if (location->flags() != (*i)->flags()) {
+                               /* Skip locations in the session list that aren't of the right type */
+                               ++i;
+                               continue;
+                       }
+
+                       if (*i == location) {
+                               children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
+                               break;
+                       }
+
+                       ++i;
+                       
+                       if (j != children.end()) {
+                               ++j;
+                       }
+               }
+
+               range_rows.show_all ();
+               location_rows.show_all ();
        }
 }
 
@@ -738,12 +775,6 @@ LocationUI::location_removed (Location* location)
        }
 }
 
-struct LocationSortByStart {
-    bool operator() (Location *a, Location *b) {
-           return a->start() < b->start();
-    }
-};
-
 void
 LocationUI::map_locations (Locations::LocationList& locations)
 {
index 7d3b0ac1a9ea003bcced6eaf41e8977500b67471..3f3eaf4fc8cde97cedb7fd8eac95a8e7873f7409 100644 (file)
@@ -104,6 +104,8 @@ class Location : public PBD::StatefulDestructible
        bool is_range_marker() const { return _flags & IsRangeMarker; }
        bool matches (Flags f) const { return _flags & f; }
 
+       Flags flags () const { return _flags; }
+
        PBD::Signal1<void,Location*> name_changed;
        PBD::Signal1<void,Location*> end_changed;
        PBD::Signal1<void,Location*> start_changed;