Commit be2d9b4f authored by Cosimo Cecchi's avatar Cosimo Cecchi

GSimpleAction: add g_simple_action_set_state_hint

Currently the only way to set a state hint on an action is through a
subclass; add a g_simple_action_set_state_hint() method so that this
becomes easier for clients that already use GSimpleAction.

https://bugzilla.gnome.org/show_bug.cgi?id=743521
parent 2a0c1804
......@@ -3221,6 +3221,7 @@ g_simple_action_new_stateful
<SUBSECTION>
g_simple_action_set_enabled
g_simple_action_set_state
g_simple_action_set_state_hint
<SUBSECTION Standard>
g_simple_action_get_type
......
......@@ -44,6 +44,7 @@ struct _GSimpleAction
GVariantType *parameter_type;
gboolean enabled;
GVariant *state;
GVariant *state_hint;
gboolean state_set_already;
};
......@@ -102,7 +103,12 @@ g_simple_action_get_state_type (GAction *action)
static GVariant *
g_simple_action_get_state_hint (GAction *action)
{
return NULL;
GSimpleAction *simple = G_SIMPLE_ACTION (action);
if (simple->state_hint != NULL)
return g_variant_ref (simple->state_hint);
else
return NULL;
}
static gboolean
......@@ -319,6 +325,8 @@ g_simple_action_finalize (GObject *object)
g_variant_type_free (simple->parameter_type);
if (simple->state)
g_variant_unref (simple->state);
if (simple->state_hint)
g_variant_unref (simple->state_hint);
G_OBJECT_CLASS (g_simple_action_parent_class)
->finalize (object);
......@@ -543,6 +551,35 @@ g_simple_action_set_enabled (GSimpleAction *simple,
g_object_notify (G_OBJECT (simple), "enabled");
}
}
/**
* g_simple_action_set_state_hint:
* @simple: a #GSimpleAction
* @state_hint: (allow-none): a #GVariant representing the state hint
*
* Sets the state hint for the action.
*
* See g_action_get_state_hint() for more information about
* action state hints.
*
* Since: 2.44
**/
void
g_simple_action_set_state_hint (GSimpleAction *simple,
GVariant *state_hint)
{
g_return_if_fail (G_IS_SIMPLE_ACTION (simple));
if (simple->state_hint != NULL)
{
g_variant_unref (simple->state_hint);
simple->state_hint = NULL;
}
if (state_hint != NULL)
simple->state_hint = g_variant_ref (state_hint);
}
/**
* g_simple_action_new:
* @name: the name of the action
......
......@@ -54,6 +54,10 @@ GLIB_AVAILABLE_IN_2_30
void g_simple_action_set_state (GSimpleAction *simple,
GVariant *value);
GLIB_AVAILABLE_IN_2_44
void g_simple_action_set_state_hint (GSimpleAction *simple,
GVariant *state_hint);
G_END_DECLS
#endif /* __G_SIMPLE_ACTION_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment