diff options
author | Johannes Mueller <github@johannes-mueller.org> | 2019-04-20 14:12:24 +0200 |
---|---|---|
committer | Johannes Mueller <github@johannes-mueller.org> | 2019-04-20 15:25:32 +0200 |
commit | de876acc8bb8d5dbabdedc05b56110a31383be50 (patch) | |
tree | 5f066b977fa62cb591cbbdd8e8320b8c869c613e /libs/gtkmm2ext | |
parent | 5b7bcec529c0b44cacf61298a0df5e7903e111d9 (diff) |
Provide a function to fill a Gtk::ComboBox with all available actions
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r-- | libs/gtkmm2ext/action_model.cc | 38 | ||||
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/action_model.h | 9 |
2 files changed, 47 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/action_model.cc b/libs/gtkmm2ext/action_model.cc index cc3b62d9a6..a909a8a837 100644 --- a/libs/gtkmm2ext/action_model.cc +++ b/libs/gtkmm2ext/action_model.cc @@ -20,6 +20,8 @@ #include <vector> +#include <gtkmm/combobox.h> + #include "pbd/i18n.h" #include "pbd/strsplit.h" @@ -116,3 +118,39 @@ ActionManager::ActionModel::ActionModel () row[_columns.path] = *p; } } + +bool +ActionManager::ActionModel::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found) const +{ + TreeModel::Row row = *iter; + string path = row[_columns.path]; + + if (path == action_path) { + *found = iter; + return true; + } + + return false; +} + +void +ActionManager::ActionModel::build_action_combo (ComboBox& cb, string const& current_action) const +{ + cb.set_model (_model); + cb.pack_start (_columns.name); + + if (current_action.empty()) { + cb.set_active (0); /* "disabled" */ + return; + } + + TreeModel::iterator iter = _model->children().end(); + + _model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &ActionManager::ActionModel::find_action_in_model), current_action, &iter)); + + if (iter != _model->children().end()) { + cb.set_active (iter); + } else { + cb.set_active (0); + } +} diff --git a/libs/gtkmm2ext/gtkmm2ext/action_model.h b/libs/gtkmm2ext/gtkmm2ext/action_model.h index b269499ecc..4716660b14 100644 --- a/libs/gtkmm2ext/gtkmm2ext/action_model.h +++ b/libs/gtkmm2ext/gtkmm2ext/action_model.h @@ -25,6 +25,11 @@ #include "gtkmm2ext/visibility.h" +namespace Gtk +{ +class ComboBox; +} + /* The singleton ActionModel provides a Gtk::Treestore of all actions known to ardour. @@ -55,9 +60,13 @@ public: const Columns& columns() const { return _columns; } + void build_action_combo (Gtk::ComboBox& cb, std::string const& current_action) const; + private: ActionModel (); + bool find_action_in_model (const Gtk::TreeModel::iterator& iter, std::string const & action_path, Gtk::TreeModel::iterator* found) const; + const Columns _columns; Glib::RefPtr<Gtk::TreeStore> _model; }; |