[glib] GSimpleAction: add g_simple_action_set_state_hint
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GSimpleAction: add g_simple_action_set_state_hint
- Date: Mon, 26 Jan 2015 14:18:59 +0000 (UTC)
commit be2d9b4f5801380ac02e8d158686538d10e3dee5
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jan 26 11:18:06 2015 +0000
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
docs/reference/gio/gio-sections.txt | 1 +
gio/gsimpleaction.c | 39 ++++++++++++++++++++++++++++++++++-
gio/gsimpleaction.h | 4 +++
3 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index e7330bf..329c739 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -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
diff --git a/gio/gsimpleaction.c b/gio/gsimpleaction.c
index 610e2fa..589972a 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 3dd0fa9..c629212 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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]