summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext
diff options
context:
space:
mode:
authorJohannes Mueller <github@johannes-mueller.org>2019-04-20 22:12:52 +0200
committerJohannes Mueller <github@johannes-mueller.org>2019-04-20 22:12:52 +0200
commit822f55f4afe5d28bb32fba2e35c4518575c29ae3 (patch)
tree5e7e1305fb1606b02a5b3f7bce1bd1be3baf060c /libs/gtkmm2ext
parent73f8b8d98249f091702f63b0d2f4d96de8dd1e70 (diff)
Provide ActionModel::build_custom_action_combo() for Control Protcols
to consolidate code that's identical in several control protocols.
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r--libs/gtkmm2ext/action_model.cc58
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/action_model.h3
2 files changed, 53 insertions, 8 deletions
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 <vector>
#include <gtkmm/combobox.h>
+#include <gtkmm/liststore.h>
#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<string> keys;
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 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<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);
+ }
+}
+
+}
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<std::pair<std::string,std::string> >& actions,
+ const std::string& current_action) const;
private:
ActionModel ();