From 94dbcaa7e294267c9d05c75dedce4f5393cee1e8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 14 May 2025 11:37:01 -0600 Subject: [PATCH] provide a new EditingContext/Editor method to set the cursor appropriately for section selections --- gtk2_ardour/editing_context.h | 1 + gtk2_ardour/editor.h | 1 + gtk2_ardour/editor_mouse.cc | 41 ++++++++++++++++++++++++++++++++++ gtk2_ardour/editor_sections.cc | 37 +----------------------------- 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/gtk2_ardour/editing_context.h b/gtk2_ardour/editing_context.h index 41c8d5ea14..7bffb20403 100644 --- a/gtk2_ardour/editing_context.h +++ b/gtk2_ardour/editing_context.h @@ -362,6 +362,7 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider, */ Editing::MouseMode current_mouse_mode () const { return mouse_mode; } virtual Editing::MouseMode effective_mouse_mode () const { return mouse_mode; } + virtual void use_appropriate_mouse_mode_for_sections () {} /** @return Whether the current mouse mode is an "internal" editing mode. */ virtual bool internal_editing() const = 0; diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index fd3f66108c..110087bb24 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -572,6 +572,7 @@ private: void on_samples_per_pixel_changed (); Editing::MouseMode effective_mouse_mode () const; + void use_appropriate_mouse_mode_for_sections (); Editing::MarkerClickBehavior marker_click_behavior; diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 82320c4ffd..ff776b8bd5 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2355,6 +2355,47 @@ Editor::effective_mouse_mode () const return mouse_mode; } +void +Editor::use_appropriate_mouse_mode_for_sections () +{ + Glib::RefPtr tact; + + switch (current_mouse_mode ()) { + case Editing::MouseRange: + /* OK, no need to change mouse mode */ + break; + case Editing::MouseObject: + /* "object-range" mode is not a distinct mouse mode, so + we cannot use get_mouse_mode_action() here + */ + tact = ActionManager::get_toggle_action (X_("Editor"), "set-mouse-mode-object-range"); + if (!tact) { + /* missing action */ + fatal << X_("programming error: missing mouse-mode-object-range action") << endmsg; + /*NOTREACHED*/ + break; + } + if (tact->get_active()) { + /* smart mode; OK, leave things as they are */ + break; + } + /*fallthrough*/ + default: + /* switch to range mode */ + Glib::RefPtr ract = Glib::RefPtr::cast_static (get_mouse_mode_action (Editing::MouseRange)); + if (!ract) { + /* missing action */ + fatal << X_("programming error: missing mouse-mode-range action") << endmsg; + /*NOTREACHED*/ + break; + } + if (ract) { + ract->set_active (true); + } + break; + } +} + void Editor::remove_midi_note (ArdourCanvas::Item* item, GdkEvent *) { diff --git a/gtk2_ardour/editor_sections.cc b/gtk2_ardour/editor_sections.cc index 3e88d990d8..59f7d46777 100644 --- a/gtk2_ardour/editor_sections.cc +++ b/gtk2_ardour/editor_sections.cc @@ -274,47 +274,12 @@ EditorSections::selection_changed () return; } Gtk::TreeModel::Row row = *_model->get_iter (*rows.begin ()); - Glib::RefPtr tact; timepos_t start = row[_columns.start]; timepos_t end = row[_columns.end]; _selection_change.block (); - switch (PublicEditor::instance ().current_mouse_mode ()) { - case Editing::MouseRange: - /* OK */ - break; - case Editing::MouseObject: - /* "object-range" mode is not a distinct mouse mode, so - we cannot use get_mouse_mode_action() here - */ - std::cerr << "A\n"; - tact = ActionManager::get_toggle_action (X_("Editor"), "set-mouse-mode-object-range"); - if (!tact) { - /* missing action */ - fatal << X_("programming error: missing mouse-mode-object-range action") << endmsg; - /*NOTREACHED*/ - break; - } - if (tact->get_active()) { - /* smart mode; OK */ - break; - } - /*fallthrough*/ - default: - std::cerr << "B\n"; - Glib::RefPtr ract = ActionManager::get_radio_action (X_("Editor"), X_("set-mouse-mode-range")); - if (!ract) { - /* missing action */ - fatal << X_("programming error: missing mouse-mode-range action") << endmsg; - /*NOTREACHED*/ - break; - } - if (ract) { - ract->set_active (true); - } - break; - } + editing_context.use_appropriate_mouse_mode_for_sections (); Selection& s (editing_context.get_selection ()); s.clear ();