2 * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3 * Copyright (C) 2005-2015 Tim Mayberry <mojofunk@gmail.com>
4 * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
6 * Copyright (C) 2008-2012 David Robillard <d@drobilla.net>
7 * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
8 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <gtk/gtkaccelmap.h>
30 #include <gtk/gtkuimanager.h>
31 #include <gtk/gtkactiongroup.h>
33 #include <gtkmm/accelmap.h>
34 #include <gtkmm/uimanager.h>
36 #include "pbd/error.h"
37 #include "pbd/file_utils.h"
39 #include "ardour/filesystem_paths.h"
40 #include "ardour/rc_configuration.h"
42 #include "gtkmm2ext/actions.h"
51 using namespace ARDOUR;
53 typedef std::vector<RefPtr<Gtk::Action> > RelatedActions;
55 RelatedActions ActionManager::session_sensitive_actions;
56 RelatedActions ActionManager::write_sensitive_actions;
57 RelatedActions ActionManager::region_list_selection_sensitive_actions;
58 RelatedActions ActionManager::plugin_selection_sensitive_actions;
59 RelatedActions ActionManager::track_selection_sensitive_actions;
60 RelatedActions ActionManager::stripable_selection_sensitive_actions;
61 RelatedActions ActionManager::route_selection_sensitive_actions;
62 RelatedActions ActionManager::bus_selection_sensitive_actions;
63 RelatedActions ActionManager::vca_selection_sensitive_actions;
64 RelatedActions ActionManager::point_selection_sensitive_actions;
65 RelatedActions ActionManager::time_selection_sensitive_actions;
66 RelatedActions ActionManager::line_selection_sensitive_actions;
67 RelatedActions ActionManager::playlist_selection_sensitive_actions;
68 RelatedActions ActionManager::mouse_edit_point_requires_canvas_actions;
69 RelatedActions ActionManager::range_sensitive_actions;
70 RelatedActions ActionManager::engine_sensitive_actions;
71 RelatedActions ActionManager::engine_opposite_sensitive_actions;
72 RelatedActions ActionManager::transport_sensitive_actions;
73 RelatedActions ActionManager::rec_sensitive_actions;
76 ActionManager::load_menus (const string& menus_file)
80 find_file (ardour_config_search_path(), menus_file, ui_file);
85 ui_manager->add_ui_from_file (ui_file);
86 info << string_compose (_("Loading menus from %1"), ui_file) << endmsg;
88 } catch (Glib::MarkupError& err) {
89 error << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endmsg;
90 cerr << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endl;
92 error << string_compose (_("%1 menu definition file not found"), PROGRAM_NAME) << endmsg;
96 cerr << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endl;
97 error << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endmsg;
102 /** Examine the state of a Configuration setting and a toggle action, and toggle the Configuration
103 * setting if its state doesn't match the toggle action.
104 * @param group Action group.
105 * @param action Action name.
106 * @param Method to set the state of the Configuration setting.
107 * @param Method to get the state of the Configuration setting.
110 ActionManager::toggle_config_state (const char* group, const char* action, bool (RCConfiguration::*set)(bool), bool (RCConfiguration::*get)(void) const)
112 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
115 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
118 bool x = (Config->*get)();
120 if (x != tact->get_active()) {
127 /** Examine the state of a Configuration setting and a toggle action, and toggle the Configuration
128 * setting if its state doesn't match the toggle action.
129 * @param group Action group.
130 * @param action Action name.
131 * @param Method to set the state of the Configuration setting.
132 * @param Method to get the state of the Configuration setting.
135 ActionManager::toggle_config_state (const char* group, const char* action, bool (UIConfiguration::*set)(bool), bool (UIConfiguration::*get)(void) const)
137 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
140 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
143 bool x = (UIConfiguration::instance().*get)();
145 if (x != tact->get_active()) {
146 (UIConfiguration::instance().*set) (!x);
153 ActionManager::toggle_config_state_foo (const char* group, const char* action, sigc::slot<bool, bool> set, sigc::slot<bool> get)
155 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
158 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
161 bool const x = get ();
163 if (x != tact->get_active ()) {
171 /** Set the state of a ToggleAction using a particular Configuration get() method
172 * @param group Action group.
173 * @param action Action name.
174 * @param get Method to obtain the state that the ToggleAction should have.
177 ActionManager::map_some_state (const char* group, const char* action, bool (RCConfiguration::*get)() const)
179 Glib::RefPtr<Action> act = ActionManager::get_action (group, action, false);
181 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
185 bool x = (Config->*get)();
187 if (tact->get_active() != x) {
188 tact->set_active (x);
194 /** Set the state of a ToggleAction using a particular Configuration get() method
195 * @param group Action group.
196 * @param action Action name.
197 * @param get Method to obtain the state that the ToggleAction should have.
200 ActionManager::map_some_state (const char* group, const char* action, bool (UIConfiguration::*get)() const)
202 Glib::RefPtr<Action> act = ActionManager::get_action (group, action, false);
204 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
208 bool x = (UIConfiguration::instance().*get)();
210 if (tact->get_active() != x) {
211 tact->set_active (x);
218 ActionManager::map_some_state (const char* group, const char* action, sigc::slot<bool> get)
220 Glib::RefPtr<Action> act = ActionManager::get_action (group, action, false);
222 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
226 bool const x = get ();
228 if (tact->get_active() != x) {
229 tact->set_active (x);