13
0

add syntactic sugar for fetching toggle and radio actions

This commit is contained in:
Paul Davis 2018-12-06 22:12:27 -05:00
parent 927a33c5f3
commit dd4c788d3e
2 changed files with 53 additions and 0 deletions

View File

@ -1188,6 +1188,30 @@ ActionMap::find_action (const string& name)
return RefPtr<Action>(); return RefPtr<Action>();
} }
RefPtr<ToggleAction>
ActionMap::find_toggle_action (const string& name)
{
RefPtr<Action> act = find_action (name);
if (!act) {
return RefPtr<ToggleAction>();
}
return Glib::RefPtr<ToggleAction>::cast_dynamic (act);
}
RefPtr<RadioAction>
ActionMap::find_radio_action (const string& name)
{
RefPtr<Action> act = find_action (name);
if (!act) {
return RefPtr<RadioAction>();
}
return Glib::RefPtr<RadioAction>::cast_dynamic (act);
}
RefPtr<Action> RefPtr<Action>
ActionMap::find_action (char const * group_name, char const * action_name) ActionMap::find_action (char const * group_name, char const * action_name)
{ {
@ -1205,6 +1229,31 @@ ActionMap::find_action (char const * group_name, char const * action_name)
return RefPtr<Action>(); return RefPtr<Action>();
} }
RefPtr<ToggleAction>
ActionMap::find_toggle_action (char const * group_name, char const * action_name)
{
RefPtr<Action> act = find_action (group_name, action_name);
if (!act) {
return RefPtr<ToggleAction>();
}
return Glib::RefPtr<ToggleAction>::cast_dynamic (act);
}
RefPtr<RadioAction>
ActionMap::find_radio_action (char const * group_name, char const * action_name)
{
RefPtr<Action> act = find_action (group_name, action_name);
if (!act) {
return RefPtr<RadioAction>();
}
return Glib::RefPtr<RadioAction>::cast_dynamic (act);
}
RefPtr<ActionGroup> RefPtr<ActionGroup>
ActionMap::create_action_group (const string& name) ActionMap::create_action_group (const string& name)
{ {

View File

@ -107,6 +107,10 @@ class LIBGTKMM2EXT_API ActionMap {
Glib::RefPtr<Gtk::Action> find_action (const std::string& name); Glib::RefPtr<Gtk::Action> find_action (const std::string& name);
Glib::RefPtr<Gtk::Action> find_action (char const * group_name, char const * action_name); Glib::RefPtr<Gtk::Action> find_action (char const * group_name, char const * action_name);
Glib::RefPtr<Gtk::ToggleAction> find_toggle_action (const std::string& name);
Glib::RefPtr<Gtk::ToggleAction> find_toggle_action (char const * group_name, char const * action_name);
Glib::RefPtr<Gtk::RadioAction> find_radio_action (const std::string& name);
Glib::RefPtr<Gtk::RadioAction> find_radio_action (char const * group_name, char const * action_name);
void set_bindings (Bindings*); void set_bindings (Bindings*);
Bindings* bindings() const { return _bindings; } Bindings* bindings() const { return _bindings; }