2 Copyright (C) 2005 Paul Davis
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <gtk/gtkaccelmap.h>
25 #include <gtk/gtkuimanager.h>
26 #include <gtk/gtkactiongroup.h>
28 #include <gtkmm/accelmap.h>
29 #include <gtkmm/uimanager.h>
31 #include "pbd/error.h"
32 #include "pbd/file_utils.h"
34 #include "ardour/filesystem_paths.h"
35 #include "ardour/rc_configuration.h"
37 #include "gtkmm2ext/actions.h"
46 using namespace ARDOUR;
48 vector<RefPtr<Gtk::Action> > ActionManager::session_sensitive_actions;
49 vector<RefPtr<Gtk::Action> > ActionManager::write_sensitive_actions;
50 vector<RefPtr<Gtk::Action> > ActionManager::region_list_selection_sensitive_actions;
51 vector<RefPtr<Gtk::Action> > ActionManager::track_selection_sensitive_actions;
52 vector<RefPtr<Gtk::Action> > ActionManager::point_selection_sensitive_actions;
53 vector<RefPtr<Gtk::Action> > ActionManager::time_selection_sensitive_actions;
54 vector<RefPtr<Gtk::Action> > ActionManager::line_selection_sensitive_actions;
55 vector<RefPtr<Gtk::Action> > ActionManager::playlist_selection_sensitive_actions;
56 vector<RefPtr<Gtk::Action> > ActionManager::mouse_edit_point_requires_canvas_actions;
58 vector<RefPtr<Gtk::Action> > ActionManager::range_sensitive_actions;
59 vector<RefPtr<Gtk::Action> > ActionManager::engine_sensitive_actions;
60 vector<RefPtr<Gtk::Action> > ActionManager::engine_opposite_sensitive_actions;
61 vector<RefPtr<Gtk::Action> > ActionManager::transport_sensitive_actions;
62 vector<RefPtr<Gtk::Action> > ActionManager::edit_point_in_region_sensitive_actions;
64 static Glib::RefPtr<UIManager> ui_manager;
67 ActionManager::init ()
69 ui_manager = UIManager::create ();
73 ActionManager::load_menus (const string& menus_file)
77 find_file (ardour_config_search_path(), menus_file, ui_file);
82 ui_manager->add_ui_from_file (ui_file);
83 info << string_compose (_("Loading menus from %1"), ui_file) << endmsg;
85 } catch (Glib::MarkupError& err) {
86 error << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endmsg;
87 cerr << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endl;
89 error << string_compose (_("%1 menu definition file not found"), PROGRAM_NAME) << endmsg;
93 cerr << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endl;
94 error << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endmsg;
99 /** Examine the state of a Configuration setting and a toggle action, and toggle the Configuration
100 * setting if its state doesn't match the toggle action.
101 * @param group Action group.
102 * @param action Action name.
103 * @param Method to set the state of the Configuration setting.
104 * @param Method to get the state of the Configuration setting.
107 ActionManager::toggle_config_state (const char* group, const char* action, bool (RCConfiguration::*set)(bool), bool (RCConfiguration::*get)(void) const)
109 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
112 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
115 bool x = (Config->*get)();
117 if (x != tact->get_active()) {
124 /** Examine the state of a Configuration setting and a toggle action, and toggle the Configuration
125 * setting if its state doesn't match the toggle action.
126 * @param group Action group.
127 * @param action Action name.
128 * @param Method to set the state of the Configuration setting.
129 * @param Method to get the state of the Configuration setting.
132 ActionManager::toggle_config_state (const char* group, const char* action, bool (UIConfiguration::*set)(bool), bool (UIConfiguration::*get)(void) const)
134 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
137 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
140 bool x = (UIConfiguration::instance().*get)();
142 if (x != tact->get_active()) {
143 (UIConfiguration::instance().*set) (!x);
150 ActionManager::toggle_config_state_foo (const char* group, const char* action, sigc::slot<bool, bool> set, sigc::slot<bool> get)
152 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
155 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
158 bool const x = get ();
160 if (x != tact->get_active ()) {
168 /** Set the state of a ToggleAction using a particular Configuration get() method
169 * @param group Action group.
170 * @param action Action name.
171 * @param get Method to obtain the state that the ToggleAction should have.
174 ActionManager::map_some_state (const char* group, const char* action, bool (RCConfiguration::*get)() const)
176 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
178 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
182 bool x = (Config->*get)();
184 if (tact->get_active() != x) {
185 tact->set_active (x);
191 /** Set the state of a ToggleAction using a particular Configuration get() method
192 * @param group Action group.
193 * @param action Action name.
194 * @param get Method to obtain the state that the ToggleAction should have.
197 ActionManager::map_some_state (const char* group, const char* action, bool (UIConfiguration::*get)() const)
199 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
201 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
205 bool x = (UIConfiguration::instance().*get)();
207 if (tact->get_active() != x) {
208 tact->set_active (x);
215 ActionManager::map_some_state (const char* group, const char* action, sigc::slot<bool> get)
217 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
219 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
223 bool const x = get ();
225 if (tact->get_active() != x) {
226 tact->set_active (x);