2 * Copyright (C) 2019 Johannes Mueller <github@johannes-mueller.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <gtkmm/combobox.h>
22 #include <gtkmm/liststore.h>
25 #include "pbd/strsplit.h"
27 #include "gtkmm2ext/actions.h"
28 #include "gtkmm2ext/action_model.h"
33 namespace ActionManager {
36 ActionModel::instance ()
38 static ActionModel am;
42 ActionModel::ActionModel ()
44 _model = TreeStore::create (_columns);
47 typedef std::map<string,TreeIter> NodeMap;
52 TreeModel::Row parent;
54 rowp = _model->append ();
56 parent[_columns.name] = _("Disabled");
59 vector<string> labels;
60 vector<string> tooltips;
62 vector<Glib::RefPtr<Gtk::Action> > actions;
64 get_all_actions (paths, labels, tooltips, keys, actions);
66 vector<string>::iterator k;
67 vector<string>::iterator p;
68 vector<string>::iterator t;
69 vector<string>::iterator l;
71 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
76 split (*p, parts, '/');
82 //kinda kludgy way to avoid displaying menu items as mappable
83 if ( parts[0] == _("Main_menu") )
85 if ( parts[0] == _("JACK") )
87 if ( parts[0] == _("redirectmenu") )
89 if ( parts[0] == _("Editor_menus") )
91 if ( parts[0] == _("RegionList") )
93 if ( parts[0] == _("ProcessorMenu") )
96 if ((r = nodes.find (parts[0])) == nodes.end()) {
97 /* top level is missing */
100 TreeModel::Row parent;
101 rowp = _model->append();
102 nodes[parts[0]] = rowp;
104 parent[_columns.name] = parts[0];
106 row = *(_model->append (parent.children()));
108 row = *(_model->append ((*r->second)->children()));
111 /* add this action */
114 row[_columns.name] = *t;
116 row[_columns.name] = *l;
119 row[_columns.path] = *p;
124 ActionModel::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found) const
126 TreeModel::Row row = *iter;
127 string path = row[_columns.path];
129 if (path == action_path) {
138 ActionModel::build_action_combo (ComboBox& cb, string const& current_action) const
140 cb.set_model (_model);
141 cb.pack_start (_columns.name);
143 if (current_action.empty()) {
144 cb.set_active (0); /* "disabled" */
148 TreeModel::iterator iter = _model->children().end();
150 _model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &ActionModel::find_action_in_model), current_action, &iter));
152 if (iter != _model->children().end()) {
153 cb.set_active (iter);
160 ActionModel::build_custom_action_combo (ComboBox& cb, const vector<pair<string,string> >& actions, const string& current_action) const
162 Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (_columns));
167 vector<pair<string,string> >::const_iterator i;
169 rowp = model->append();
171 row[_columns.name] = _("Disabled");
172 row[_columns.path] = string();
174 if (current_action.empty()) {
178 for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
179 rowp = model->append();
181 row[_columns.name] = i->first;
182 row[_columns.path] = i->second;
183 if (current_action == i->second) {
188 cb.set_model (model);
189 cb.pack_start (_columns.name);
191 if (active_row >= 0) {
192 cb.set_active (active_row);