ardour
actions.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <cstring>
21 #include <string>
22 #include <list>
23 
24 #include <gtk/gtkaccelmap.h>
25 #include <gtk/gtkuimanager.h>
26 #include <gtk/gtkactiongroup.h>
27 
28 #include <gtkmm/accelmap.h>
29 #include <gtkmm/uimanager.h>
30 
31 #include "pbd/error.h"
32 #include "pbd/file_utils.h"
33 
36 
37 #include "gtkmm2ext/actions.h"
38 
39 #include "ardour_ui.h"
40 #include "actions.h"
41 #include "i18n.h"
42 
43 using namespace std;
44 using namespace Gtk;
45 using namespace Glib;
46 using namespace PBD;
47 using namespace ARDOUR;
48 
49 vector<RefPtr<Gtk::Action> > ActionManager::session_sensitive_actions;
50 vector<RefPtr<Gtk::Action> > ActionManager::write_sensitive_actions;
59 
60 vector<RefPtr<Gtk::Action> > ActionManager::range_sensitive_actions;
61 vector<RefPtr<Gtk::Action> > ActionManager::engine_sensitive_actions;
63 vector<RefPtr<Gtk::Action> > ActionManager::transport_sensitive_actions;
65 
66 static Glib::RefPtr<UIManager> ui_manager;
67 
68 void
70 {
71  ui_manager = UIManager::create ();
72 }
73 
74 void
76 {
77  std::string ui_file;
78 
79  find_file (ardour_config_search_path(), menus_file, ui_file);
80 
81  bool loaded = false;
82 
83  try {
84  ui_manager->add_ui_from_file (ui_file);
85  info << string_compose (_("Loading menus from %1"), ui_file) << endmsg;
86  loaded = true;
87  } catch (Glib::MarkupError& err) {
88  error << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endmsg;
89  cerr << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endl;
90  } catch (...) {
91  error << string_compose (_("%1 menu definition file not found"), PROGRAM_NAME) << endmsg;
92  }
93 
94  if (!loaded) {
95  cerr << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endl;
96  error << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endmsg;
97  exit(1);
98  }
99 }
100 
108 void
109 ActionManager::toggle_config_state (const char* group, const char* action, bool (RCConfiguration::*set)(bool), bool (RCConfiguration::*get)(void) const)
110 {
111  Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
112 
113  if (act) {
114  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
115 
116  if (tact) {
117  bool x = (Config->*get)();
118 
119  if (x != tact->get_active()) {
120  (Config->*set) (!x);
121  }
122  }
123  }
124 }
125 
133 void
134 ActionManager::toggle_config_state (const char* group, const char* action, bool (UIConfiguration::*set)(bool), bool (UIConfiguration::*get)(void) const)
135 {
136  Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
137 
138  if (act) {
139  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
140 
141  if (tact) {
142  bool x = (ARDOUR_UI::config()->*get)();
143 
144  if (x != tact->get_active()) {
145  (ARDOUR_UI::config()->*set) (!x);
146  }
147  }
148  }
149 }
150 
151 void
152 ActionManager::toggle_config_state_foo (const char* group, const char* action, sigc::slot<bool, bool> set, sigc::slot<bool> get)
153 {
154  Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
155 
156  if (act) {
157  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
158 
159  if (tact) {
160  bool const x = get ();
161 
162  if (x != tact->get_active ()) {
163  set (!x);
164  }
165  }
166  }
167 }
168 
169 
175 void
176 ActionManager::map_some_state (const char* group, const char* action, bool (RCConfiguration::*get)() const)
177 {
178  Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
179  if (act) {
180  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
181 
182  if (tact) {
183 
184  bool x = (Config->*get)();
185 
186  if (tact->get_active() != x) {
187  tact->set_active (x);
188  }
189  }
190  }
191 }
192 
198 void
199 ActionManager::map_some_state (const char* group, const char* action, bool (UIConfiguration::*get)() const)
200 {
201  Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
202  if (act) {
203  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
204 
205  if (tact) {
206 
207  bool x = (ARDOUR_UI::config()->*get)();
208 
209  if (tact->get_active() != x) {
210  tact->set_active (x);
211  }
212  }
213  }
214 }
215 
216 void
217 ActionManager::map_some_state (const char* group, const char* action, sigc::slot<bool> get)
218 {
219  Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
220  if (act) {
221  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
222 
223  if (tact) {
224 
225  bool const x = get ();
226 
227  if (tact->get_active() != x) {
228  tact->set_active (x);
229  }
230  }
231  }
232 }
233 
std::vector< Glib::RefPtr< Gtk::Action > > track_selection_sensitive_actions
Definition: actions.cc:53
std::vector< Glib::RefPtr< Gtk::Action > > engine_opposite_sensitive_actions
Definition: actions.cc:62
Definition: ardour_ui.h:130
std::vector< Glib::RefPtr< Gtk::Action > > time_selection_sensitive_actions
Definition: actions.cc:55
std::vector< Glib::RefPtr< Gtk::Action > > engine_sensitive_actions
Definition: actions.cc:61
std::string menus_file
Definition: opts.cc:46
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > get_action(const char *group, const char *name)
Definition: actions.cc:406
void toggle_config_state_foo(const char *group, const char *action, sigc::slot< bool, bool >, sigc::slot< bool >)
Definition: actions.cc:152
Definition: Beats.hpp:239
LIBPBD_API Transmitter error
std::vector< Glib::RefPtr< Gtk::Action > > line_selection_sensitive_actions
Definition: actions.cc:56
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
static Glib::RefPtr< UIManager > ui_manager
Definition: actions.cc:66
std::vector< Glib::RefPtr< Gtk::Action > > range_sensitive_actions
Definition: actions.cc:60
void init()
Definition: actions.cc:69
bool find_file(const Searchpath &search_path, const string &filename, std::string &result)
Definition: file_utils.cc:187
std::vector< Glib::RefPtr< Gtk::Action > > point_selection_sensitive_actions
Definition: actions.cc:54
#define _(Text)
Definition: i18n.h:11
LIBARDOUR_API RCConfiguration * Config
Definition: globals.cc:119
std::vector< Glib::RefPtr< Gtk::Action > > region_list_selection_sensitive_actions
Definition: actions.cc:51
Definition: amp.h:29
std::vector< Glib::RefPtr< Gtk::Action > > write_sensitive_actions
Definition: actions.cc:50
std::vector< Glib::RefPtr< Gtk::Action > > session_sensitive_actions
Definition: actions.cc:49
std::vector< Glib::RefPtr< Gtk::Action > > plugin_selection_sensitive_actions
Definition: actions.cc:52
LIBARDOUR_API PBD::Searchpath ardour_config_search_path()
void map_some_state(const char *group, const char *action, bool(ARDOUR::RCConfiguration::*get)() const)
LIBPBD_API Transmitter info
static UIConfiguration * config()
Definition: ardour_ui.h:188
std::vector< Glib::RefPtr< Gtk::Action > > mouse_edit_point_requires_canvas_actions
Definition: actions.cc:58
std::vector< Glib::RefPtr< Gtk::Action > > edit_point_in_region_sensitive_actions
Definition: actions.cc:64
Definition: debug.h:30
std::vector< Glib::RefPtr< Gtk::Action > > playlist_selection_sensitive_actions
Definition: actions.cc:57
void load_menus(const std::string &menus_file_name)
void toggle_config_state(const char *group, const char *action, bool(UIConfiguration::*set)(bool), bool(UIConfiguration::*get)(void) const)
Definition: actions.cc:134
std::vector< Glib::RefPtr< Gtk::Action > > transport_sensitive_actions
Definition: actions.cc:63
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208