glibmm 2.86.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gio::Action Class Reference

Action - An action interface. More...

`#include <giomm/action.h>`

Inheritance diagram for Gio::Action:
[legend]

## Public Member Functions
| Action (Action && src) noexcept
Action & | operator= (Action && src) noexcept
| ~Action () noexcept override
GAction * | gobj ()
| Provides access to the underlying C GObject.
const GAction * | gobj () const
| Provides access to the underlying C GObject.
Glib::ustring | get_name () const
| Queries the name of action.
Glib::VariantType | get_parameter_type () const
| Queries the type of the parameter that must be given when activating action.
Glib::VariantType | get_state_type () const
| Queries the type of the state of action.
template<typename T_Value>
void | get_state_hint (T_Value & value) const
| Requests a hint about the valid range of values for the state of the action.
Glib::VariantContainerBase | get_state_hint_variant () const
| Requests a hint about the valid range of values for the state of action.
bool | get_enabled () const
| Checks if action is currently enabled.
template<typename T_Value>
void | change_state (const T_Value & value)
| Request for the state of action to be changed to value, assuming that the action has the expected state type.
template<typename T_Value>
void | change_state (const Glib::Variant< T_Value > & value)
void | change_state_variant (const Glib::VariantBase & value)
| Request for the state of action to be changed to value.
template<typename T_Value>
void | get_state (T_Value & value) const
| Queries the current state of the action.
Glib::VariantBase | get_state_variant () const
| Queries the current state of action.
void | activate ()
| Activates the action without a parameter.
template<typename T_Value>
void | activate (const T_Value & parameter)
| Activates the action with a parameter.
template<typename T_Value>
void | activate (const Glib::Variant< T_Value > & parameter)
void | activate_variant (const Glib::VariantBase & parameter)
| Activates the action.
template<typename T_Value>
Glib::ustring | print_detailed_name (const T_Value & target_value)
| Formats a detailed action name from the action's action_name and target_value.
Glib::PropertyProxy_ReadOnly< bool > | property_enabled () const
| If action is currently enabled.
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_name () const
| The name of the action.
Glib::PropertyProxy_ReadOnly< Glib::VariantType > | property_parameter_type () const
| The type of the parameter that must be given when activating the action.
Glib::PropertyProxy_ReadOnly< Glib::VariantBase > | property_state () const
| The state of the action, or nullptr if the action is stateless.
Glib::PropertyProxy_ReadOnly< Glib::VariantType > | property_state_type () const
| The Glib::VariantType of the state that the action has, or nullptr if the action is stateless.
Public Member Functions inherited from Glib::Interface
| Interface ()
| A Default constructor.
| Interface (Interface && src) noexcept
Interface & | operator= (Interface && src) noexcept
| Interface (const Glib::Interface_Class & interface_class)
| Called by constructors of derived classes.
| Interface (GObject * castitem)
| Called by constructors of derived classes.
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
| You probably want to use a specific property_*() accessor method instead.
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
| You probably want to use a specific property_*() accessor method instead.
template<class PropertyType>
void | set_property (const Glib::ustring & property_name, const PropertyType & value)
| You probably want to use a specific property_*() accessor method instead.
template<class PropertyType>
void | get_property (const Glib::ustring & property_name, PropertyType & value) const
| You probably want to use a specific property_*() accessor method instead.
template<class PropertyType>
PropertyType | get_property (const Glib::ustring & property_name) const
| You probably want to use a specific property_*() accessor method instead.
sigc::connection | connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void()> & slot)
| You can use the signal_changed() signal of the property proxy instead.
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
| You can use the signal_changed() signal of the property proxy instead.
void | freeze_notify ()
| Increases the freeze count on object.
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify().
virtual void | reference () const
| Increment the reference count for this object.
virtual void | unreference () const
| Decrement the reference count for this object.
GObject * | gobj ()
| Provides access to the underlying C GObject.
const GObject * | gobj () const
| Provides access to the underlying C GObject.
GObject * | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access.

## Static Public Member Functions
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static bool | name_is_valid (const Glib::ustring & action_name)
| Checks if action_name is valid.
template<typename T_Value>
static void | parse_detailed_name (const Glib::ustring & detailed_name, Glib::ustring & action_name, T_Value & target_value)
| Parses a detailed action name into its separate name and target components.
static void | parse_detailed_name_variant (const Glib::ustring & detailed_name, Glib::ustring & action_name, Glib::VariantBase & target_value)
| Parses a detailed action name into its separate name and target components.
static Glib::ustring | print_detailed_name_variant (const Glib::ustring & action_name, const Glib::VariantBase & target_value)
| Formats a detailed action name from action_name and target_value.

## Protected Member Functions
| Action ()
| You should derive from this class to use it.
virtual Glib::ustring | get_name_vfunc () const
virtual Glib::VariantType | get_parameter_type_vfunc () const
virtual Glib::VariantType | get_state_type_vfunc () const
virtual Glib::VariantBase | get_state_hint_vfunc () const
virtual bool | get_enabled_vfunc () const
virtual Glib::VariantBase | get_state_vfunc () const
virtual void | change_state_vfunc (const Glib::VariantBase & value)
virtual void | activate_vfunc (const Glib::VariantBase & parameter)
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor.
| ObjectBase (const char * custom_type_name)
| A derived constructor always overrides this choice.
| ObjectBase (const std::type_info & custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually.
| ObjectBase (ObjectBase && src) noexcept
ObjectBase & | operator= (ObjectBase && src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject * castitem)
void | initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gio::Action > | wrap (GAction * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

Action - An action interface.

Action represents a single named action.

The main interface to an action is that it can be activated with activate(). This results in the signal_activate() signal being emitted. An activation may optionally have a parameter, activate(const T_Value& parameter). The correct type for the parameter is determined by a static parameter type (which is given at construction time).

An action may optionally have a state, in which case the state may be set with change_state(). The correct type for the state is determined by a static state type (which is given at construction time).

An Action can have a state, but no parameter, or vice versa. If it has both, the parameter type can differ from the state type.

The state may have a hint associated with it, specifying its valid range.

Action is merely the interface to the concept of an action, as described above. Various implementations of actions exist, including SimpleAction.

In all cases, the implementing class is responsible for storing the name of the action, the parameter type, the enabled state, the optional state type and the state and emitting the appropriate signals when these change. The implementor is responsible for filtering calls to activate() and change_state() for type safety and for the state being enabled.

Probably the only useful thing to do with an Action is to put it inside of a SimpleActionGroup.

Since glibmm 2.32

## Constructor & Destructor Documentation

## ◆ Action() [1/2]

Gio::Action::Action | ( |  | ) |
| protected

You should derive from this class to use it.

## ◆ Action() [2/2]

Gio::Action::Action | ( | Action && | src | ) |
| noexcept

## ◆ ~Action()

Gio::Action::~Action | ( |  | ) |
| override noexcept

## Member Function Documentation

## ◆ activate() [1/3]

void Gio::Action::activate | ( |  | ) |

Activates the action without a parameter.

## ◆ activate() [2/3]

template <typename T_Value>

void Gio::Action::activate | ( | const Glib::Variant< T_Value > & | parameter | ) |

## ◆ activate() [3/3]

template <typename T_Value>

void Gio::Action::activate | ( | const T_Value & | parameter | ) |

Activates the action with a parameter.

The parameter must be the correct type of parameter for the action (ie: the parameter type given at construction time).

Parameters

  parameter | The parameter to the activation

## ◆ activate_variant()

void Gio::Action::activate_variant | ( | const Glib::VariantBase & | parameter | ) |

Activates the action.

parameter must be the correct type of parameter for the action (ie: the parameter type given at construction time). If the parameter type was nullptr then parameter must also be nullptr.

If the parameter Glib::Variant is floating, it is consumed.

Since glibmm 2.28

Parameters

  parameter | The parameter to the activation.

## ◆ activate_vfunc()

virtual void Gio::Action::activate_vfunc | ( | const Glib::VariantBase & | parameter | ) |
| protected virtual

## ◆ add_interface()

void Gio::Action::add_interface | ( | GType | gtype_implementer | ) |
| static

## ◆ change_state() [1/2]

template <typename T_Value>

void Gio::Action::change_state | ( | const Glib::Variant< T_Value > & | value | ) |

## ◆ change_state() [2/2]

template <typename T_Value>

void Gio::Action::change_state | ( | const T_Value & | value | ) |

Request for the state of action to be changed to value, assuming that the action has the expected state type.

See get_state_type().

This call merely requests a change. The action may refuse to change its state or may change its state to something other than value. See get_state_hint().

Since glibmm 2.38

Parameters

  value | The new state.

## ◆ change_state_variant()

void Gio::Action::change_state_variant | ( | const Glib::VariantBase & | value | ) |

Request for the state of action to be changed to value.

The action must be stateful and value must be of the correct type. See Gio::Action::get_state_type().

This call merely requests a change. The action may refuse to change its state or may change its state to something other than value. See Gio::Action::get_state_hint().

If the value Glib::Variant is floating, it is consumed.

Since glibmm 2.30

Parameters

  value | The new state.

## ◆ change_state_vfunc()

virtual void Gio::Action::change_state_vfunc | ( | const Glib::VariantBase & | value | ) |
| protected virtual

## ◆ get_enabled()

bool Gio::Action::get_enabled | ( |  | ) | const

Checks if action is currently enabled.

An action must be enabled in order to be activated or in order to have its state changed from outside callers.

Since glibmm 2.28

Returns
  Whether the action is enabled.

## ◆ get_enabled_vfunc()

virtual bool Gio::Action::get_enabled_vfunc | ( |  | ) | const
| protected virtual

## ◆ get_name()

Glib::ustring Gio::Action::get_name | ( |  | ) | const

Queries the name of action.

Since glibmm 2.28

Returns
  The name of the action.

## ◆ get_name_vfunc()

virtual Glib::ustring Gio::Action::get_name_vfunc | ( |  | ) | const
| protected virtual

## ◆ get_parameter_type()

Glib::VariantType Gio::Action::get_parameter_type | ( |  | ) | const

Queries the type of the parameter that must be given when activating action.

When activating the action using Gio::Action::activate(), the Glib::Variant given to that function must be of the type returned by this function.

In the case that this function returns nullptr, you must not give any Glib::Variant, but nullptr instead.

Since glibmm 2.28

Returns
  The parameter type.

## ◆ get_parameter_type_vfunc()

virtual Glib::VariantType Gio::Action::get_parameter_type_vfunc | ( |  | ) | const
| protected virtual

## ◆ get_state()

template <typename T_Value>

void Gio::Action::get_state | ( | T_Value & | value | ) | const

Queries the current state of the action.

If the action is not stateful then a null Variant will be returned. If the action is stateful then the type of the return value is the type given by get_state_type().

Parameters

  value | This will be set to the current state of the action.

## ◆ get_state_hint()

template <typename T_Value>

void Gio::Action::get_state_hint | ( | T_Value & | value | ) | const

Requests a hint about the valid range of values for the state of the action.

If a null Variant is returned it either means that the action is not stateful or that there is no hint about the valid range of values for the state of the action.

If a Variant array is returned then each item in the array is a possible value for the state. If a Variant pair (ie: two-tuple) is returned then the tuple specifies the inclusive lower and upper bound of valid values for the state.

In any case, the information is merely a hint. It may be possible to have a state value outside of the hinted range and setting a value within the range may fail.

Parameters

  value | This will be set to the state range hint.

## ◆ get_state_hint_variant()

Glib::VariantContainerBase Gio::Action::get_state_hint_variant | ( |  | ) | const

Requests a hint about the valid range of values for the state of action.

If nullptr is returned it either means that the action is not stateful or that there is no hint about the valid range of values for the state of the action.

If a Glib::Variant array is returned then each item in the array is a possible value for the state. If a Glib::Variant pair (ie: two-tuple) is returned then the tuple specifies the inclusive lower and upper bound of valid values for the state.

In any case, the information is merely a hint. It may be possible to have a state value outside of the hinted range and setting a value within the range may fail.

The return value (if non-nullptr) should be freed with Glib::Variant::unref() when it is no longer required.

Since glibmm 2.28

Returns
  The state range hint.

## ◆ get_state_hint_vfunc()

virtual Glib::VariantBase Gio::Action::get_state_hint_vfunc | ( |  | ) | const
| protected virtual

## ◆ get_state_type()

Glib::VariantType Gio::Action::get_state_type | ( |  | ) | const

Queries the type of the state of action.

If the action is stateful (e.g. created with Gio::SimpleAction::new_stateful()) then this function returns the Glib::VariantType of the state. This is the type of the initial value given as the state. All calls to Gio::Action::change_state() must give a Glib::Variant of this type and Gio::Action::get_state() will return a Glib::Variant of the same type.

If the action is not stateful (e.g. created with Gio::SimpleAction::new()) then this function will return nullptr. In that case, Gio::Action::get_state() will return nullptr and you must not call Gio::Action::change_state().

Since glibmm 2.28

Returns
  The state type, if the action is stateful.

## ◆ get_state_type_vfunc()

virtual Glib::VariantType Gio::Action::get_state_type_vfunc | ( |  | ) | const
| protected virtual

## ◆ get_state_variant()

Glib::VariantBase Gio::Action::get_state_variant | ( |  | ) | const

Queries the current state of action.

If the action is not stateful then nullptr will be returned. If the action is stateful then the type of the return value is the type given by Gio::Action::get_state_type().

The return value (if non-nullptr) should be freed with Glib::Variant::unref() when it is no longer required.

Since glibmm 2.28

Returns
  The current state of the action.

## ◆ get_state_vfunc()

virtual Glib::VariantBase Gio::Action::get_state_vfunc | ( |  | ) | const
| protected virtual

## ◆ get_type()

GType Gio::Action::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GAction * Gio::Action::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GAction * Gio::Action::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ name_is_valid()

bool Gio::Action::name_is_valid | ( | const Glib::ustring & | action_name | ) |
| static

Checks if action_name is valid.

action_name is valid if it consists only of alphanumeric characters, plus - and .. The empty string is not a valid action name.

It is an error to call this function with a non-UTF-8 action_name. action_name must not be nullptr.

Since glibmm 2.38

Parameters

  action_name | A potential action name.

Returns
  true if action_name is valid.

## ◆ operator=()

Action & Gio::Action::operator= | ( | Action && | src | ) |
| noexcept

## ◆ parse_detailed_name()

template <typename T_Value>

void Gio::Action::parse_detailed_name | ( | const Glib::ustring & | detailed_name,
|  | Glib::ustring & | action_name,
|  | T_Value & | target_value )
| static

Parses a detailed action name into its separate name and target components.

Detailed action names can have three formats. See parse_detailed_name_variant().

Since glibmm 2.40

Parameters

  | detailed_name | A detailed action name.
  [out] | action_name | The action name.
  [out] | target_value | The target value.

Exceptions

  Glib::VariantParseError | if detailed_name has an invalid format or a target of an unexpected type.

## ◆ parse_detailed_name_variant()

void Gio::Action::parse_detailed_name_variant | ( | const Glib::ustring & | detailed_name,
|  | Glib::ustring & | action_name,
|  | Glib::VariantBase & | target_value )
| static

Parses a detailed action name into its separate name and target components.

Detailed action names can have three formats.

The first format is used to represent an action name with no target value and consists of just an action name containing no whitespace nor the characters :, ( or ). For example: app.action.

The second format is used to represent an action with a target value that is a non-empty string consisting only of alphanumerics, plus - and .. In that case, the action name and target value are separated by a double colon (::). For example: app.action::target.

The third format is used to represent an action with any type of target value, including strings. The target value follows the action name, surrounded in parens. For example: app.action(42). The target value is parsed using glib_variant_parse(). If a tuple-typed value is desired, it must be specified in the same way, resulting in two sets of parens, for example: app.action((1,2,3)). A string target can be specified this way as well: app.action('target'). For strings, this third format must be used if target value is empty or contains characters other than alphanumerics, - and ..

If this function returns true, a non-nullptr value is guaranteed to be returned in action_name (if a pointer is passed in). A nullptr value may still be returned in target_value, as the detailed_name may not contain a target.

If returned, the Glib::Variant in target_value is guaranteed to not be floating.

Since glibmm 2.38

Parameters

  detailed_name | A detailed action name.
  action_name | The action name.
  target_value | The target value, or nullptr for no target.

Exceptions

  Glib::VariantParseError |

## ◆ print_detailed_name()

template <typename T_Value>

Glib::ustring Gio::Action::print_detailed_name | ( | const T_Value & | target_value | ) |

Formats a detailed action name from the action's action_name and target_value.

This function is the opposite of parse_detailed_action_name(). It will produce a string that can be parsed back to the action_name and target_value by that function.

See that function for the types of strings that will be printed by this function.

Parameters

  target_value | A Variant target value.

Returns
  A detailed format string.

## ◆ print_detailed_name_variant()

Glib::ustring Gio::Action::print_detailed_name_variant | ( | const Glib::ustring & | action_name,
|  | const Glib::VariantBase & | target_value )
| static

Formats a detailed action name from action_name and target_value.

It is an error to call this function with an invalid action name.

This function is the opposite of gio_action_parse_detailed_name(). It will produce a string that can be parsed back to the action_name and target_value by that function.

See that function for the types of strings that will be printed by this function.

Since glibmm 2.38

Parameters

  action_name | A valid action name.
  target_value | A Glib::Variant target value, or nullptr.

Returns
  A detailed format string.

## ◆ property_enabled()

Glib::PropertyProxy_ReadOnly< bool > Gio::Action::property_enabled | ( |  | ) | const

If action is currently enabled.

If the action is disabled then calls to Gio::Action::activate() and Gio::Action::change_state() have no effect.

Since glibmm 2.28

Default value: true

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_name()

Glib::PropertyProxy_ReadOnly< Glib::ustring > Gio::Action::property_name | ( |  | ) | const

The name of the action.

This is mostly meaningful for identifying the action once it has been added to a Gio::ActionGroup. It is immutable.

Since glibmm 2.28

Default value: ""

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_parameter_type()

Glib::PropertyProxy_ReadOnly< Glib::VariantType > Gio::Action::property_parameter_type | ( |  | ) | const

The type of the parameter that must be given when activating the action.

This is immutable, and may be nullptr if no parameter is needed when activating the action.

Since glibmm 2.28

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_state()

Glib::PropertyProxy_ReadOnly< Glib::VariantBase > Gio::Action::property_state | ( |  | ) | const

The state of the action, or nullptr if the action is stateless.

Since glibmm 2.28

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_state_type()

Glib::PropertyProxy_ReadOnly< Glib::VariantType > Gio::Action::property_state_type | ( |  | ) | const

The Glib::VariantType of the state that the action has, or nullptr if the action is stateless.

This is immutable.

Since glibmm 2.28

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gio::Action > wrap | ( | GAction * | object,
|  | bool | take_copy = false )
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.