Add API to set select item from ArdourDropdown

This fixes an issue with scroll-wheel control which uses `get_active()`.
It work around an issue with gtkmm:

 const MenuItem* get_active () const
 void set_active (guint index)

and MenuList::activate_item() not emitting activate_item().
This commit is contained in:
Robin Gareus
2019-10-20 21:21:57 +02:00
parent 20daca9290
commit 88fc226107
2 changed files with 18 additions and 1 deletions

View File

@@ -80,6 +80,22 @@ ArdourDropdown::on_button_press_event (GdkEventButton* ev)
return true;
}
void
ArdourDropdown::set_active (std::string const& text)
{
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) {
_menu.set_active(c);
_menu.activate_item(*i);
break;
}
}
set_text (text);
}
bool
ArdourDropdown::on_scroll_event (GdkEventScroll* ev)
{

View File

@@ -51,9 +51,10 @@ public:
Gtk::Menu_Helpers::MenuList& items () { return _menu.items (); }
void append_text_item (std::string const& text);
void set_active (std::string const& text);
protected:
void default_text_handler (std::string const& text);
void default_text_handler (std::string const&);
private:
Gtk::Menu _menu;