From 86ecca8c765e4a06ffaaf2faf9c9b56922c1ba21 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 30 Jun 2024 08:16:07 -0600 Subject: [PATCH] make undo/redo action sensitivity work with multiple EditingContexts --- gtk2_ardour/cue_editor.cc | 8 ++++++++ gtk2_ardour/cue_editor.h | 4 +++- gtk2_ardour/editing_context.cc | 32 ++++++++++++++++++++++++++++++++ gtk2_ardour/editing_context.h | 5 ++++- gtk2_ardour/editor.cc | 27 +++------------------------ 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/gtk2_ardour/cue_editor.cc b/gtk2_ardour/cue_editor.cc index 383ad8dda6..60a8108617 100644 --- a/gtk2_ardour/cue_editor.cc +++ b/gtk2_ardour/cue_editor.cc @@ -1,5 +1,6 @@ #include "cue_editor.h" #include "editor_drag.h" +#include "gui_thread.h" #include "pbd/i18n.h" @@ -7,6 +8,7 @@ CueEditor::CueEditor (std::string const & name) : EditingContext (name) , HistoryOwner (X_("cue-editor")) { + _history.Changed.connect (history_connection, invalidator (*this), boost::bind (&CueEditor::history_changed, this), gui_context()); } CueEditor::~CueEditor () @@ -239,3 +241,9 @@ CueEditor::do_redo (uint32_t n) _history.redo (n); } +void +CueEditor::history_changed () +{ + update_undo_redo_actions (_history); +} + diff --git a/gtk2_ardour/cue_editor.h b/gtk2_ardour/cue_editor.h index 0bc1471874..b0510a5959 100644 --- a/gtk2_ardour/cue_editor.h +++ b/gtk2_ardour/cue_editor.h @@ -24,7 +24,7 @@ #include "editing.h" #include "editing_context.h" -class CueEditor : public EditingContext, public PBD::HistoryOwner +class CueEditor : public EditingContext, public PBD::HistoryOwner, public sigc::trackable { public: CueEditor (std::string const & name); @@ -67,6 +67,8 @@ class CueEditor : public EditingContext, public PBD::HistoryOwner void redo_selection_op (); PBD::HistoryOwner& history() { return *this; } + void history_changed (); + PBD::ScopedConnection history_connection; void add_command (PBD::Command * cmd) { HistoryOwner::add_command (cmd); } void begin_reversible_command (std::string cmd_name) { HistoryOwner::begin_reversible_command (cmd_name); } diff --git a/gtk2_ardour/editing_context.cc b/gtk2_ardour/editing_context.cc index de35d337ab..d6b9a61cc6 100644 --- a/gtk2_ardour/editing_context.cc +++ b/gtk2_ardour/editing_context.cc @@ -1992,13 +1992,18 @@ EditingContext::current_editing_context() void EditingContext::push_editing_context (EditingContext* ec) { + assert (ec); ec_stack.push (ec); + ec->history_changed (); } void EditingContext::pop_editing_context () { ec_stack.pop (); + if (!ec_stack.empty()) { + ec_stack.top()->history_changed (); + } } double @@ -2490,3 +2495,30 @@ EditingContext::radio_reg_sens (RefPtr action_group, RadioAction::G ActionManager::session_sensitive_actions.push_back (act); } +void +EditingContext::update_undo_redo_actions (PBD::UndoHistory const & history) +{ + string label; + + if (undo_action) { + if (history.undo_depth() == 0) { + label = S_("Command|Undo"); + undo_action->set_sensitive(false); + } else { + label = string_compose(S_("Command|Undo (%1)"), history.next_undo()); + undo_action->set_sensitive(true); + } + undo_action->property_label() = label; + } + + if (redo_action) { + if (history.redo_depth() == 0) { + label = _("Redo"); + redo_action->set_sensitive (false); + } else { + label = string_compose(_("Redo (%1)"), history.next_redo()); + redo_action->set_sensitive (true); + } + redo_action->property_label() = label; + } +} diff --git a/gtk2_ardour/editing_context.h b/gtk2_ardour/editing_context.h index 3be030f6bc..2b5a86e16f 100644 --- a/gtk2_ardour/editing_context.h +++ b/gtk2_ardour/editing_context.h @@ -75,7 +75,7 @@ class SelectionMemento; class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider { -public: + public: /** Context for mouse entry (stored in a stack). */ struct EnterContext { ItemType item_type; @@ -398,6 +398,9 @@ public: */ void redo (uint32_t n = 1) { do_redo (n); } + virtual void history_changed() = 0; + static void update_undo_redo_actions (PBD::UndoHistory const &); + protected: std::string _name; diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index ca56f62705..b5927a18dd 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1319,9 +1319,10 @@ Editor::set_session (Session *t) _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::location_gone, this, _1), gui_context()); _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::refresh_location_display, this), gui_context()); _session->auto_loop_location_changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::loop_location_changed, this, _1), gui_context ()); - _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context()); Location::flags_changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_section_rects, this), gui_context ()); + _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context()); + _playhead_cursor->track_canvas_item().reparent ((ArdourCanvas::Item*) get_cursor_scroll_group()); _playhead_cursor->show (); @@ -3063,29 +3064,7 @@ Editor::history_changed () return; } - string label; - - if (undo_action) { - if (_session->undo_depth() == 0) { - label = S_("Command|Undo"); - undo_action->set_sensitive(false); - } else { - label = string_compose(S_("Command|Undo (%1)"), _session->next_undo()); - undo_action->set_sensitive(true); - } - undo_action->property_label() = label; - } - - if (redo_action) { - if (_session->redo_depth() == 0) { - label = _("Redo"); - redo_action->set_sensitive (false); - } else { - label = string_compose(_("Redo (%1)"), _session->next_redo()); - redo_action->set_sensitive (true); - } - redo_action->property_label() = label; - } + update_undo_redo_actions (_session->undo_redo()); } void