Import Dialog is Window. Dialog Esc behavior needs to be emulated.
[ardour.git] / gtk2_ardour / editor_routes.cc
index 119387f366de97080757b0e72f3c8665f0741406..487f3aff2b7a8e3a90d069c2023a7219fa9b5111 100644 (file)
@@ -31,6 +31,7 @@
 #include "ardour/audio_track.h"
 #include "ardour/midi_track.h"
 #include "ardour/route.h"
+#include "ardour/selection.h"
 #include "ardour/session.h"
 #include "ardour/solo_isolate_control.h"
 #include "ardour/utils.h"
@@ -319,7 +320,6 @@ EditorRoutes::EditorRoutes (Editor* e)
        _display.set_enable_search (false);
 
        Route::PluginSetup.connect_same_thread (*this, boost::bind (&EditorRoutes::plugin_setup, this, _1, _2, _3));
-       PresentationInfo::Change.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::presentation_info_changed, this, _1), gui_context());
 }
 
 bool
@@ -558,16 +558,6 @@ EditorRoutes::build_menu ()
        items.push_back (MenuElem (_("Only Show Tracks with Regions Under Playhead"), sigc::mem_fun (*this, &EditorRoutes::show_tracks_with_regions_at_playhead)));
 }
 
-void
-EditorRoutes::show_menu ()
-{
-       if (_menu == 0) {
-               build_menu ();
-       }
-
-       _menu->popup (1, gtk_get_current_event_time());
-}
-
 void
 EditorRoutes::redisplay_real ()
 {
@@ -737,7 +727,10 @@ EditorRoutes::time_axis_views_added (list<TimeAxisView*> tavs)
                }
        }
 
-       _display.set_model (Glib::RefPtr<ListStore>());
+       {
+               PBD::Unwinder<bool> uw (_ignore_selection_change, true);
+               _display.set_model (Glib::RefPtr<ListStore>());
+       }
 
        for (list<TimeAxisView*>::iterator x = tavs.begin(); x != tavs.end(); ++x) {
 
@@ -764,7 +757,6 @@ EditorRoutes::time_axis_views_added (list<TimeAxisView*> tavs)
 
                        row[_columns.is_track] = (boost::dynamic_pointer_cast<Track> (stripable) != 0);
 
-
                        if (midi_trk) {
                                row[_columns.is_input_active] = midi_trk->input_active ();
                                row[_columns.is_midi] = true;
@@ -842,7 +834,10 @@ EditorRoutes::time_axis_views_added (list<TimeAxisView*> tavs)
        update_input_active_display ();
        update_active_display ();
 
-       _display.set_model (_model);
+       {
+               PBD::Unwinder<bool> uw (_ignore_selection_change, true);
+               _display.set_model (_model);
+       }
 
        /* now update route order keys from the treeview/track display order */
 
@@ -880,6 +875,8 @@ EditorRoutes::route_removed (TimeAxisView *tv)
        TreeModel::Children rows = _model->children();
        TreeModel::Children::iterator ri;
 
+       PBD::Unwinder<bool> uw (_ignore_selection_change, true);
+
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                if ((*ri)[_columns.tv] == tv) {
                        PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
@@ -887,10 +884,6 @@ EditorRoutes::route_removed (TimeAxisView *tv)
                        break;
                }
        }
-
-       /* the deleted signal for the treeview/model will take
-          care of any updates.
-       */
 }
 
 void
@@ -1092,19 +1085,6 @@ EditorRoutes::sync_presentation_info_from_treeview ()
        }
 }
 
-void
-EditorRoutes::presentation_info_changed (PropertyChange const & what_changed)
-{
-       PropertyChange soh;
-       soh.add (Properties::selected);
-       soh.add (Properties::order);
-       soh.add (Properties::hidden);
-
-       if (what_changed.contains (soh)) {
-               sync_treeview_from_presentation_info (what_changed);
-       }
-}
-
 void
 EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_changed)
 {
@@ -1179,13 +1159,18 @@ EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_
 
        if (what_changed.contains (Properties::selected)) {
 
+               /* by the time this is invoked, the GUI Selection model has
+                * already updated itself.
+                */
+
                TrackViewList tvl;
                PBD::Unwinder<bool> uw (_ignore_selection_change, true);
 
-               /* step one: set the treeview model selection state */
+               /* set the treeview model selection state */
+
                for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
                        boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
-                       if (stripable && stripable->presentation_info().selected()) {
+                       if (stripable && stripable->is_selected()) {
                                TimeAxisView* tav = (*ri)[_columns.tv];
                                if (tav) {
                                        tvl.push_back (tav);
@@ -1195,9 +1180,6 @@ EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_
                                _display.get_selection()->unselect (*ri);
                        }
                }
-
-               /* step two: set the Selection (for stripables/routes) */
-               _editor->get_selection().set (tvl);
        }
 
        redisplay ();
@@ -1469,7 +1451,10 @@ bool
 EditorRoutes::button_press (GdkEventButton* ev)
 {
        if (Keyboard::is_context_menu_event (ev)) {
-               show_menu ();
+               if (_menu == 0) {
+                       build_menu ();
+               }
+               _menu->popup (ev->button, ev->time);
                return true;
        }
 
@@ -1582,13 +1567,14 @@ struct PresentationInfoVCASorter
 void
 EditorRoutes::initial_display ()
 {
-       _model->clear ();
 
        if (!_session) {
+               _model->clear ();
                return;
        }
 
        DisplaySuspender ds;
+       _model->clear ();
 
        StripableList s;
 
@@ -1648,7 +1634,7 @@ EditorRoutes::move_selected_tracks (bool up)
        /* build a list that includes time axis view information */
 
        for (StripableList::const_iterator sli = sl.begin(); sli != sl.end(); ++sli) {
-               TimeAxisView* tv = _editor->axis_view_from_stripable (*sli);
+               TimeAxisView* tv = _editor->time_axis_view_from_stripable (*sli);
                view_stripables.push_back (ViewStripable (tv, *sli));
        }
 
@@ -1669,7 +1655,7 @@ EditorRoutes::move_selected_tracks (bool up)
 
                        while (vsi != view_stripables.end()) {
 
-                               if (vsi->stripable->presentation_info().selected()) {
+                               if (vsi->stripable->is_selected()) {
 
                                        if (unselected_neighbour != view_stripables.end()) {
 
@@ -1704,7 +1690,7 @@ EditorRoutes::move_selected_tracks (bool up)
 
                                --vsi;
 
-                               if (vsi->stripable->presentation_info().selected()) {
+                               if (vsi->stripable->is_selected()) {
 
                                        if (unselected_neighbour != view_stripables.end()) {
 
@@ -1855,6 +1841,7 @@ EditorRoutes::views () const
 void
 EditorRoutes::clear ()
 {
+       PBD::Unwinder<bool> uw (_ignore_selection_change, true);
        _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
        _model->clear ();
        _display.set_model (_model);
@@ -1905,7 +1892,7 @@ EditorRoutes::show_tracks_with_regions_at_playhead ()
 
        set<TimeAxisView*> show;
        for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
-               TimeAxisView* tav = _editor->axis_view_from_stripable (*i);
+               TimeAxisView* tav = _editor->time_axis_view_from_stripable (*i);
                if (tav) {
                        show.insert (tav);
                }