[gnome-builder/wip/chergert/bug1: 34/35] debugger: add basic styling to match editor
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/bug1: 34/35] debugger: add basic styling to match editor
- Date: Tue, 29 Aug 2017 05:20:52 +0000 (UTC)
commit 742a63920e9e1d6df2323784368fa848130cb8d2
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 28 18:52:05 2017 -0700
debugger: add basic styling to match editor
libide/debugger/ide-debugger-view.c | 96 +++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/libide/debugger/ide-debugger-view.c b/libide/debugger/ide-debugger-view.c
index 4c8ffb9..e84f927 100644
--- a/libide/debugger/ide-debugger-view.c
+++ b/libide/debugger/ide-debugger-view.c
@@ -32,6 +32,7 @@ struct _IdeDebuggerView
/* Owned references */
GFile *file;
+ GSettings *editor_settings;
/* Unowned references */
GtkSourceView *source_view;
@@ -44,10 +45,87 @@ struct _IdeDebuggerView
G_DEFINE_TYPE (IdeDebuggerView, ide_debugger_view, IDE_TYPE_LAYOUT_VIEW)
static void
+notify_style_scheme (IdeDebuggerView *self,
+ GParamSpec *pspec,
+ GtkSourceBuffer *buffer)
+{
+ g_autofree gchar *background = NULL;
+ g_autofree gchar *foreground = NULL;
+ GtkSourceStyleScheme *scheme;
+ GtkSourceStyle *style;
+ gboolean background_set = FALSE;
+ gboolean foreground_set = FALSE;
+ GdkRGBA rgba;
+
+ g_assert (IDE_IS_DEBUGGER_VIEW (self));
+ g_assert (GTK_SOURCE_IS_BUFFER (buffer));
+
+ if (NULL == (scheme = gtk_source_buffer_get_style_scheme (buffer)) ||
+ NULL == (style = gtk_source_style_scheme_get_style (scheme, "text")))
+ goto unset_primary_color;
+
+ g_object_get (style,
+ "background-set", &background_set,
+ "background", &background,
+ "foreground-set", &foreground_set,
+ "foreground", &foreground,
+ NULL);
+
+ if (!background_set || background == NULL || !gdk_rgba_parse (&rgba, background))
+ goto unset_primary_color;
+
+ if (background_set && background != NULL && gdk_rgba_parse (&rgba, background))
+ ide_layout_view_set_primary_color_bg (IDE_LAYOUT_VIEW (self), &rgba);
+ else
+ goto unset_primary_color;
+
+ if (foreground_set && foreground != NULL && gdk_rgba_parse (&rgba, foreground))
+ ide_layout_view_set_primary_color_fg (IDE_LAYOUT_VIEW (self), &rgba);
+ else
+ ide_layout_view_set_primary_color_fg (IDE_LAYOUT_VIEW (self), NULL);
+
+ return;
+
+unset_primary_color:
+ ide_layout_view_set_primary_color_bg (IDE_LAYOUT_VIEW (self), NULL);
+ ide_layout_view_set_primary_color_fg (IDE_LAYOUT_VIEW (self), NULL);
+}
+
+static gboolean
+grid_get_mapping (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ if (g_variant_get_boolean (variant))
+ g_value_set_enum (value, GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID);
+ else
+ g_value_set_enum (value, GTK_SOURCE_BACKGROUND_PATTERN_TYPE_NONE);
+
+ return TRUE;
+}
+
+static gboolean
+scheme_get_mapping (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GtkSourceStyleSchemeManager *manager = gtk_source_style_scheme_manager_get_default ();
+ const gchar *name = g_variant_get_string (variant, NULL);
+ GtkSourceStyleScheme *scheme = NULL;
+
+ if (name != NULL)
+ scheme = gtk_source_style_scheme_manager_get_scheme (manager, name);
+ g_value_set_object (value, scheme);
+
+ return TRUE;
+}
+
+static void
ide_debugger_view_destroy (GtkWidget *widget)
{
IdeDebuggerView *self = (IdeDebuggerView *)widget;
+ g_clear_object (&self->editor_settings);
g_clear_object (&self->file);
GTK_WIDGET_CLASS (ide_debugger_view_parent_class)->destroy (widget);
@@ -77,6 +155,24 @@ ide_debugger_view_init (IdeDebuggerView *self)
"visible", TRUE,
NULL);
gtk_source_gutter_insert (gutter, GTK_SOURCE_GUTTER_RENDERER (self->breakpoints_gutter), -100);
+
+ g_signal_connect_swapped (self->source_buffer,
+ "notify::style-scheme",
+ G_CALLBACK (notify_style_scheme),
+ self);
+ notify_style_scheme (self, NULL, self->source_buffer);
+
+ self->editor_settings = g_settings_new ("org.gnome.builder.editor");
+
+ g_settings_bind_with_mapping (self->editor_settings, "show-grid-lines",
+ self->source_view, "background-pattern",
+ G_SETTINGS_BIND_GET,
+ grid_get_mapping, NULL, NULL, NULL);
+
+ g_settings_bind_with_mapping (self->editor_settings, "style-scheme-name",
+ self->source_buffer, "style-scheme",
+ G_SETTINGS_BIND_GET,
+ scheme_get_mapping, NULL, NULL, NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]