allow to remove a session from the recent list
authorRobin Gareus <robin@gareus.org>
Wed, 30 Nov 2016 10:07:37 +0000 (11:07 +0100)
committerRobin Gareus <robin@gareus.org>
Wed, 30 Nov 2016 10:07:37 +0000 (11:07 +0100)
gtk2_ardour/session_dialog.cc
gtk2_ardour/session_dialog.h

index 6cb28f99b04e51d612a89a6a582715b887763723..f94074f718081e213871ea24fbcc6091151b437a 100644 (file)
@@ -324,6 +324,7 @@ SessionDialog::setup_recent_sessions ()
 
        recent_session_display.show();
        recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &SessionDialog::recent_row_activated));
+       recent_session_display.signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::recent_button_press), false);
 }
 
 void
@@ -1178,6 +1179,65 @@ SessionDialog::recent_row_activated (const Gtk::TreePath&, Gtk::TreeViewColumn*)
        response (RESPONSE_ACCEPT);
 }
 
+bool
+SessionDialog::recent_button_press (GdkEventButton* ev)
+{
+       if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3) ) {
+
+               TreeModel::Path path;
+               TreeViewColumn* column;
+               int cellx, celly;
+               if (recent_session_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
+                       Glib::RefPtr<Gtk::TreeView::Selection> selection = recent_session_display.get_selection();
+                       if (selection) {
+                               selection->unselect_all();
+                               selection->select(path);
+                       }
+               }
+
+               if (recent_session_display.get_selection()->count_selected_rows() > 0) {
+                       recent_context_mennu (ev);
+               }
+       }
+       return false;
+}
+
+void
+SessionDialog::recent_context_mennu (GdkEventButton *ev)
+{
+       using namespace Gtk::Menu_Helpers;
+
+       TreeIter iter = recent_session_display.get_selection()->get_selected();
+       assert (iter);
+       string s = (*iter)[recent_session_columns.fullpath];
+       if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
+               s = Glib::path_get_dirname (s);
+       }
+       if (!Glib::file_test (s, Glib::FILE_TEST_IS_DIR)) {
+               return;
+       }
+
+       Gtk::Menu* m = manage (new Menu);
+       MenuList& items = m->items ();
+       items.push_back (MenuElem (s));
+       items.push_back (SeparatorElem());
+       items.push_back (MenuElem (_("Remove from recent"), sigc::mem_fun (*this, &SessionDialog::recent_remove_selected)));
+       m->popup (ev->button, ev->time);
+}
+
+void
+SessionDialog::recent_remove_selected ()
+{
+       TreeIter iter = recent_session_display.get_selection()->get_selected();
+       assert (iter);
+       string s = (*iter)[recent_session_columns.fullpath];
+       if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
+               s = Glib::path_get_dirname (s);
+       }
+       ARDOUR::remove_recent_sessions (s);
+       redisplay_recent_sessions ();
+}
+
 void
 SessionDialog::disable_plugins_clicked ()
 {
index 98bdd6b7885ef6d09ebee3e55e46be6f6c66fca7..a464e5a5ef182fe09ed70f7a1b79e39d4dfcf6f0 100644 (file)
@@ -139,15 +139,18 @@ class SessionDialog : public ArdourDialog {
        Gtk::TreeView                recent_session_display;
        Glib::RefPtr<Gtk::TreeStore> recent_session_model;
        Gtk::ScrolledWindow          recent_scroller;
-        Gtk::Label                   recent_label;
+       Gtk::Label                   recent_label;
        Gtk::FileChooserButton       existing_session_chooser;
        int redisplay_recent_sessions ();
        void recent_session_row_selected ();
        void recent_session_sort_changed ();
        void recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
+       bool recent_button_press (GdkEventButton*);
+       void recent_context_mennu (GdkEventButton*);
+       void recent_remove_selected ();
 
        void existing_session_selected ();
-        void session_selected ();
+       void session_selected ();
 
        /* new sessions */