PropertyAction

A GPropertyAction is a way to get a GAction with a state value reflecting and controlling the value of a GObject property.

The state of the action will correspond to the value of the property. Changing it will change the property (assuming the requested value matches the requirements as specified in the GParamSpec).

Only the most common types are presently supported. Booleans are mapped to booleans, strings to strings, signed/unsigned integers to int32/uint32 and floats and doubles to doubles.

If the property is an enum then the state will be string-typed and conversion will automatically be performed between the enum value and "nick" string as per the GEnumValue table.

Flags types are not currently supported.

Properties of object types, boxed types and pointer types are not supported and probably never will be.

Properties of GVariant types are not currently supported.

If the property is boolean-valued then the action will have a NULL parameter type, and activating the action (with no parameter) will toggle the value of the property.

In all other cases, the parameter type will correspond to the type of the property.

The general idea here is to reduce the number of locations where a particular piece of state is kept (and therefore has to be synchronised between). GPropertyAction does not have a separate state that is kept in sync with the property value -- its state <em>is</em> the property value.

For example, it might be useful to create a GAction corresponding to the "visible-child-name" property of a GtkStack so that the current page can be switched from a menu. The active radio indication in the menu is then directly determined from the active page of the GtkStack.

An anti-example would be binding the "active-id" property on a GtkComboBox. This is because the state of the combobox itself is probably uninteresting and is actually being used to control something else.

Another anti-example would be to bind to the "visible-child-name" property of a GtkStack if this value is actually stored in GSettings. In that case, the real source of the value is GSettings. If you want a GAction to control a setting stored in GSettings, see g_settings_create_action() instead, and possibly combine its use with g_settings_bind().

Constructors

this
this(GPropertyAction* gPropertyAction)

Sets our main struct and passes it to the parent class

this
this(string name, void* object, string propertyName)

Creates a GAction corresponding to the value of property property_name on object. The property must be existent and readable and writable (and not construct-only). This function takes a reference on object and doesn't release it until the action is destroyed. Since 2.38

Members

Functions

getPropertyActionStruct
GPropertyAction* getPropertyActionStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getStruct
void* getStruct()

the main Gtk struct as a void*

Mixins

__anonymous
mixin ActionT!(GPropertyAction)
Undocumented in source.

Variables

gPropertyAction
GPropertyAction* gPropertyAction;

the main Gtk struct

Inherited Members

From ActionIF

getActionTStruct
GAction* getActionTStruct()
Undocumented in source.
getStruct
void* getStruct()

the main Gtk struct as a void*

nameIsValid
int nameIsValid(string actionName)

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 NULL. Since 2.38

getName
string getName()

Queries the name of action. Since 2.28

getParameterType
VariantType getParameterType()

Queries the type of the parameter that must be given when activating action. When activating the action using g_action_activate(), the GVariant given to that function must be of the type returned by this function. In the case that this function returns NULL, you must not give any GVariant, but NULL instead. Since 2.28

getStateType
VariantType getStateType()

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 GVariantType 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 GVariant of this type and g_action_get_state() will return a GVariant of the same type. If the action is not stateful (e.g. created with g_simple_action_new()) then this function will return NULL. In that case, g_action_get_state() will return NULL and you must not call g_action_change_state(). Since 2.28

getStateHint
Variant getStateHint()

Requests a hint about the valid range of values for the state of action. If NULL 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 GVariant array is returned then each item in the array is a possible value for the state. If a GVariant 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-NULL) should be freed with g_variant_unref() when it is no longer required. Since 2.28

getEnabled
int getEnabled()

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 2.28

getState
Variant getState()

Queries the current state of action. If the action is not stateful then NULL 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-NULL) should be freed with g_variant_unref() when it is no longer required. Since 2.28

changeState
void changeState(Variant 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 2.30

activate
void activate(Variant parameter)

Activates the action. Since 2.28

parseDetailedName
int parseDetailedName(string detailedName, string actionName, Variant targetValue)

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 g_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 2.38

printDetailedName
string printDetailedName(string actionName, Variant parameter)

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 g_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 2.38

Meta