From 291575683cb87713cc7a5856a96c5fdd69b9a52c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 22 Jul 2015 21:14:08 -0400 Subject: [PATCH] dynamically update menus/actions controlling tabbable show/hide/attach/detach operations --- gtk2_ardour/ardour_ui.h | 2 + gtk2_ardour/ardour_ui2.cc | 1 + gtk2_ardour/ardour_ui_dialogs.cc | 63 ++++++++++++++++++++++++++++++++ gtk2_ardour/ardour_ui_ed.cc | 1 + gtk2_ardour/ardour_ui_mixer.cc | 1 + 5 files changed, 68 insertions(+) diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 13627e4af1..0c11233c15 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -379,6 +379,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr void detach_tabbable (Gtkmm2ext::Tabbable*); void attach_tabbable (Gtkmm2ext::Tabbable*); + void tabbable_state_change (Gtkmm2ext::Tabbable&); + void toggle_meterbridge (); int setup_windows (); diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index c895262cb6..db0f28a566 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -100,6 +100,7 @@ ARDOUR_UI::setup_windows () rc_option_editor = new RCOptionEditor; rc_option_editor->add_to_notebook (_tabs, _("Preferences")); rc_option_editor->contents().show_all (); + rc_option_editor->StateChange.connect (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_state_change)); /* all other dialogs are created conditionally */ diff --git a/gtk2_ardour/ardour_ui_dialogs.cc b/gtk2_ardour/ardour_ui_dialogs.cc index 0d8c8a9c27..08174a62bc 100644 --- a/gtk2_ardour/ardour_ui_dialogs.cc +++ b/gtk2_ardour/ardour_ui_dialogs.cc @@ -23,6 +23,10 @@ This is to cut down on the compile times. It also helps with my sanity. */ +#include + +#include "pbd/convert.h" + #include "ardour/audioengine.h" #include "ardour/automation_watch.h" #include "ardour/control_protocol_manager.h" @@ -376,6 +380,65 @@ ARDOUR_UI::detach_tabbable (Tabbable* t) t->detach (); } +void +ARDOUR_UI::tabbable_state_change (Tabbable& t) +{ + std::vector insensitive_action_names; + std::vector sensitive_action_names; + Glib::RefPtr action; + std::string downcased_name = downcase (t.name()); + + std::cerr << t.name() << " changed state\n"; + + if (t.tabbed()) { + + std::cerr << "tabbed\n"; + + insensitive_action_names.push_back (string_compose ("attach-%1", downcased_name)); + insensitive_action_names.push_back (string_compose ("show-%1", downcased_name)); + sensitive_action_names.push_back (string_compose ("detach-%1", downcased_name)); + sensitive_action_names.push_back (string_compose ("hide-%1", downcased_name)); + + + } else if (t.window_visible()) { + + std::cerr << "windowed\n"; + + insensitive_action_names.push_back (string_compose ("detach-%1", downcased_name)); + insensitive_action_names.push_back (string_compose ("show-%1", downcased_name)); + sensitive_action_names.push_back (string_compose ("attach-%1", downcased_name)); + sensitive_action_names.push_back (string_compose ("hide-%1", downcased_name)); + + } else { + + std::cerr << "invisible\n"; + + /* not currently visible. allow user to retab it or just make + * it visible. + */ + + insensitive_action_names.push_back (string_compose ("detach-%1", downcased_name)); + insensitive_action_names.push_back (string_compose ("hide-%1", downcased_name)); + sensitive_action_names.push_back (string_compose ("show-%1", downcased_name)); + sensitive_action_names.push_back (string_compose ("attach-%1", downcased_name)); + } + + + for (std::vector::iterator s = insensitive_action_names.begin(); s != insensitive_action_names.end(); ++s) { + action = ActionManager::get_action (X_("Common"), (*s).c_str()); + if (action) { + action->set_sensitive (false); + } + } + + for (std::vector::iterator s = sensitive_action_names.begin(); s != sensitive_action_names.end(); ++s) { + action = ActionManager::get_action (X_("Common"), (*s).c_str()); + if (action) { + action->set_sensitive (true); + } + } +} + void ARDOUR_UI::toggle_meterbridge () { diff --git a/gtk2_ardour/ardour_ui_ed.cc b/gtk2_ardour/ardour_ui_ed.cc index 18689a23c9..442ea1d97d 100644 --- a/gtk2_ardour/ardour_ui_ed.cc +++ b/gtk2_ardour/ardour_ui_ed.cc @@ -79,6 +79,7 @@ ARDOUR_UI::create_editor () { try { editor = new Editor (); + editor->StateChange.connect (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_state_change)); } catch (failed_constructor& err) { diff --git a/gtk2_ardour/ardour_ui_mixer.cc b/gtk2_ardour/ardour_ui_mixer.cc index 773a2ed14f..6279f4c789 100644 --- a/gtk2_ardour/ardour_ui_mixer.cc +++ b/gtk2_ardour/ardour_ui_mixer.cc @@ -41,6 +41,7 @@ ARDOUR_UI::create_mixer () { try { mixer = Mixer_UI::instance (); + mixer->StateChange.connect (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_state_change)); } catch (failed_constructor& err) {