From 02b0ecdacb12d7f0ae3fb0c4a6b9683e7197fecd Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Fri, 16 Apr 2021 12:41:11 -0500 Subject: [PATCH] Safeguard snapshot switch Require double-click, and prompt user, before opening a session snapshot from the sidebar. --- gtk2_ardour/editor_snapshots.cc | 66 +++++++++++++++++++-------------- gtk2_ardour/editor_snapshots.h | 1 - 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/gtk2_ardour/editor_snapshots.cc b/gtk2_ardour/editor_snapshots.cc index 16b3e36fbf..099dde8023 100644 --- a/gtk2_ardour/editor_snapshots.cc +++ b/gtk2_ardour/editor_snapshots.cc @@ -52,7 +52,7 @@ EditorSnapshots::EditorSnapshots () { _snapshot_model = ListStore::create (_columns); _snapshot_display.set_model (_snapshot_model); - _snapshot_display.append_column (_("Snapshot (click to load)"), _columns.visible_name); + _snapshot_display.append_column (_("Snapshot (dbl-click to load)"), _columns.visible_name); _snapshot_display.append_column (_("Modified Date"), _columns.time_formatted); _snapshot_display.set_size_request (75, -1); _snapshot_display.set_headers_visible (true); @@ -60,7 +60,6 @@ EditorSnapshots::EditorSnapshots () _scroller.add (_snapshot_display); _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - _snapshot_display.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &EditorSnapshots::selection_changed)); _snapshot_display.signal_button_press_event().connect (sigc::mem_fun (*this, &EditorSnapshots::button_press), false); } @@ -72,31 +71,6 @@ EditorSnapshots::set_session (Session* s) redisplay (); } -/* A new snapshot has been selected. */ -void -EditorSnapshots::selection_changed () -{ - if (_snapshot_display.get_selection()->count_selected_rows() == 0) { - return; - } - - TreeModel::iterator i = _snapshot_display.get_selection()->get_selected(); - - std::string snap_name = (*i)[_columns.real_name]; - - if (snap_name.length() == 0) { - return; - } - - if (_session->snap_name() == snap_name) { - return; - } - - _snapshot_display.set_sensitive (false); - ARDOUR_UI::instance()->load_session (_session->path(), string (snap_name)); - _snapshot_display.set_sensitive (true); -} - bool EditorSnapshots::button_press (GdkEventButton* ev) { @@ -115,6 +89,44 @@ EditorSnapshots::button_press (GdkEventButton* ev) popup_context_menu (ev->button, ev->time, row[_columns.real_name]); } return true; + } else if (ev->type == GDK_2BUTTON_PRESS) { + Gtk::TreeModel::Path path; + Gtk::TreeViewColumn* col; + int cx; + int cy; + string snap_name; + _snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy); + Gtk::TreeModel::iterator iter = _snapshot_model->get_iter (path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + snap_name = row[_columns.real_name]; + } + + if (snap_name.length() == 0) { + return false; + } + + if (_session->snap_name() == snap_name) { + return false; + } + + ArdourDialog confirm (_("Load Snapshot?"), true); + Gtk::Label* m = Gtk::manage (new Gtk::Label (string_compose ("%1\n%2", _("Do you want to load this snapshot?"), snap_name))); + confirm.get_vbox()->pack_start (*m, true, true); + confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + confirm.add_button (_("Yes, Load It"), Gtk::RESPONSE_ACCEPT); + confirm.show_all (); + switch (confirm.run()) { + case RESPONSE_ACCEPT: + break; + default: + return false; + } + + _snapshot_display.set_sensitive (false); + ARDOUR_UI::instance()->load_session (_session->path(), string (snap_name)); + _snapshot_display.set_sensitive (true); + return true; } return false; } diff --git a/gtk2_ardour/editor_snapshots.h b/gtk2_ardour/editor_snapshots.h index 5633365c22..bc919977e6 100644 --- a/gtk2_ardour/editor_snapshots.h +++ b/gtk2_ardour/editor_snapshots.h @@ -61,7 +61,6 @@ private: Gtk::Menu _menu; bool button_press (GdkEventButton *); - void selection_changed (); void popup_context_menu (int, int32_t, std::string); void remove (std::string); void rename (std::string);