[gnome-builder] source-style-scheme: add helper to sync styles to text tags
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] source-style-scheme: add helper to sync styles to text tags
- Date: Thu, 3 Mar 2016 05:45:55 +0000 (UTC)
commit 0e44a1d5f156c9056801b1eec40856ff82a5f8ec
Author: Christian Hergert <chergert redhat com>
Date: Wed Mar 2 21:36:18 2016 -0800
source-style-scheme: add helper to sync styles to text tags
https://bugzilla.gnome.org/show_bug.cgi?id=762505
libide/Makefile.am | 2 +
libide/ide-source-style-scheme.c | 94 ++++++++++++++++++++++++++++++++++++++
libide/ide-source-style-scheme.h | 32 +++++++++++++
libide/ide.h | 1 +
4 files changed, 129 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index c6e5c93..0159ee5 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -112,6 +112,7 @@ libide_1_0_la_public_headers = \
ide-source-snippet.h \
ide-source-snippets-manager.h \
ide-source-snippets.h \
+ ide-source-style-scheme.h \
ide-source-view-mode.h \
ide-source-view.h \
ide-subprocess-launcher.h \
@@ -263,6 +264,7 @@ libide_1_0_la_public_sources = \
ide-source-snippet.c \
ide-source-snippets-manager.c \
ide-source-snippets.c \
+ ide-source-style-scheme.c \
ide-source-view-mode.c \
ide-source-view.c \
ide-subprocess-launcher.c \
diff --git a/libide/ide-source-style-scheme.c b/libide/ide-source-style-scheme.c
new file mode 100644
index 0000000..bb5012c
--- /dev/null
+++ b/libide/ide-source-style-scheme.c
@@ -0,0 +1,94 @@
+/* ide-source-style-scheme.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+
+#include "ide-source-style-scheme.h"
+
+void
+ide_source_style_scheme_apply_style (GtkSourceStyleScheme *style_scheme,
+ const gchar *style_name,
+ GtkTextTag *tag)
+{
+ g_autofree gchar *foreground = NULL;
+ g_autofree gchar *background = NULL;
+ g_autofree gchar *tag_name = NULL;
+ GtkSourceStyle *style;
+ const gchar *colon;
+ gboolean foreground_set = FALSE;
+ gboolean background_set = FALSE;
+ gboolean bold = FALSE;
+ gboolean bold_set = FALSE;
+ gboolean underline = FALSE;
+ gboolean underline_set = FALSE;
+ gboolean italic = FALSE;
+ gboolean italic_set = FALSE;
+
+ g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (style_scheme));
+ g_return_if_fail (style_name != NULL);
+
+ g_object_set (tag,
+ "foreground-set", FALSE,
+ "background-set", FALSE,
+ "weight-set", FALSE,
+ "underline-set", FALSE,
+ "style-set", FALSE,
+ NULL);
+
+ style = gtk_source_style_scheme_get_style (style_scheme, style_name);
+
+ if (style == NULL && (colon = strchr (style_name, ':')))
+ {
+ gchar defname[64];
+
+ g_snprintf (defname, sizeof defname, "def%s", colon);
+
+ style = gtk_source_style_scheme_get_style (style_scheme, defname);
+
+ if (style == NULL)
+ return;
+ }
+
+ g_object_get (style,
+ "background", &background,
+ "background-set", &background_set,
+ "foreground", &foreground,
+ "foreground-set", &foreground_set,
+ "bold", &bold,
+ "bold-set", &bold_set,
+ "underline", &underline,
+ "underline-set", &underline_set,
+ "italic", &italic,
+ "italic-set", &italic_set,
+ NULL);
+
+ if (background_set)
+ g_object_set (tag, "background", background, NULL);
+
+ if (foreground_set)
+ g_object_set (tag, "foreground", foreground, NULL);
+
+ if (bold_set && bold)
+ g_object_set (tag, "weight", PANGO_WEIGHT_BOLD, NULL);
+
+ if (italic_set && italic)
+ g_object_set (tag, "style", PANGO_STYLE_ITALIC, NULL);
+
+ if (underline_set && underline)
+ g_object_set (tag, "underline", PANGO_UNDERLINE_SINGLE, NULL);
+}
diff --git a/libide/ide-source-style-scheme.h b/libide/ide-source-style-scheme.h
new file mode 100644
index 0000000..118656f
--- /dev/null
+++ b/libide/ide-source-style-scheme.h
@@ -0,0 +1,32 @@
+/* ide-source-style-scheme.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_SOURCE_STYLE_SCHEME_H
+#define IDE_SOURCE_STYLE_SCHEME_H
+
+#include <gtksourceview/gtksource.h>
+
+G_BEGIN_DECLS
+
+void ide_source_style_scheme_apply_style (GtkSourceStyleScheme *style_scheme,
+ const gchar *style,
+ GtkTextTag *tag);
+
+G_END_DECLS
+
+#endif /* IDE_SOURCE_STYLE_SCHEME_H */
diff --git a/libide/ide.h b/libide/ide.h
index 14a35b0..d61fa87 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -106,6 +106,7 @@ G_BEGIN_DECLS
#include "ide-source-snippet.h"
#include "ide-source-snippets-manager.h"
#include "ide-source-snippets.h"
+#include "ide-source-style-scheme.h"
#include "ide-source-view.h"
#include "ide-subprocess-launcher.h"
#include "ide-symbol-resolver.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]