[gnome-builder] editor: add GbEditorDocument:style-scheme-name



commit 0931ce989df9c9518ec19f99cc8e4e27bd5c15ff
Author: Christian Hergert <christian hergert me>
Date:   Wed Oct 15 23:10:56 2014 -0700

    editor: add GbEditorDocument:style-scheme-name

 src/editor/gb-editor-document.c |   59 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-document.c b/src/editor/gb-editor-document.c
index e22d80a..f7956fa 100644
--- a/src/editor/gb-editor-document.c
+++ b/src/editor/gb-editor-document.c
@@ -16,15 +16,27 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "editor-document"
+
+#include <glib/gi18n.h>
+#include <gtksourceview/gtksource.h>
+
 #include "gb-editor-document.h"
 
 enum {
+  PROP_0,
+  PROP_STYLE_SCHEME_NAME,
+  LAST_PROP
+};
+
+enum {
   CURSOR_MOVED,
   LAST_SIGNAL
 };
 
 G_DEFINE_TYPE (GbEditorDocument, gb_editor_document, GTK_SOURCE_TYPE_BUFFER)
 
+static  GParamSpec *gParamSpecs [LAST_PROP];
 static guint gSignals [LAST_SIGNAL];
 
 GbEditorDocument *
@@ -34,6 +46,21 @@ gb_editor_document_new (void)
 }
 
 static void
+gb_editor_document_set_style_scheme_name (GbEditorDocument *document,
+                                          const gchar      *style_scheme_name)
+{
+  GtkSourceStyleSchemeManager *manager;
+  GtkSourceStyleScheme *scheme;
+
+  g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+  manager = gtk_source_style_scheme_manager_get_default ();
+  scheme = gtk_source_style_scheme_manager_get_scheme (manager,
+                                                       style_scheme_name);
+  gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (document), scheme);
+}
+
+static void
 gb_editor_document_mark_set (GtkTextBuffer     *buffer,
                              const GtkTextIter *iter,
                              GtkTextMark       *mark)
@@ -56,14 +83,46 @@ gb_editor_document_changed (GtkTextBuffer *buffer)
 }
 
 static void
+gb_editor_document_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GbEditorDocument *self = (GbEditorDocument *)object;
+
+  switch (prop_id)
+    {
+    case PROP_STYLE_SCHEME_NAME:
+      gb_editor_document_set_style_scheme_name (self,
+                                                g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
 gb_editor_document_class_init (GbEditorDocumentClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkTextBufferClass *text_buffer_class = GTK_TEXT_BUFFER_CLASS (klass);
 
+  object_class->set_property = gb_editor_document_set_property;
+
   text_buffer_class->mark_set = gb_editor_document_mark_set;
   text_buffer_class->changed = gb_editor_document_changed;
 
+  gParamSpecs [PROP_STYLE_SCHEME_NAME] =
+    g_param_spec_string ("style-scheme-name",
+                         _("Style Scheme Name"),
+                         _("The style scheme name."),
+                         NULL,
+                         (G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_STYLE_SCHEME_NAME,
+                                   gParamSpecs [PROP_STYLE_SCHEME_NAME]);
+
   gSignals[CURSOR_MOVED] =
     g_signal_new ("cursor-moved",
                   G_OBJECT_CLASS_TYPE (object_class),


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