[gtksourceview] Properly notify when a style scheme is changed
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Properly notify when a style scheme is changed
- Date: Tue, 30 Dec 2014 16:59:56 +0000 (UTC)
commit cb4e1ef02c710670a3d23a70b0c540e6d364c4f2
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Dec 30 17:57:58 2014 +0100
Properly notify when a style scheme is changed
We now notify when a row is selected, which means that the current
style scheme has changed
gtksourceview/gtksourcestyleschemechooserwidget.c | 202 ++++++++++++---------
1 files changed, 120 insertions(+), 82 deletions(-)
---
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.c
b/gtksourceview/gtksourcestyleschemechooserwidget.c
index a317ba7..60c773c 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.c
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.c
@@ -51,6 +51,7 @@
typedef struct
{
GtkListBox *list_box;
+ GtkSourceStyleScheme *scheme;
} GtkSourceStyleSchemeChooserWidgetPrivate;
static void gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init
(GtkSourceStyleSchemeChooserInterface *iface);
@@ -70,6 +71,65 @@ enum
PROP_STYLE_SCHEME
};
+static void
+gtk_source_style_scheme_chooser_widget_dispose (GObject *object)
+{
+ GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (object);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
+
+ g_clear_object (&priv->scheme);
+
+ G_OBJECT_CLASS (gtk_source_style_scheme_chooser_widget_parent_class)->dispose (object);
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id)
+ {
+ case PROP_STYLE_SCHEME:
+ g_value_set_object (value,
+ gtk_source_style_scheme_chooser_get_style_scheme
(GTK_SOURCE_STYLE_SCHEME_CHOOSER (object)));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id)
+ {
+ case PROP_STYLE_SCHEME:
+ gtk_source_style_scheme_chooser_set_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER
(object),
+ g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_class_init (GtkSourceStyleSchemeChooserWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gtk_source_style_scheme_chooser_widget_dispose;
+ object_class->get_property = gtk_source_style_scheme_chooser_widget_get_property;
+ object_class->set_property = gtk_source_style_scheme_chooser_widget_set_property;
+
+ g_object_class_override_property (object_class, PROP_STYLE_SCHEME, "style-scheme");
+}
+
static GtkWidget *
make_row (GtkSourceStyleScheme *scheme,
GtkSourceLanguage *language)
@@ -82,7 +142,7 @@ make_row (GtkSourceStyleScheme *scheme,
row = gtk_list_box_row_new ();
gtk_widget_show (row);
- g_object_set_data (G_OBJECT (row), "scheme_id", scheme);
+ g_object_set_data (G_OBJECT (row), "scheme", scheme);
buffer = gtk_source_buffer_new_with_language (language);
gtk_source_buffer_set_highlight_matching_brackets (buffer, FALSE);
@@ -108,18 +168,35 @@ make_row (GtkSourceStyleScheme *scheme,
}
static void
+on_row_selected (GtkListBox *list_box,
+ GtkListBoxRow *row,
+ GtkSourceStyleSchemeChooserWidget *widget)
+{
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
+
+ if (row != NULL)
+ {
+ GtkSourceStyleScheme *scheme;
+
+ scheme = g_object_get_data (G_OBJECT (row), "scheme");
+
+ if (g_set_object (&priv->scheme, scheme))
+ {
+ g_object_notify (G_OBJECT (widget), "style-scheme");
+ }
+ }
+}
+
+static void
gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidget *widget)
{
GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
GtkSourceLanguageManager *lm;
GtkSourceLanguage *lang;
GtkSourceStyleSchemeManager *manager;
- GtkSourceStyleScheme *selected_scheme;
const gchar * const *scheme_ids;
guint i;
- selected_scheme = gtk_source_style_scheme_chooser_get_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER
(widget));
-
gtk_container_foreach (GTK_CONTAINER (priv->list_box),
(GtkCallback)gtk_widget_destroy,
NULL);
@@ -139,9 +216,11 @@ gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidg
row = make_row (scheme, lang);
gtk_container_add (GTK_CONTAINER (priv->list_box), GTK_WIDGET (row));
- if (scheme == selected_scheme)
+ if (scheme == priv->scheme)
{
+ g_signal_handlers_block_by_func (priv->list_box, on_row_selected, widget);
gtk_list_box_select_row (priv->list_box, GTK_LIST_BOX_ROW (row));
+ g_signal_handlers_unblock_by_func (priv->list_box, on_row_selected, widget);
}
}
}
@@ -155,77 +234,31 @@ on_scheme_ids_changed (GtkSourceStyleSchemeManager *manager,
}
static void
-gtk_source_style_scheme_chooser_widget_constructed (GObject *object)
+gtk_source_style_scheme_chooser_widget_init (GtkSourceStyleSchemeChooserWidget *widget)
{
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
GtkSourceStyleSchemeManager *manager;
- G_OBJECT_CLASS (gtk_source_style_scheme_chooser_widget_parent_class)->constructed (object);
+ priv->list_box = GTK_LIST_BOX (gtk_list_box_new ());
+ gtk_list_box_set_selection_mode (priv->list_box, GTK_SELECTION_BROWSE);
+ gtk_widget_show (GTK_WIDGET (priv->list_box));
+ gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (priv->list_box));
manager = gtk_source_style_scheme_manager_get_default ();
g_signal_connect (manager,
"notify::scheme-ids",
G_CALLBACK (on_scheme_ids_changed),
- object);
-
- gtk_source_style_scheme_chooser_widget_populate (GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (object));
-}
-
-static void
-gtk_source_style_scheme_chooser_widget_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id)
- {
- case PROP_STYLE_SCHEME:
- g_value_set_object (value,
- gtk_source_style_scheme_chooser_get_style_scheme
(GTK_SOURCE_STYLE_SCHEME_CHOOSER (object)));
- break;
+ widget);
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-gtk_source_style_scheme_chooser_widget_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id)
- {
- case PROP_STYLE_SCHEME:
- gtk_source_style_scheme_chooser_set_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER
(object),
- g_value_get_object (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-gtk_source_style_scheme_chooser_widget_class_init (GtkSourceStyleSchemeChooserWidgetClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = gtk_source_style_scheme_chooser_widget_get_property;
- object_class->set_property = gtk_source_style_scheme_chooser_widget_set_property;
- object_class->constructed = gtk_source_style_scheme_chooser_widget_constructed;
-
- g_object_class_override_property (object_class, PROP_STYLE_SCHEME, "style-scheme");
-}
+ gtk_source_style_scheme_chooser_widget_populate (widget);
-static void
-gtk_source_style_scheme_chooser_widget_init (GtkSourceStyleSchemeChooserWidget *widget)
-{
- GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
+ gtk_source_style_scheme_chooser_set_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER (widget),
+ _gtk_source_style_scheme_get_default ());
- priv->list_box = GTK_LIST_BOX (gtk_list_box_new ());
- gtk_widget_show (GTK_WIDGET (priv->list_box));
- gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (priv->list_box));
+ g_signal_connect (priv->list_box,
+ "row-selected",
+ G_CALLBACK (on_row_selected),
+ widget);
}
static GtkSourceStyleScheme *
@@ -233,11 +266,8 @@ gtk_source_style_scheme_chooser_widget_get_style_scheme (GtkSourceStyleSchemeCho
{
GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (chooser);
GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
- GtkListBoxRow *row;
- row = gtk_list_box_get_selected_row (priv->list_box);
-
- return row != NULL ? g_object_get_data (G_OBJECT (row), "scheme_id") : NULL;
+ return priv->scheme;
}
static void
@@ -246,26 +276,34 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
{
GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (chooser);
GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
- GList *children;
- GList *l;
-
- children = gtk_container_get_children (GTK_CONTAINER (priv->list_box));
- for (l = children; l != NULL; l = g_list_next (l))
+ if (g_set_object (&priv->scheme, scheme))
{
- GtkListBoxRow *row = l->data;
- GtkSourceStyleScheme *cur;
+ GList *children;
+ GList *l;
- cur = g_object_get_data (G_OBJECT (row), "scheme_id");
+ children = gtk_container_get_children (GTK_CONTAINER (priv->list_box));
- if (cur == scheme)
+ for (l = children; l != NULL; l = g_list_next (l))
{
- gtk_list_box_select_row (priv->list_box, row);
- break;
+ GtkListBoxRow *row = l->data;
+ GtkSourceStyleScheme *cur;
+
+ cur = g_object_get_data (G_OBJECT (row), "scheme");
+
+ if (cur == scheme)
+ {
+ g_signal_handlers_block_by_func (priv->list_box, on_row_selected, widget);
+ gtk_list_box_select_row (priv->list_box, row);
+ g_signal_handlers_unblock_by_func (priv->list_box, on_row_selected, widget);
+ break;
+ }
}
- }
- g_list_free (children);
+ g_list_free (children);
+
+ g_object_notify (G_OBJECT (chooser), "style-scheme");
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]