Fix crash when X11 is not available for VST UIs
[ardour.git] / gtk2_ardour / editor_selection.cc
index e24c525abb9de720aebbbadcfed7755138ba5f8a..1e28d77e0b01743f80bb0383ee6b735d04393c1b 100644 (file)
@@ -1,21 +1,26 @@
 /*
-    Copyright (C) 2000-2018 Paul Davis
-
-    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.
-
-*/
+ * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2007-2015 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2013-2017 Nick Mainsbridge <mainsbridge@gmail.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2014-2019 Ben Loftis <ben@harrisonconsoles.com>
+ * Copyright (C) 2015 AndrĂ© Nusser <andre.nusser@googlemail.com>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <algorithm>
 #include <cstdlib>
@@ -35,6 +40,7 @@
 #include "editor.h"
 #include "editor_drag.h"
 #include "editor_routes.h"
+#include "editor_sources.h"
 #include "actions.h"
 #include "audio_time_axis.h"
 #include "audio_region_view.h"
@@ -1214,6 +1220,7 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
        bool have_selection = false;
        bool have_entered = false;
        bool have_edit_point = false;
+       bool have_selected_source = false;
        RegionSelection rs;
 
        // std::cerr << "STRRA: crossing ? " << because_canvas_crossing << " within ? " << within_track_canvas
@@ -1229,6 +1236,10 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
                rs.add (entered_regionview);
        }
 
+       if ( _sources->get_single_selection() ) {
+               have_selected_source = true;
+       }
+
        if (rs.empty() && !selection->tracks.empty()) {
 
                /* no selected regions, but some selected tracks.
@@ -1278,6 +1289,8 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
                        sensitive = true;
                } else if ((tgt & EditPointRegions) && have_edit_point) {
                        sensitive = true;
+               } else if ((tgt & ListSelection) && have_selected_source ) {
+                       sensitive = true;
                }
 
                x->second.action->set_sensitive (sensitive);
@@ -1503,13 +1516,13 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
                _region_actions->get_action("naturalize-region")->set_sensitive (false);
        }
 
-/* Todo: insert-region-from-source-list  
+       /* Todo: insert-region-from-source-list */
        /* XXX: should also check that there is a track of the appropriate type for the selected region */
 #if 0
        if (_edit_point == EditAtMouse || _regions->get_single_selection() == 0 || selection->tracks.empty()) {
-               _region_actions->get_action("insert-region-from-region-list")->set_sensitive (false);
+               _region_actions->get_action("insert-region-from-source-list")->set_sensitive (false);
        } else {
-               _region_actions->get_action("insert-region-from-region-list")->set_sensitive (true);
+               _region_actions->get_action("insert-region-from-source-list")->set_sensitive (true);
        }
 #endif
 
@@ -1565,13 +1578,12 @@ Editor::region_selection_changed ()
        sensitize_the_right_region_actions (false);
 
        /* propagate into backend */
+       assert (_session);
 
-       if (_session) {
-               if (!selection->regions.empty()) {
-                       _session->set_object_selection (selection->regions.start(), selection->regions.end_sample());
-               } else {
-                       _session->clear_object_selection ();
-               }
+       if (!selection->regions.empty()) {
+               _session->set_object_selection (selection->regions.start(), selection->regions.end_sample());
+       } else {
+               _session->clear_object_selection ();
        }
 
        if (_session->solo_selection_active()) {
@@ -1720,7 +1732,7 @@ Editor::invert_selection ()
 {
 
        if (internal_editing()) {
-               for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               for (MidiRegionSelection::iterator i = selection->midi_regions.begin(); i != selection->midi_regions.end(); ++i) {
                        MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
                        if (mrv) {
                                mrv->invert_selection ();