diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index e7330bf12..329c7390f 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -3221,6 +3221,7 @@ g_simple_action_new_stateful g_simple_action_set_enabled g_simple_action_set_state +g_simple_action_set_state_hint g_simple_action_get_type diff --git a/gio/gsimpleaction.c b/gio/gsimpleaction.c index 610e2fa1d..589972a26 100644 --- a/gio/gsimpleaction.c +++ b/gio/gsimpleaction.c @@ -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 diff --git a/gio/gsimpleaction.h b/gio/gsimpleaction.h index 3dd0fa932..c6292120b 100644 --- a/gio/gsimpleaction.h +++ b/gio/gsimpleaction.h @@ -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__ */