Provide ActionModel::build_custom_action_combo() for Control Protcols
to consolidate code that's identical in several control protocols.
This commit is contained in:
parent
73f8b8d982
commit
822f55f4af
|
@ -21,6 +21,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <gtkmm/combobox.h>
|
#include <gtkmm/combobox.h>
|
||||||
|
#include <gtkmm/liststore.h>
|
||||||
|
|
||||||
#include "pbd/i18n.h"
|
#include "pbd/i18n.h"
|
||||||
#include "pbd/strsplit.h"
|
#include "pbd/strsplit.h"
|
||||||
|
@ -31,14 +32,16 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Gtk;
|
using namespace Gtk;
|
||||||
|
|
||||||
const ActionManager::ActionModel&
|
namespace ActionManager {
|
||||||
ActionManager::ActionModel::instance ()
|
|
||||||
|
const ActionModel&
|
||||||
|
ActionModel::instance ()
|
||||||
{
|
{
|
||||||
static ActionManager::ActionModel am;
|
static ActionModel am;
|
||||||
return am;
|
return am;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionManager::ActionModel::ActionModel ()
|
ActionModel::ActionModel ()
|
||||||
{
|
{
|
||||||
_model = TreeStore::create (_columns);
|
_model = TreeStore::create (_columns);
|
||||||
_model->clear ();
|
_model->clear ();
|
||||||
|
@ -60,7 +63,7 @@ ActionManager::ActionModel::ActionModel ()
|
||||||
vector<string> keys;
|
vector<string> keys;
|
||||||
vector<Glib::RefPtr<Gtk::Action> > actions;
|
vector<Glib::RefPtr<Gtk::Action> > actions;
|
||||||
|
|
||||||
ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
|
get_all_actions (paths, labels, tooltips, keys, actions);
|
||||||
|
|
||||||
vector<string>::iterator k;
|
vector<string>::iterator k;
|
||||||
vector<string>::iterator p;
|
vector<string>::iterator p;
|
||||||
|
@ -120,7 +123,7 @@ ActionManager::ActionModel::ActionModel ()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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;
|
TreeModel::Row row = *iter;
|
||||||
string path = row[_columns.path];
|
string path = row[_columns.path];
|
||||||
|
@ -134,7 +137,7 @@ ActionManager::ActionModel::find_action_in_model (const TreeModel::iterator& ite
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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.set_model (_model);
|
||||||
cb.pack_start (_columns.name);
|
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();
|
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()) {
|
if (iter != _model->children().end()) {
|
||||||
cb.set_active (iter);
|
cb.set_active (iter);
|
||||||
|
@ -154,3 +157,42 @@ ActionManager::ActionModel::build_action_combo (ComboBox& cb, string const& curr
|
||||||
cb.set_active (0);
|
cb.set_active (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ActionModel::build_custom_action_combo (ComboBox& cb, const vector<pair<string,string> >& actions, const string& current_action) const
|
||||||
|
{
|
||||||
|
Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (_columns));
|
||||||
|
TreeIter rowp;
|
||||||
|
TreeModel::Row row;
|
||||||
|
int active_row = -1;
|
||||||
|
int n;
|
||||||
|
vector<pair<string,string> >::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ public:
|
||||||
const Columns& columns() const { return _columns; }
|
const Columns& columns() const { return _columns; }
|
||||||
|
|
||||||
void build_action_combo (Gtk::ComboBox& cb, std::string const& current_action) const;
|
void build_action_combo (Gtk::ComboBox& cb, std::string const& current_action) const;
|
||||||
|
void build_custom_action_combo (Gtk::ComboBox& cb,
|
||||||
|
const std::vector<std::pair<std::string,std::string> >& actions,
|
||||||
|
const std::string& current_action) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ActionModel ();
|
ActionModel ();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user