only show plugin context-menu if there is a selection
[ardour.git] / gtk2_ardour / mixer_ui.cc
index 7bbfb843c6dd83dec7e6778fd83c39e2ea9c1a6e..45299ba020b96b97cf041a29e22a89d60cc77741 100644 (file)
@@ -207,6 +207,7 @@ Mixer_UI::Mixer_UI ()
        favorite_plugins_display.set_drag_column (favorite_plugins_columns.name.index());
        favorite_plugins_display.signal_row_activated().connect (sigc::mem_fun (*this, &Mixer_UI::plugin_row_activated));
        favorite_plugins_display.signal_button_press_event().connect (sigc::mem_fun (*this, &Mixer_UI::plugin_row_button_press), false);
+       favorite_plugins_display.signal_drop.connect (sigc::mem_fun (*this, &Mixer_UI::plugin_drop));
 
        favorite_plugins_scroller.add (favorite_plugins_display);
        favorite_plugins_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
@@ -2344,7 +2345,6 @@ Mixer_UI::popup_note_context_menu (GdkEventButton *ev)
        if (_selection.routes.empty()) {
                items.push_back (MenuElem (_("No Track/Bus is selected.")));
        } else {
-
                items.push_back (MenuElem (_("Add at the top"),
                                        sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddTop)));
                items.push_back (MenuElem (_("Add Pre-Fader"),
@@ -2354,8 +2354,16 @@ Mixer_UI::popup_note_context_menu (GdkEventButton *ev)
                items.push_back (MenuElem (_("Add at the end"),
                                        sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddBottom)));
        }
+
        items.push_back (SeparatorElem());
+
        items.push_back (MenuElem (_("Remove from favorites"), sigc::mem_fun (*this, &Mixer_UI::remove_selected_from_favorites)));
+
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (ppp && ppp->_preset.valid) {
+               items.push_back (MenuElem (_("Delete Preset"), sigc::mem_fun (*this, &Mixer_UI::delete_selected_preset)));
+       }
+
        m->popup (ev->button, ev->time);
 }
 
@@ -2363,44 +2371,75 @@ bool
 Mixer_UI::plugin_row_button_press (GdkEventButton *ev)
 {
        if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3) ) {
-               popup_note_context_menu (ev);
+               TreeModel::Path path;
+               TreeViewColumn* column;
+               int cellx, celly;
+               if (favorite_plugins_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
+                       Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
+                       if (selection) {
+                               selection->unselect_all();
+                               selection->select(path);
+                       }
+               }
+               ARDOUR::PluginPresetPtr ppp = selected_plugin();
+               if (ppp) {
+                       popup_note_context_menu (ev);
+               }
        }
        return false;
 }
 
-void
-Mixer_UI::add_selected_processor (ProcessorPosition pos)
+
+PluginPresetPtr
+Mixer_UI::selected_plugin ()
 {
        Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
        if (!selection) {
-               return;
+               return PluginPresetPtr();
        }
        Gtk::TreeModel::iterator iter = selection->get_selected();
        if (!iter) {
-               return;
+               return PluginPresetPtr();
        }
-       ARDOUR::PluginPresetPtr ppp = (*iter)[favorite_plugins_columns.plugin];
-       add_favorite_processor (ppp, pos);
+       return (*iter)[favorite_plugins_columns.plugin];
 }
 
 void
-Mixer_UI::remove_selected_from_favorites ()
+Mixer_UI::add_selected_processor (ProcessorPosition pos)
 {
-       Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
-       if (!selection) {
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (ppp) {
+               add_favorite_processor (ppp, pos);
+       }
+}
+
+void
+Mixer_UI::delete_selected_preset ()
+{
+       if (!_session) {
                return;
        }
-       Gtk::TreeModel::iterator iter = selection->get_selected();
-       if (!iter) {
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (!ppp || !ppp->_preset.valid) {
+               return;
+       }
+       PluginPtr plugin = ppp->_pip->load (*_session);
+       plugin->get_presets();
+       plugin->remove_preset (ppp->_preset.label);
+}
+
+void
+Mixer_UI::remove_selected_from_favorites ()
+{
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (!ppp) {
                return;
        }
-       ARDOUR::PluginPresetPtr ppp = (*iter)[favorite_plugins_columns.plugin];
        PluginManager::PluginStatusType status = PluginManager::Normal;
        PluginManager& manager (PluginManager::instance());
 
        manager.set_status (ppp->_pip->type, ppp->_pip->unique_id, status);
        manager.save_statuses ();
-       sync_treeview_from_favorite_order ();
 }
 
 void
@@ -2475,3 +2514,22 @@ PluginTreeStore::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const
        }
        return false;
 }
+
+void
+Mixer_UI::plugin_drop (const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData& data)
+{
+       if (data.get_target() != "PluginPresetPtr") {
+               return;
+       }
+       if (data.get_length() != sizeof (PluginPresetPtr)) {
+               return;
+       }
+       const void *d = data.get_data();
+       const PluginPresetPtr ppp = *(static_cast<const PluginPresetPtr*> (d));
+
+       PluginManager::PluginStatusType status = PluginManager::Favorite;
+       PluginManager& manager (PluginManager::instance());
+
+       manager.set_status (ppp->_pip->type, ppp->_pip->unique_id, status);
+       manager.save_statuses ();
+}