[gtksourceview] SpaceDrawer: add function to bind matrix property to GSettings key
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] SpaceDrawer: add function to bind matrix property to GSettings key
- Date: Wed, 5 Oct 2016 17:50:31 +0000 (UTC)
commit 800ae1646b7d273302e611be8b79cefdfb8d3991
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Oct 5 19:42:45 2016 +0200
SpaceDrawer: add function to bind matrix property to GSettings key
docs/reference/gtksourceview-3.0-sections.txt | 1 +
gtksourceview/gtksourcespacedrawer.c | 66 +++++++++++++++++++++++++
gtksourceview/gtksourcespacedrawer.h | 6 ++
3 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index cbd63cf..2a04388 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -752,6 +752,7 @@ gtk_source_space_drawer_set_matrix
gtk_source_space_drawer_get_matrix
gtk_source_space_drawer_set_enable_matrix
gtk_source_space_drawer_get_enable_matrix
+gtk_source_space_drawer_bind_matrix_setting
<SUBSECTION Standard>
GTK_SOURCE_IS_SPACE_DRAWER
GTK_SOURCE_IS_SPACE_DRAWER_CLASS
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index ddf28fd..b392be8 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -766,6 +766,72 @@ gtk_source_space_drawer_set_enable_matrix (GtkSourceSpaceDrawer *drawer,
}
}
+static gboolean
+matrix_get_mapping (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ g_value_set_variant (value, variant);
+ return TRUE;
+}
+
+static GVariant *
+matrix_set_mapping (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data)
+{
+ return g_value_dup_variant (value);
+}
+
+/**
+ * gtk_source_space_drawer_bind_matrix_setting:
+ * @drawer: a #GtkSourceSpaceDrawer object.
+ * @settings: a #GSettings object.
+ * @key: the @settings key to bind.
+ * @flags: flags for the binding.
+ *
+ * Binds the #GtkSourceSpaceDrawer:matrix property to a #GSettings key.
+ *
+ * The #GSettings key must be of the same type as the
+ * #GtkSourceSpaceDrawer:matrix property, that is, `"au"`.
+ *
+ * The g_settings_bind() function cannot be used, because the default GIO
+ * mapping functions don't support #GVariant properties (maybe it will be
+ * supported by a future GIO version, in which case this function can be
+ * deprecated).
+ *
+ * Since: 3.24
+ */
+void
+gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
+ GSettings *settings,
+ const gchar *key,
+ GSettingsBindFlags flags)
+{
+ GVariant *value;
+
+ g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
+ g_return_if_fail (G_IS_SETTINGS (settings));
+ g_return_if_fail (key != NULL);
+ g_return_if_fail ((flags & G_SETTINGS_BIND_INVERT_BOOLEAN) == 0);
+
+ value = g_settings_get_value (settings, key);
+ if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("au")))
+ {
+ g_warning ("%s(): the GSettings key must be of type \"au\".", G_STRFUNC);
+ g_variant_unref (value);
+ return;
+ }
+ g_variant_unref (value);
+
+ g_settings_bind_with_mapping (settings, key,
+ drawer, "matrix",
+ flags,
+ matrix_get_mapping,
+ matrix_set_mapping,
+ NULL, NULL);
+}
+
void
_gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
GtkSourceView *view)
diff --git a/gtksourceview/gtksourcespacedrawer.h b/gtksourceview/gtksourcespacedrawer.h
index 3454901..c97e5db 100644
--- a/gtksourceview/gtksourcespacedrawer.h
+++ b/gtksourceview/gtksourcespacedrawer.h
@@ -136,6 +136,12 @@ GTK_SOURCE_AVAILABLE_IN_3_24
void gtk_source_space_drawer_set_enable_matrix (GtkSourceSpaceDrawer *drawer,
gboolean enable_matrix);
+GTK_SOURCE_AVAILABLE_IN_3_24
+void gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
+ GSettings *settings,
+ const gchar *key,
+ GSettingsBindFlags flags);
+
G_END_DECLS
#endif /* GTK_SOURCE_SPACE_DRAWER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]