27 #include <boost/shared_ptr.hpp>
29 #include <gtk/gtkaccelmap.h>
30 #include <gtk/gtkuimanager.h>
31 #include <gtk/gtkactiongroup.h>
34 #include <gtkmm/accelmap.h>
35 #include <gtkmm/uimanager.h>
37 #include <glibmm/miscutils.h>
62 act = Action::create (name, label);
73 act = Action::create (name, label);
85 act = RadioAction::create (rgroup, name, label);
93 RefPtr<ActionGroup> group, RadioAction::Group& rgroup,
string const & name,
string const & label,
string const & tooltip, slot<void> sl
98 act = RadioAction::create (rgroup, name, label, tooltip);
109 act = ToggleAction::create (name, label);
110 group->add (act, sl);
120 act = ToggleAction::create (name, label, tooltip);
121 group->add (act, sl);
130 bool known = gtk_accel_map_lookup_entry (accel_path.c_str(), &gkey);
133 key = AccelKey (gkey.accel_key, Gdk::ModifierType (gkey.accel_mods));
135 key = AccelKey (GDK_VoidSymbol, Gdk::ModifierType (0));
142 bool operator() (Glib::RefPtr<Gtk::Action> a, Glib::RefPtr<Gtk::Action> b) {
143 ustring astr = a->get_accel_path();
144 ustring bstr = b->get_accel_path();
156 GList* list = gtk_ui_manager_get_action_groups (
ui_manager->gobj());
160 for (node = list; node; node = g_list_next (node)) {
162 GtkActionGroup* group = (GtkActionGroup*) node->data;
166 typedef std::list<Glib::RefPtr<Gtk::Action> > action_list;
167 action_list the_acts;
169 for (acts = gtk_action_group_list_actions (group); acts; acts = g_list_next (acts)) {
170 GtkAction* action = (GtkAction*) acts->data;
171 the_acts.push_back (Glib::wrap (action,
true));
179 for (action_list::iterator a = the_acts.begin(); a != the_acts.end(); ++a) {
181 string accel_path = (*a)->get_accel_path ();
183 groups.push_back (gtk_action_group_get_name(group));
184 names.push_back (accel_path.substr (accel_path.find_last_of (
'/') + 1));
185 tooltips.push_back ((*a)->get_tooltip ());
189 bindings.push_back (AccelKey (key.get_key(), Gdk::ModifierType (key.get_mod())));
195 ActionManager::get_all_actions (vector<string>& names, vector<string>& paths, vector<string>& tooltips, vector<string>& keys, vector<AccelKey>& bindings)
201 GList* list = gtk_ui_manager_get_action_groups (
ui_manager->gobj());
205 for (node = list; node; node = g_list_next (node)) {
207 GtkActionGroup* group = (GtkActionGroup*) node->data;
211 typedef std::list<Glib::RefPtr<Gtk::Action> > action_list;
212 action_list the_acts;
214 for (acts = gtk_action_group_list_actions (group); acts; acts = g_list_next (acts)) {
215 GtkAction* action = (GtkAction*) acts->data;
216 the_acts.push_back (Glib::wrap (action,
true));
224 for (action_list::iterator a = the_acts.begin(); a != the_acts.end(); ++a) {
226 ustring
const label = (*a)->property_label ();
227 string const accel_path = (*a)->get_accel_path ();
229 names.push_back (label);
230 paths.push_back (accel_path);
231 tooltips.push_back ((*a)->get_tooltip ());
235 bindings.push_back (AccelKey (key.get_key(), Gdk::ModifierType (key.get_mod())));
247 GList* list = gtk_ui_manager_get_action_groups (
ui_manager->gobj());
250 string ui_string =
"<ui>";
256 for (node = list; node; node = g_list_next (node)) {
258 GtkActionGroup* group = (GtkActionGroup*) node->data;
260 for (acts = gtk_action_group_list_actions (group); acts; acts = g_list_next (acts)) {
261 ui_string +=
"<accelerator action=\"";
270 string fullpath = gtk_action_get_accel_path ((GtkAction*) acts->data);
272 ui_string += Glib::path_get_basename (fullpath);
277 ui_string +=
"</ui>";
307 for (node = list; node; node = g_list_next (node)) {
309 GtkActionGroup* group = (GtkActionGroup*) node->data;
313 typedef std::list<Glib::RefPtr<Gtk::Action> > action_list;
314 action_list the_acts;
316 for (acts = gtk_action_group_list_actions (group); acts; acts = g_list_next (acts)) {
317 GtkAction* action = (GtkAction*) acts->data;
319 state->push_back (
ActionState (action, gtk_action_get_sensitive (action)));
335 if (state_stack.empty()) {
343 for (ActionStates::iterator i = as->begin(); i != as->end(); ++i) {
344 gtk_action_set_sensitive ((*i).action, (*i).sensitive);
354 for (ActionStates::iterator i = as->begin(); i != as->end(); ++i) {
355 gtk_action_set_sensitive ((*i).action,
false);
375 return RefPtr<Action>();
380 int len = strlen (path);
384 return RefPtr<Action>();
387 if (len > 10 && !strncmp (path,
"<Actions>/", 10 )) {
389 }
else if (path[0] ==
'/') {
393 vector<char> copy(len+1);
394 strcpy (©[0], path);
395 char* slash = strchr (©[0],
'/');
397 return RefPtr<Action> ();
413 return RefPtr<Action> ();
416 GList* list = gtk_ui_manager_get_action_groups (
ui_manager->gobj());
420 for (node = list; node; node = g_list_next (node)) {
422 GtkActionGroup* _ag = (GtkActionGroup*) node->data;
424 if (strcmp (group_name, gtk_action_group_get_name (_ag)) == 0) {
428 if ((_act = gtk_action_group_get_action (_ag, action_name)) != 0) {
429 act = Glib::wrap (_act,
true);
445 GList* list = gtk_ui_manager_get_action_groups (
ui_manager->gobj());
449 for (node = list; node; node = g_list_next (node)) {
451 GtkActionGroup* group = (GtkActionGroup*) node->data;
453 for (acts = gtk_action_group_list_actions (group); acts; acts = g_list_next (acts)) {
454 GtkAction* action = (GtkAction*) acts->data;
455 if (!strcmp (gtk_action_get_name (action),
name)) {
456 return Glib::wrap (action,
true);
461 return RefPtr<Action>();
467 for (vector<RefPtr<Action> >::iterator i = actions.begin(); i != actions.end(); ++i) {
468 (*i)->set_sensitive (state);
487 char const * name = n.c_str ();
489 const char *last_slash = strrchr (name,
'/');
491 if (last_slash == 0) {
498 size_t len = last_slash - (name + 10);
500 char* group_name =
new char[len+1];
501 memcpy (group_name, name + 10, len);
502 group_name[len] =
'\0';
504 const char* action_name = last_slash + 1;
506 RefPtr<Action> act =
get_action (group_name, action_name);
508 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
509 tact->set_active (s);
514 delete [] group_name;
524 key = AccelKey (k, Gdk::ModifierType (key.get_mod()));
525 return ui_manager->get_accel_group()->get_label (key.get_key(), Gdk::ModifierType (key.get_mod()));
545 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
547 tact->set_active (yn);
ActionState(GtkAction *a, bool s)
LIBPBD_API Transmitter fatal
LIBGTKMM2EXT_API Gtk::Widget * get_widget(const char *name)
LIBGTKMM2EXT_API void enable_accelerators()
bool lookup_entry(const string accel_path, Gtk::AccelKey &key)
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > get_action(const char *group, const char *name)
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > get_action_from_name(const char *name)
LIBGTKMM2EXT_API void set_toggle_action(const char *group, const char *name, bool)
LIBGTKMM2EXT_API void do_action(const char *group, const char *name)
LIBPBD_API Transmitter error
LIBPBD_API Transmitter warning
std::ostream & endmsg(std::ostream &ostr)
static Glib::RefPtr< UIManager > ui_manager
LIBGTKMM2EXT_API uint32_t possibly_translate_legal_accelerator_to_real_key(uint32_t keyval)
static std::stack< boost::shared_ptr< ActionStates > > state_stack
LIBGTKMM2EXT_API void disable_all_actions()
LIBGTKMM2EXT_API void set_sensitive(std::vector< Glib::RefPtr< Gtk::Action > > &actions, bool)
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > register_radio_action(Glib::RefPtr< Gtk::ActionGroup > group, Gtk::RadioAction::Group &, const char *name, const char *label, sigc::slot< void > sl, guint key, Gdk::ModifierType mods)
LIBGTKMM2EXT_API void uncheck_toggleaction(std::string)
LIBGTKMM2EXT_API void set_toggleaction_state(std::string, bool)
LIBGTKMM2EXT_API std::string unbound_string
LIBGTKMM2EXT_API void check_toggleaction(std::string)
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::UIManager > ui_manager
static boost::shared_ptr< ActionStates > get_action_state()
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > register_toggle_action(Glib::RefPtr< Gtk::ActionGroup > group, const char *name, const char *label, sigc::slot< void > sl, guint key, Gdk::ModifierType mods)
LIBGTKMM2EXT_API std::string get_key_representation(const std::string &accel_path, Gtk::AccelKey &key)
LIBGTKMM2EXT_API bool lookup_entry(const Glib::ustring accel_path, Gtk::AccelKey &key)
LIBGTKMM2EXT_API void pop_action_state()
LIBGTKMM2EXT_API void get_all_actions(std::vector< std::string > &names, std::vector< std::string > &paths, std::vector< std::string > &tooltips, std::vector< std::string > &keys, std::vector< Gtk::AccelKey > &bindings)
LIBGTKMM2EXT_API void push_action_state()
LIBGTKMM2EXT_API void add_action_group(Glib::RefPtr< Gtk::ActionGroup >)
std::vector< ActionState > ActionStates
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > register_action(Glib::RefPtr< Gtk::ActionGroup > group, const char *name, const char *label)
std::string string_compose(const std::string &fmt, const T1 &o1)