2 Copyright (C) 2009-2013 Paul Davis
3 Author: Johannes Mueller
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <gtkmm/combobox.h>
26 #include "pbd/strsplit.h"
28 #include "gtkmm2ext/actions.h"
29 #include "gtkmm2ext/action_model.h"
34 const ActionManager::ActionModel&
35 ActionManager::ActionModel::instance ()
37 static ActionManager::ActionModel am;
41 ActionManager::ActionModel::ActionModel ()
43 _model = TreeStore::create (_columns);
46 typedef std::map<string,TreeIter> NodeMap;
51 TreeModel::Row parent;
53 rowp = _model->append ();
55 parent[_columns.name] = _("Disabled");
58 vector<string> labels;
59 vector<string> tooltips;
61 vector<Glib::RefPtr<Gtk::Action> > actions;
63 ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
65 vector<string>::iterator k;
66 vector<string>::iterator p;
67 vector<string>::iterator t;
68 vector<string>::iterator l;
70 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
75 split (*p, parts, '/');
81 //kinda kludgy way to avoid displaying menu items as mappable
82 if ( parts[0] == _("Main_menu") )
84 if ( parts[0] == _("JACK") )
86 if ( parts[0] == _("redirectmenu") )
88 if ( parts[0] == _("Editor_menus") )
90 if ( parts[0] == _("RegionList") )
92 if ( parts[0] == _("ProcessorMenu") )
95 if ((r = nodes.find (parts[0])) == nodes.end()) {
96 /* top level is missing */
99 TreeModel::Row parent;
100 rowp = _model->append();
101 nodes[parts[0]] = rowp;
103 parent[_columns.name] = parts[0];
105 row = *(_model->append (parent.children()));
107 row = *(_model->append ((*r->second)->children()));
110 /* add this action */
113 row[_columns.name] = *t;
115 row[_columns.name] = *l;
118 row[_columns.path] = *p;
123 ActionManager::ActionModel::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found) const
125 TreeModel::Row row = *iter;
126 string path = row[_columns.path];
128 if (path == action_path) {
137 ActionManager::ActionModel::build_action_combo (ComboBox& cb, string const& current_action) const
139 cb.set_model (_model);
140 cb.pack_start (_columns.name);
142 if (current_action.empty()) {
143 cb.set_active (0); /* "disabled" */
147 TreeModel::iterator iter = _model->children().end();
149 _model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &ActionManager::ActionModel::find_action_in_model), current_action, &iter));
151 if (iter != _model->children().end()) {
152 cb.set_active (iter);