[gtksourceview/wip/scheme-chooser] Add style scheme chooser widgets



commit fc978e5f8b5ca1f64b38299229e886d3487f0e7e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Dec 29 12:21:48 2014 +0100

    Add style scheme chooser widgets

 gtksourceview/Makefile.am                          |   69 +++---
 gtksourceview/gtksource.h                          |    3 +
 gtksourceview/gtksourcestyleschemechooser.c        |   98 +++++++
 gtksourceview/gtksourcestyleschemechooser.h        |   60 ++++
 gtksourceview/gtksourcestyleschemechooserbutton.c  |  282 ++++++++++++++++++++
 gtksourceview/gtksourcestyleschemechooserbutton.h  |   56 ++++
 gtksourceview/gtksourcestyleschemechooserwidget.c  |  245 +++++++++++++++++
 gtksourceview/gtksourcestyleschemechooserwidget.h  |   56 ++++
 gtksourceview/gtksourcestyleschemechooserwidget.ui |   28 ++
 gtksourceview/gtksourceview.gresource.xml          |    1 +
 10 files changed, 867 insertions(+), 31 deletions(-)
---
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index 8df429f..d5bd555 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -45,6 +45,9 @@ libgtksourceview_headers =                    \
        gtksourcesearchsettings.h               \
        gtksourcestyle.h                        \
        gtksourcestylescheme.h                  \
+       gtksourcestyleschemechooser.h           \
+       gtksourcestyleschemechooserbutton.h     \
+       gtksourcestyleschemechooserwidget.h     \
        gtksourcestyleschememanager.h           \
        gtksourcetypes.h                        \
        gtksourceundomanager.h                  \
@@ -97,34 +100,37 @@ libgtksourceview_private_c_files = \
        gtksourceview-utils.c           \
        gtktextregion.c
 
-libgtksourceview_c_files =             \
-       gtksourcebuffer.c               \
-       gtksourcecompletion.c           \
-       gtksourcecompletioncontext.c    \
-       gtksourcecompletioninfo.c       \
-       gtksourcecompletionitem.c       \
-       gtksourcecompletionproposal.c   \
-       gtksourcecompletionprovider.c   \
-       gtksourceencoding.c             \
-       gtksourcefile.c                 \
-       gtksourcefileloader.c           \
-       gtksourcefilesaver.c            \
-       gtksourcegutter.c               \
-       gtksourcegutterrenderer.c       \
-       gtksourcegutterrendererpixbuf.c \
-       gtksourcegutterrenderertext.c   \
-       gtksourcelanguage.c             \
-       gtksourcelanguagemanager.c      \
-       gtksourcemark.c                 \
-       gtksourcemarkattributes.c       \
-       gtksourceprintcompositor.c      \
-       gtksourcesearchcontext.c        \
-       gtksourcesearchsettings.c       \
-       gtksourcestyle.c                \
-       gtksourcestylescheme.c          \
-       gtksourcestyleschememanager.c   \
-       gtksourceundomanager.c          \
-       gtksourceutils.c                \
+libgtksourceview_c_files =                     \
+       gtksourcebuffer.c                       \
+       gtksourcecompletion.c                   \
+       gtksourcecompletioncontext.c            \
+       gtksourcecompletioninfo.c               \
+       gtksourcecompletionitem.c               \
+       gtksourcecompletionproposal.c           \
+       gtksourcecompletionprovider.c           \
+       gtksourceencoding.c                     \
+       gtksourcefile.c                         \
+       gtksourcefileloader.c                   \
+       gtksourcefilesaver.c                    \
+       gtksourcegutter.c                       \
+       gtksourcegutterrenderer.c               \
+       gtksourcegutterrendererpixbuf.c         \
+       gtksourcegutterrenderertext.c           \
+       gtksourcelanguage.c                     \
+       gtksourcelanguagemanager.c              \
+       gtksourcemark.c                         \
+       gtksourcemarkattributes.c               \
+       gtksourceprintcompositor.c              \
+       gtksourcesearchcontext.c                \
+       gtksourcesearchsettings.c               \
+       gtksourcestyle.c                        \
+       gtksourcestylescheme.c                  \
+       gtksourcestyleschemechooser.c           \
+       gtksourcestyleschemechooserbutton.c     \
+       gtksourcestyleschemechooserwidget.c     \
+       gtksourcestyleschememanager.c           \
+       gtksourceundomanager.c                  \
+       gtksourceutils.c                        \
        gtksourceview.c
 
 # Split in a helper library, so the private functions can be used in unit tests.
@@ -220,9 +226,10 @@ stamp-gtksourceview-typebuiltins.h: Makefile.am $(libgtksourceview_headers)
        && (cmp -s xgen-gth gtksourceview-typebuiltins.h || cp xgen-gth gtksourceview-typebuiltins.h) \
        && rm -f xgen-gth && echo stamp > $(@F)
 
-EXTRA_DIST =                           \
-       GtkSource-3.0.metadata          \
-       gtksourcecompletion.ui          \
+EXTRA_DIST =                                   \
+       GtkSource-3.0.metadata                  \
+       gtksourcecompletion.ui                  \
+       gtksourcestyleschemechooserwidget.ui    \
        gtksourceview.gresource.xml
 
 CLEANFILES =                                   \
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index 0903003..b3ba52e 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -45,6 +45,9 @@
 #include <gtksourceview/gtksourcesearchsettings.h>
 #include <gtksourceview/gtksourcestyle.h>
 #include <gtksourceview/gtksourcestylescheme.h>
+#include <gtksourceview/gtksourcestyleschemechooser.h>
+#include <gtksourceview/gtksourcestyleschemechooserbutton.h>
+#include <gtksourceview/gtksourcestyleschemechooserwidget.h>
 #include <gtksourceview/gtksourcestyleschememanager.h>
 #include <gtksourceview/gtksourceundomanager.h>
 #include <gtksourceview/gtksourceutils.h>
diff --git a/gtksourceview/gtksourcestyleschemechooser.c b/gtksourceview/gtksourcestyleschemechooser.c
new file mode 100644
index 0000000..6823212
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooser.c
@@ -0,0 +1,98 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtk_sourcesourcestyleschemechooser.c
+ * This file is part of gtk_sourcesourceview
+ *
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
+ *
+ * gtk_sourcesourceview is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gtk_sourcesourceview is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with gtk_sourcesourceview. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtksourcestyleschemechooser.h"
+#include "gtksourcestylescheme.h"
+
+/**
+ * SECTION:gtksourcestyleschemechooser
+ * @Short_description: Interface implemented by widgets for choosing style schemes
+ * @Title: GtkSourceStyleSchemeChooser
+ * @See_also: #GtkSourceStyleSchemeChooserWidget, #GtkSourceStyleSchemeChooserButton
+ *
+ * #GtkSourceStyleSchemeChooser is an interface that is implemented by widgets
+ * for choosing style schemes.
+ *
+ * In GtkSourceView, the main widgets that implement this interface are
+ * #GtkSourceStyleSchemeChooserWidget and #GtkSourceStyleSchemeChooserButton.
+ *
+ * Since: 3.16
+ */
+
+G_DEFINE_INTERFACE (GtkSourceStyleSchemeChooser, gtk_source_style_scheme_chooser, G_TYPE_OBJECT);
+
+static void
+gtk_source_style_scheme_chooser_default_init (GtkSourceStyleSchemeChooserInterface *iface)
+{
+       /**
+        * GtkSourceStyleSchemeChooser:style-scheme:
+        *
+        * The ::style-scheme property contains the currently selected style
+        * scheme. The property can be set to change
+        * the current selection programmatically.
+        *
+        * Since: 3.16
+        */
+       g_object_interface_install_property (iface,
+               g_param_spec_object ("style-scheme",
+                                    "Style Scheme",
+                                    "Current style scheme",
+                                    GTK_SOURCE_TYPE_STYLE_SCHEME,
+                                    G_PARAM_READWRITE));
+}
+
+/**
+ * gtk_source_style_scheme_chooser_get_style_scheme:
+ * @chooser: a #GtkSourceStyleSchemeChooser
+ *
+ * Gets the currently-selected scheme.
+ *
+ * Returns: (transfer-none): the currently-selected scheme.
+ *
+ * Since: 3.16
+ */
+GtkSourceStyleScheme *
+gtk_source_style_scheme_chooser_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER (chooser), NULL);
+
+       return GTK_SOURCE_STYLE_SCHEME_CHOOSER_GET_IFACE (chooser)->get_style_scheme (chooser);
+}
+
+/**
+ * gtk_source_style_scheme_chooser_set_style_scheme:
+ * @chooser: a #GtkSourceStyleSchemeChooser
+ * @scheme: a #GtkSourceStyleScheme
+ *
+ * Sets the scheme.
+ *
+ * Since: 3.16
+ */
+void
+gtk_source_style_scheme_chooser_set_style_scheme (GtkSourceStyleSchemeChooser *chooser,
+                                                  GtkSourceStyleScheme        *scheme)
+{
+       g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER (chooser));
+       g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme));
+
+       GTK_SOURCE_STYLE_SCHEME_CHOOSER_GET_IFACE (chooser)->set_style_scheme (chooser, scheme);
+}
diff --git a/gtksourceview/gtksourcestyleschemechooser.h b/gtksourceview/gtksourcestyleschemechooser.h
new file mode 100644
index 0000000..abbad0f
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooser.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtk_sourcesourcestyleschemechooser.h
+ * This file is part of gtk_sourcesourceview
+ *
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
+ *
+ * gtk_sourcesourceview is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gtk_sourcesourceview is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with gtk_sourcesourceview. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GTK_SOURCE_STYLE_SCHEME_CHOOSER_H__
+#define __GTK_SOURCE_STYLE_SCHEME_CHOOSER_H__
+
+#include <gtksourceview/gtksourcetypes.h>
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER                  (gtk_source_style_scheme_chooser_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER, GtkSourceStyleSchemeChooser))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE ((inst), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER, GtkSourceStyleSchemeChooserInterface))
+
+typedef struct _GtkSourceStyleSchemeChooser          GtkSourceStyleSchemeChooser;
+typedef struct _GtkSourceStyleSchemeChooserInterface GtkSourceStyleSchemeChooserInterface;
+
+struct _GtkSourceStyleSchemeChooserInterface
+{
+       GTypeInterface base_interface;
+
+       /* Methods */
+       GtkSourceStyleScheme * (* get_style_scheme)       (GtkSourceStyleSchemeChooser *chooser);
+
+       void                   (* set_style_scheme)       (GtkSourceStyleSchemeChooser *chooser,
+                                                          GtkSourceStyleScheme        *scheme);
+
+       /* Padding */
+       gpointer padding[12];
+};
+
+GType                     gtk_source_style_scheme_chooser_get_type               (void) G_GNUC_CONST;
+
+GtkSourceStyleScheme     *gtk_source_style_scheme_chooser_get_style_scheme       
(GtkSourceStyleSchemeChooser *chooser);
+
+void                      gtk_source_style_scheme_chooser_set_style_scheme       
(GtkSourceStyleSchemeChooser *chooser,
+                                                                                  GtkSourceStyleScheme       
 *scheme);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_STYLE_SCHEME_CHOOSER_H__ */
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.c 
b/gtksourceview/gtksourcestyleschemechooserbutton.c
new file mode 100644
index 0000000..6c70c76
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.c
@@ -0,0 +1,282 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtksourcestyleschemechooserwidget.h
+ * This file is part of gtksourceview
+ *
+ * Copyright (C) 2014 - Christian Hergert
+ *               2014 - Ignacio Casal Quinteiro
+ *
+ * gtksourceview is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gtksourceview is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with gtksourceview. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gtksourcestyleschemechooserbutton.h"
+#include "gtksourcestyleschemechooser.h"
+#include "gtksourcestyleschemechooserwidget.h"
+#include "gtksourcestylescheme.h"
+
+typedef struct
+{
+       GtkSourceStyleScheme *scheme;
+
+       GtkWidget *dialog;
+       GtkSourceStyleSchemeChooserWidget *chooser;
+} GtkSourceStyleSchemeChooserButtonPrivate;
+
+enum
+{
+       STYLE_SCHEME_SET,
+       LAST_SIGNAL
+};
+
+static void gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserButton,
+                         gtk_source_style_scheme_chooser_button,
+                         GTK_TYPE_BUTTON,
+                         G_ADD_PRIVATE (GtkSourceStyleSchemeChooserButton)
+                         G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
+                                                
gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init))
+
+#define GET_PRIV(o) gtk_source_style_scheme_chooser_button_get_instance_private (o)
+
+enum
+{
+       PROP_0,
+       PROP_STYLE_SCHEME
+};
+
+static void
+gtk_source_style_scheme_chooser_button_dispose (GObject *object)
+{
+       GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (object);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+
+       g_clear_object (&priv->scheme);
+
+       G_OBJECT_CLASS (gtk_source_style_scheme_chooser_button_parent_class)->dispose (object);
+}
+
+static void
+gtk_source_style_scheme_chooser_button_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_button_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 gboolean
+dialog_destroy (GtkWidget *widget,
+                gpointer   data)
+{
+       GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (data);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+
+       priv->dialog = NULL;
+       priv->chooser = NULL;
+
+       return FALSE;
+}
+
+static void
+dialog_response (GtkDialog *dialog,
+                 gint       response,
+                 gpointer   data)
+{
+       if (response == GTK_RESPONSE_CANCEL)
+       {
+               gtk_widget_hide (GTK_WIDGET (dialog));
+       }
+       else if (response == GTK_RESPONSE_OK)
+       {
+               GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (data);
+               GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+               GtkSourceStyleScheme *scheme;
+
+               scheme = gtk_source_style_scheme_chooser_get_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER 
(priv->chooser));
+
+               gtk_widget_hide (GTK_WIDGET (dialog));
+
+               gtk_source_style_scheme_chooser_set_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER (button),
+                                                                 scheme);
+       }
+}
+
+/* Create the dialog and connects its buttons */
+static void
+ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
+{
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+       GtkWidget *parent, *dialog;
+       GtkWidget *content_area;
+
+       if (priv->dialog != NULL)
+       {
+               return;
+       }
+
+       parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+
+       /* TODO: have a ChooserDialog? */
+       priv->dialog = dialog = gtk_dialog_new_with_buttons (_("Select a Style"),
+                                                            GTK_WINDOW (parent),
+                                                            GTK_DIALOG_DESTROY_WITH_PARENT |
+                                                            GTK_DIALOG_USE_HEADER_BAR,
+                                                            _("Cancel"), GTK_RESPONSE_CANCEL,
+                                                            _("Select"), GTK_RESPONSE_OK,
+                                                            NULL);
+       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+       priv->chooser = g_object_new (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET,
+                                     "height-request", 325,
+                                     "style-scheme", priv->scheme,
+                                     "visible", TRUE,
+                                     "width-request", 450,
+                                     NULL);
+
+       content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+       gtk_container_add (GTK_CONTAINER (content_area), GTK_WIDGET (priv->chooser));
+
+       if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+       {
+               if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
+               {
+                       gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
+               }
+
+               gtk_window_set_modal (GTK_WINDOW (dialog),
+                                     gtk_window_get_modal (GTK_WINDOW (parent)));
+       }
+
+       g_signal_connect (dialog, "response",
+                         G_CALLBACK (dialog_response), button);
+       g_signal_connect (dialog, "destroy",
+                         G_CALLBACK (dialog_destroy), button);
+}
+
+static void
+gtk_source_style_scheme_chooser_button_clicked (GtkButton *button)
+{
+       GtkSourceStyleSchemeChooserButton *cbutton = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (cbutton);
+
+       ensure_dialog (cbutton);
+
+       gtk_source_style_scheme_chooser_set_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER (priv->chooser),
+                                                         priv->scheme);
+
+       gtk_window_present (GTK_WINDOW (priv->dialog));
+}
+
+static void
+gtk_source_style_scheme_chooser_button_class_init (GtkSourceStyleSchemeChooserButtonClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
+
+       object_class->dispose = gtk_source_style_scheme_chooser_button_dispose;
+       object_class->get_property = gtk_source_style_scheme_chooser_button_get_property;
+       object_class->set_property = gtk_source_style_scheme_chooser_button_set_property;
+
+       button_class->clicked = gtk_source_style_scheme_chooser_button_clicked;
+
+       g_object_class_override_property (object_class, PROP_STYLE_SCHEME, "style-scheme");
+}
+
+static void
+gtk_source_style_scheme_chooser_button_init (GtkSourceStyleSchemeChooserButton *button)
+{
+}
+
+static GtkSourceStyleScheme *
+gtk_source_style_scheme_chooser_button_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
+{
+       GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (chooser);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+
+       return priv->scheme;
+}
+
+static void
+gtk_source_style_scheme_chooser_button_update_label (GtkSourceStyleSchemeChooserButton *button)
+{
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+       const gchar *label;
+
+       label = priv->scheme != NULL ? gtk_source_style_scheme_get_name (priv->scheme) : NULL;
+       gtk_button_set_label (GTK_BUTTON (button), label);
+}
+
+static void
+gtk_source_style_scheme_chooser_button_set_style_scheme (GtkSourceStyleSchemeChooser *chooser,
+                                                         GtkSourceStyleScheme        *scheme)
+{
+       GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (chooser);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
+
+       if (g_set_object (&priv->scheme, scheme))
+       {
+               gtk_source_style_scheme_chooser_button_update_label (button);
+
+               g_object_notify (G_OBJECT (button), "style-scheme");
+       }
+}
+
+static void
+gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface)
+{
+       iface->get_style_scheme = gtk_source_style_scheme_chooser_button_get_style_scheme;
+       iface->set_style_scheme = gtk_source_style_scheme_chooser_button_set_style_scheme;
+}
+
+/**
+ * gtk_source_style_scheme_chooser_button_new:
+ *
+ * Creates a new #GtkSourceStyleSchemeChooserButton.
+ *
+ * Returns: a new #GtkSourceStyleSchemeChooserButton.
+ */
+GtkWidget *
+gtk_source_style_scheme_chooser_button_new (void)
+{
+       return g_object_new (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, NULL);
+}
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.h 
b/gtksourceview/gtksourcestyleschemechooserbutton.h
new file mode 100644
index 0000000..3287223
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtksourcestyleschemechooserwidget.h
+ * This file is part of gtksourceview
+ *
+ * Copyright (C) 2014 - Christian Hergert
+ *               2014 - Ignacio Casal Quinteiro
+ *
+ * gtksourceview is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gtksourceview is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with gtksourceview. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_H__
+#define __GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON            
(gtk_source_style_scheme_chooser_button_get_type())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButton))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButton const))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButtonClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButtonClass))
+
+typedef struct _GtkSourceStyleSchemeChooserButton        GtkSourceStyleSchemeChooserButton;
+typedef struct _GtkSourceStyleSchemeChooserButtonClass   GtkSourceStyleSchemeChooserButtonClass;
+
+struct _GtkSourceStyleSchemeChooserButton
+{
+       GtkButton parent;
+};
+
+struct _GtkSourceStyleSchemeChooserButtonClass
+{
+       GtkButtonClass parent;
+};
+
+GType                 gtk_source_style_scheme_chooser_button_get_type              (void);
+
+GtkWidget            *gtk_source_style_scheme_chooser_button_new                   (void);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_H__ */
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.c 
b/gtksourceview/gtksourcestyleschemechooserwidget.c
new file mode 100644
index 0000000..d885033
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.c
@@ -0,0 +1,245 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtksourcestyleschemechooserwidget.h
+ * This file is part of gtksourceview
+ *
+ * Copyright (C) 2014 - Christian Hergert
+ *               2014 - Ignacio Casal Quinteiro
+ *
+ * gtksourceview is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gtksourceview is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with gtksourceview. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gtksourcestyleschemechooserwidget.h"
+#include "gtksourcestyleschemechooser.h"
+#include "gtksourcestylescheme.h"
+#include "gtksourcestyleschememanager.h"
+#include "gtksourcelanguage.h"
+#include "gtksourcelanguagemanager.h"
+#include "gtksourcebuffer.h"
+#include "gtksourceview.h"
+
+typedef struct
+{
+       GtkListBox *list_box;
+} GtkSourceStyleSchemeChooserWidgetPrivate;
+
+static void gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserWidget,
+                         gtk_source_style_scheme_chooser_widget,
+                         GTK_TYPE_BIN,
+                         G_ADD_PRIVATE (GtkSourceStyleSchemeChooserWidget)
+                         G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
+                                                
gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init))
+
+#define GET_PRIV(o) gtk_source_style_scheme_chooser_widget_get_instance_private (o)
+
+enum
+{
+       PROP_0,
+       PROP_STYLE_SCHEME
+};
+
+static GtkWidget *
+make_row (GtkSourceStyleScheme *scheme,
+          GtkSourceLanguage    *language)
+{
+       GtkWidget *row;
+       GtkSourceBuffer *buffer;
+       GtkSourceView *view;
+       gchar *text;
+
+       row = gtk_list_box_row_new ();
+       gtk_widget_show (row);
+
+       g_object_set_data (G_OBJECT (row), "scheme_id", scheme);
+
+       buffer = gtk_source_buffer_new_with_language (language);
+       gtk_source_buffer_set_highlight_matching_brackets (buffer, FALSE);
+       gtk_source_buffer_set_style_scheme (buffer, scheme);
+
+       text = g_strdup_printf ("/* %s */\n#include <gtksourceview/gtksourceview.h>",
+                               gtk_source_style_scheme_get_name (scheme));
+       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), text, -1);
+
+       view = g_object_new (GTK_SOURCE_TYPE_VIEW,
+                            "buffer", buffer,
+                            "can-focus", FALSE,
+                            "cursor-visible", FALSE,
+                            "editable", FALSE,
+                            "visible", TRUE,
+                            "show-line-numbers", TRUE,
+                            "right-margin-position", 30,
+                            "show-right-margin", TRUE,
+                            NULL);
+       gtk_container_add (GTK_CONTAINER (row), GTK_WIDGET (view));
+
+       return row;
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidget *widget)
+{
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
+       GtkSourceLanguageManager *lm;
+       GtkSourceLanguage *lang;
+       GtkSourceStyleSchemeManager *manager;
+       const gchar * const *scheme_ids;
+       guint i;
+
+       manager = gtk_source_style_scheme_manager_get_default ();
+       scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (manager);
+
+       lm = gtk_source_language_manager_get_default ();
+       lang = gtk_source_language_manager_get_language (lm, "c");
+
+       for (i = 0; scheme_ids [i]; i++)
+       {
+               GtkWidget *row;
+               GtkSourceStyleScheme *scheme;
+
+               scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_ids [i]);
+               row = make_row (scheme, lang);
+               gtk_container_add (GTK_CONTAINER (priv->list_box), GTK_WIDGET (row));
+       }
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_constructed (GObject *object)
+{
+       G_OBJECT_CLASS (gtk_source_style_scheme_chooser_widget_parent_class)->constructed (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;
+
+               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);
+       GtkWidgetClass *widget_class = GTK_WIDGET_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");
+
+       /* Bind class to template */
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    
"/org/gnome/gtksourceview/ui/gtksourcestyleschemechooserwidget.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, GtkSourceStyleSchemeChooserWidget, 
list_box);
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_init (GtkSourceStyleSchemeChooserWidget *widget)
+{
+       gtk_widget_init_template (GTK_WIDGET (widget));
+}
+
+static GtkSourceStyleScheme *
+gtk_source_style_scheme_chooser_widget_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
+{
+       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;
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeChooser *chooser,
+                                                         GtkSourceStyleScheme        *scheme)
+{
+       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))
+       {
+               GtkListBoxRow *row = l->data;
+               GtkSourceStyleScheme *cur;
+
+               cur = g_object_get_data (G_OBJECT (row), "scheme_id");
+
+               if (cur == scheme)
+               {
+                       gtk_list_box_select_row (priv->list_box, row);
+                       break;
+               }
+       }
+
+       g_list_free (children);
+}
+
+static void
+gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface)
+{
+       iface->get_style_scheme = gtk_source_style_scheme_chooser_widget_get_style_scheme;
+       iface->set_style_scheme = gtk_source_style_scheme_chooser_widget_set_style_scheme;
+}
+
+/**
+ * gtk_source_style_scheme_chooser_widget_new:
+ *
+ * Creates a new #GtkSourceStyleSchemeChooserWidget.
+ *
+ * Returns: a new  #GtkSourceStyleSchemeChooserWidget.
+ */
+GtkWidget *
+gtk_source_style_scheme_chooser_widget_new (void)
+{
+       return g_object_new (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, NULL);
+}
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.h 
b/gtksourceview/gtksourcestyleschemechooserwidget.h
new file mode 100644
index 0000000..7785516
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtksourcestyleschemechooserwidget.h
+ * This file is part of gtksourceview
+ *
+ * Copyright (C) 2014 - Christian Hergert
+ *               2014 - Ignacio Casal Quinteiro
+ *
+ * gtksourceview is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gtksourceview is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with gtksourceview. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_H
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET            
(gtk_source_style_scheme_chooser_widget_get_type())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidget))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidget const))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidgetClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_WIDGET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidgetClass))
+
+typedef struct _GtkSourceStyleSchemeChooserWidget        GtkSourceStyleSchemeChooserWidget;
+typedef struct _GtkSourceStyleSchemeChooserWidgetClass   GtkSourceStyleSchemeChooserWidgetClass;
+
+struct _GtkSourceStyleSchemeChooserWidget
+{
+       GtkBin parent;
+};
+
+struct _GtkSourceStyleSchemeChooserWidgetClass
+{
+       GtkBinClass parent;
+};
+
+GType        gtk_source_style_scheme_chooser_widget_get_type              (void);
+
+GtkWidget   *gtk_source_style_scheme_chooser_widget_new                   (void);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_H */
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.ui 
b/gtksourceview/gtksourcestyleschemechooserwidget.ui
new file mode 100644
index 0000000..04e177c
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.ui
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <template class="GtkSourceStyleSchemeChooserWidget" parent="GtkBin">
+    <child>
+      <object class="GtkScrolledWindow" id="scrolledwindow">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="shadow_type">in</property>
+        <child>
+          <object class="GtkViewport" id="viewport">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkListBox" id="list_box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gtksourceview/gtksourceview.gresource.xml b/gtksourceview/gtksourceview.gresource.xml
index 8c8d5f0..9321b92 100644
--- a/gtksourceview/gtksourceview.gresource.xml
+++ b/gtksourceview/gtksourceview.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/gtksourceview/ui">
     <file preprocess="xml-stripblanks">gtksourcecompletion.ui</file>
+    <file preprocess="xml-stripblanks">gtksourcestyleschemechooserwidget.ui</file>
   </gresource>
 </gresources>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]