Provide a function to fill a Gtk::ComboBox with all available actions

This commit is contained in:
Johannes Mueller 2019-04-20 14:12:24 +02:00
parent 5b7bcec529
commit de876acc8b
2 changed files with 47 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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;
};