diff --git a/libs/gtkmm2ext/action_model.cc b/libs/gtkmm2ext/action_model.cc index a909a8a837..8341fbb1b7 100644 --- a/libs/gtkmm2ext/action_model.cc +++ b/libs/gtkmm2ext/action_model.cc @@ -21,6 +21,7 @@ #include #include +#include #include "pbd/i18n.h" #include "pbd/strsplit.h" @@ -31,14 +32,16 @@ using namespace std; using namespace Gtk; -const ActionManager::ActionModel& -ActionManager::ActionModel::instance () +namespace ActionManager { + +const ActionModel& +ActionModel::instance () { - static ActionManager::ActionModel am; + static ActionModel am; return am; } -ActionManager::ActionModel::ActionModel () +ActionModel::ActionModel () { _model = TreeStore::create (_columns); _model->clear (); @@ -60,7 +63,7 @@ ActionManager::ActionModel::ActionModel () vector keys; vector > actions; - ActionManager::get_all_actions (paths, labels, tooltips, keys, actions); + get_all_actions (paths, labels, tooltips, keys, actions); vector::iterator k; vector::iterator p; @@ -120,7 +123,7 @@ ActionManager::ActionModel::ActionModel () } bool -ActionManager::ActionModel::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found) const +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]; @@ -134,7 +137,7 @@ ActionManager::ActionModel::find_action_in_model (const TreeModel::iterator& ite } void -ActionManager::ActionModel::build_action_combo (ComboBox& cb, string const& current_action) const +ActionModel::build_action_combo (ComboBox& cb, string const& current_action) const { cb.set_model (_model); cb.pack_start (_columns.name); @@ -146,7 +149,7 @@ ActionManager::ActionModel::build_action_combo (ComboBox& cb, string const& curr TreeModel::iterator iter = _model->children().end(); - _model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &ActionManager::ActionModel::find_action_in_model), current_action, &iter)); + _model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &ActionModel::find_action_in_model), current_action, &iter)); if (iter != _model->children().end()) { cb.set_active (iter); @@ -154,3 +157,42 @@ ActionManager::ActionModel::build_action_combo (ComboBox& cb, string const& curr cb.set_active (0); } } + +void +ActionModel::build_custom_action_combo (ComboBox& cb, const vector >& actions, const string& current_action) const +{ + Glib::RefPtr model (Gtk::ListStore::create (_columns)); + TreeIter rowp; + TreeModel::Row row; + int active_row = -1; + int n; + vector >::const_iterator i; + + rowp = model->append(); + row = *(rowp); + row[_columns.name] = _("Disabled"); + row[_columns.path] = string(); + + if (current_action.empty()) { + active_row = 0; + } + + for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) { + rowp = model->append(); + row = *(rowp); + row[_columns.name] = i->first; + row[_columns.path] = i->second; + if (current_action == i->second) { + active_row = n+1; + } + } + + cb.set_model (model); + cb.pack_start (_columns.name); + + if (active_row >= 0) { + cb.set_active (active_row); + } +} + +} diff --git a/libs/gtkmm2ext/gtkmm2ext/action_model.h b/libs/gtkmm2ext/gtkmm2ext/action_model.h index 4716660b14..c3e993dfb3 100644 --- a/libs/gtkmm2ext/gtkmm2ext/action_model.h +++ b/libs/gtkmm2ext/gtkmm2ext/action_model.h @@ -61,6 +61,9 @@ public: const Columns& columns() const { return _columns; } void build_action_combo (Gtk::ComboBox& cb, std::string const& current_action) const; + void build_custom_action_combo (Gtk::ComboBox& cb, + const std::vector >& actions, + const std::string& current_action) const; private: ActionModel ();