diff --git a/libs/widgets/ardour_dropdown.cc b/libs/widgets/ardour_dropdown.cc index d2f2d8226b..732a064bfd 100644 --- a/libs/widgets/ardour_dropdown.cc +++ b/libs/widgets/ardour_dropdown.cc @@ -82,20 +82,23 @@ ArdourDropdown::on_button_press_event (GdkEventButton* ev) void ArdourDropdown::set_active (std::string const& text) { - const MenuItem* current_active = _menu.get_active(); - if (current_active && current_active->get_label() == text) { + LblMenuItem const* current_active = dynamic_cast (_menu.get_active ()); + if (current_active && current_active->label() == text) { set_text (text); return; } using namespace Menu_Helpers; - const MenuList& items = _menu.items (); int c = 0; - for (MenuList::const_iterator i = items.begin(); i != items.end(); ++i, ++c) { - if (i->get_label() == text) { + for (auto& i : _menu.items()) { + LblMenuItem const* m = dynamic_cast (&i); + if ((m && (m->label() == text || m->menutext() == text)) + || + (!m && i.get_label() == text)) { _menu.set_active (c); - _menu.activate_item (*i); + _menu.activate_item (i); break; } + ++c; } set_text (text); StateChanged (); /* EMIT SIGNAL */ @@ -206,11 +209,11 @@ ArdourDropdown::default_text_handler (std::string const& text) { void ArdourDropdown::append (Glib::RefPtr action) { - _menu.items().push_back (Menu_Helpers::MenuElem (action->get_short_label(), sigc::mem_fun (action.get(), &Action::activate))); + _menu.items().push_back (LblMenuElement (action)); } void ArdourDropdown::append (Gtk::Menu& submenu, Glib::RefPtr action) { - submenu.items().push_back (Menu_Helpers::MenuElem (action->get_short_label(), sigc::mem_fun (action.get(), &Action::activate))); + submenu.items().push_back (LblMenuElement (action)); } diff --git a/libs/widgets/widgets/ardour_dropdown.h b/libs/widgets/widgets/ardour_dropdown.h index 8cf573cc5c..6c9abbe0bd 100644 --- a/libs/widgets/widgets/ardour_dropdown.h +++ b/libs/widgets/widgets/ardour_dropdown.h @@ -61,6 +61,43 @@ protected: void default_text_handler (std::string const&); private: + class LblMenuItem : public Gtk::MenuItem + { + public: + LblMenuItem (std::string const& label, std::string const& menutext) + : Gtk::MenuItem (menutext, false) + , _label (label) + { + } + + std::string label () const + { + return _label; + } + + std::string menutext () const + { + return get_label (); + } + + private: + std::string _label; + }; + + class LblMenuElement : public Gtk::Menu_Helpers::MenuElem + { + public: + LblMenuElement (Glib::RefPtr action) + : Gtk::Menu_Helpers::MenuElem ("") + { + LblMenuItem* mmi = manage (new LblMenuItem (action->get_short_label(), action->get_label())); + child_->unreference (); + set_child (mmi); + child_->signal_activate ().connect (sigc::mem_fun (action.get(), &Gtk::Action::activate)); + child_->show (); + } + }; + Gtk::Menu _menu; bool _scrolling_disabled;