glibmm 2.46.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

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

Action - An action. More...

`#include <giomm/action.h>`

Inheritance diagram for Gio::Action:
[legend]

## Public Member Functions

| Action (Action&& src) noexcept
Action& | operator= (Action&& src) noexcept
virtual | ~Action () noexcept
GAction* | gobj ()
| Provides access to the underlying C GObject. More...
const GAction* | gobj () const
| Provides access to the underlying C GObject. More...
Glib::ustring | get_name () const
| Queries the name of action. More...
Glib::VariantType | get_parameter_type () const
| Queries the type of the parameter that must be given when activating action. More...
Glib::VariantType | get_state_type () const
| Queries the type of the state of action. More...
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. More...
Glib::VariantBase | get_state_hint_variant () const
| Requests a hint about the valid range of values for the state of action. More...
bool | get_enabled () const
| Checks if action is currently enabled. More...
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. More...
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. More...
void | change_state (const Glib::VariantBase& value)
| Request for the state of action to be changed to value. More...
template<typename T_Value >
void | get_state (T_Value& value) const
| Queries the current state of the action. More...
Glib::VariantBase | get_state_variant () const
| Queries the current state of action. More...
void | activate ()
| Activates the action. More...
template<typename T_Value >
void | activate (const T_Value& parameter)
| Activates the action. More...
template<typename T_Value >
void | activate (const Glib::Variant< T_Value >& parameter)
void | activate_variant (const Glib::VariantBase& parameter)
| Activates the action. More...
void | activate (const Glib::VariantBase& parameter)
| Activates the action. More...
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. More...
Glib::PropertyProxy_ReadOnly< bool > | property_enabled () const
| If action is currently enabled. More...
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_name () const
| The name of the action. More...
Glib::PropertyProxy_ReadOnly< Glib::VariantType > | property_parameter_type () const
| The type of the parameter that must be given when activating the action. More...
Glib::PropertyProxy_ReadOnly< Glib::VariantBase > | property_state () const
| The state of the action, or `0` if the action is stateless. More...
Glib::PropertyProxy_ReadOnly< Glib::VariantType > | property_state_type () const
| The VariantType of the state that the action has, or `0` if the action is stateless. More...
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)
Public Member Functions inherited from Glib::Interface
| Interface ()
| A Default constructor. More...
| Interface (Interface&& src) noexcept
Interface& | operator= (Interface&& src) noexcept
| Interface (const Glib::Interface_Class& interface_class)
| Called by constructors of derived classes. More...
| Interface (GObject* castitem)
| Called by constructors of derived classes. More...
virtual | ~Interface () noexcept
| 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. More...
void | get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
| You probably want to use a specific property_*() accessor method instead. More...
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. More...
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. More...
void | 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, but this is necessary when using the reduced API. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject* | gobj ()
| Provides access to the underlying C GObject. More...
const GObject* | gobj () const
| Provides access to the underlying C GObject. More...
GObject* | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const

## 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. More...
static bool | name_is_valid (const Glib::ustring& action_name)
| Checks if action_name is valid. More...
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. More...
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. More...
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. More...

## Protected Member Functions

| Action ()
| You should derive from this class to use it. More...
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. More...
| ObjectBase (const char* custom_type_name)
| A derived constructor always overrides this choice. More...
| 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. More...
| 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 Functions

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

## Additional Inherited Members

Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

Action - An action.

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 has a Glib::VariantBase parameter (which may be `0`). 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(). This call takes a Glib::VariantBase. The correct type for the state is determined by a static state type (which is given at construction time).

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 and Gtk::Action.

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 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 a Action is to put it inside of a SimpleActionGroup.

Since glibmm 2.32:

## Constructor & Destructor Documentation

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

protected

You should derive from this class to use it.

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

noexcept

virtual Gio::Action::~Action | ( |  | ) |

virtual noexcept

## Member Function Documentation

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

Activates the action.

template <typename T_Value >

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

Activates the action.

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

Parameters

  parameter | The parameter to the activation

template <typename T_Value >

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

void Gio::Action::activate | ( | 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 `0` then parameter must also be `0`.

If the parameter GVariant is floating, it is consumed.

Since glibmm 2.28:

Deprecated:
  Use the templated method instead, passing a normal C++ type.

Parameters

  parameter | The parameter to the activation.

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 `0` then parameter must also be `0`.

If the parameter GVariant is floating, it is consumed.

Since glibmm 2.28:

Parameters

  parameter | The parameter to the activation.

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

virtual

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

static

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.

template <typename T_Value >

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

void Gio::Action::change_state | ( | 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 g_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 g_action_get_state_hint().

If the value GVariant is floating, it is consumed.

Since glibmm 2.30:

Deprecated:
  Use the templated method instead, passing a normal C++ type.

Parameters

  value | The new state.

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 g_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 g_action_get_state_hint().

If the value GVariant is floating, it is consumed.

Since glibmm 2.30:

Parameters

  value | The new state.

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

virtual

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.

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

virtual

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

Queries the name of action.

Since glibmm 2.28:

Returns
  The name of the action.

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

virtual

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 g_action_activate(), the Variant given to that function must be of the type returned by this function.

In the case that this function returns `0`, you must not give any Variant, but `0` instead.

Since glibmm 2.28:

Returns
  The parameter type.

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

virtual

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.

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.

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

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

If `0` 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.

The return value (if non-`0`) should be freed with Glib::variant_unref() when it is no longer required.

Since glibmm 2.28:

Returns
  The state range hint.

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

virtual

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 g_simple_action_new_stateful()) then this function returns the VariantType of the state. This is the type of the initial value given as the state. All calls to g_action_change_state() must give a Variant of this type and g_action_get_state() will return a Variant of the same type.

If the action is not stateful (e.g. created with g_simple_action_new()) then this function will return `0`. In that case, g_action_get_state() will return `0` and you must not call g_action_change_state().

Since glibmm 2.28:

Returns
  The state type, if the action is stateful.

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

virtual

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

Queries the current state of action.

If the action is not stateful then `0` will be returned. If the action is stateful then the type of the return value is the type given by g_action_get_state_type().

The return value (if non-`0`) should be freed with Glib::variant_unref() when it is no longer required.

Since glibmm 2.28:

Returns
  The current state of the action.

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

virtual

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

static

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

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

inline

Provides access to the underlying C GObject.

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

inline

Provides access to the underlying C GObject.

static 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-utf8 action_name. action_name must not be `0`.

Since glibmm 2.38:

Parameters

  action_name | An potential action name.

Returns
  `true` if action_name is valid.

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

noexcept

template <typename T_Value >

static 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.

static 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 '.'.

Since glibmm 2.38:

Parameters

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

Returns
  `true` if successful, else `false` with error set.

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.

static 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 Glib::action_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.

Since glibmm 2.38:

Parameters

  action_name | A valid action name.
  target_value | A Variant target value, or `0`.

Returns
  A detailed format string.

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

If action is currently enabled.

If the action is disabled then calls to g_action_activate() and g_action_change_state() have no effect.

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.

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 ActionGroup. It 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.

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 `0` 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.

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

The state of the action, or `0` 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.

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

The VariantType of the state that the action has, or `0` 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 Function Documentation

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.