[gnome-builder] code-insight: allow semantic highlighting to be disabled
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] code-insight: allow semantic highlighting to be disabled
- Date: Sat, 16 May 2015 10:45:59 +0000 (UTC)
commit 7d2b92860b9f41293041663919fcf2605420dbe9
Author: Christian Hergert <christian hergert me>
Date: Sat May 16 03:45:53 2015 -0700
code-insight: allow semantic highlighting to be disabled
This gives us a quick and dirty control knob. Obviously default to on.
.../org.gnome.builder.code-insight.gschema.xml | 5 ++
data/ui/gb-preferences-page-insight.ui | 11 +++
libide/ide-highlight-engine.c | 68 ++++++++++++++++++-
3 files changed, 80 insertions(+), 4 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.code-insight.gschema.xml
b/data/gsettings/org.gnome.builder.code-insight.gschema.xml
index 7706af4..7f69aed 100644
--- a/data/gsettings/org.gnome.builder.code-insight.gschema.xml
+++ b/data/gsettings/org.gnome.builder.code-insight.gschema.xml
@@ -15,5 +15,10 @@
<summary>Enable auto-completion of words in document</summary>
<description>If enabled, words within the current document will be available for
auto-completion.</description>
</key>
+ <key name="semantic-highlighting" type="b">
+ <default>true</default>
+ <summary>Enable semantic highlighting</summary>
+ <description>If enabled, additional highlighting will be provided in supported languages based on
information extracted from the source code.</description>
+ </key>
</schema>
</schemalist>
diff --git a/data/ui/gb-preferences-page-insight.ui b/data/ui/gb-preferences-page-insight.ui
index d94507a..1a62a59 100644
--- a/data/ui/gb-preferences-page-insight.ui
+++ b/data/ui/gb-preferences-page-insight.ui
@@ -9,9 +9,20 @@
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
+ <object class="GbPreferencesSwitch" id="semantic_highlighting">
+ <property name="settings">insight_settings</property>
+ <property name="settings-schema-key">semantic-highlighting</property>
+ <property name="title" translatable="yes">Semantic Language Highlighting</property>
+ <property name="description" translatable="yes">Highlight additional syntax based upon
information found in the document.</property>
+ <property name="size-group">control_group</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ <child>
<object class="GtkLabel">
<property name="visible">true</property>
<property name="label" translatable="yes">Auto Completion</property>
+ <property name="margin-top">12</property>
<property name="margin-bottom">6</property>
<property name="xalign">0.0</property>
<style>
diff --git a/libide/ide-highlight-engine.c b/libide/ide-highlight-engine.c
index fe1a43d..04f562d 100644
--- a/libide/ide-highlight-engine.c
+++ b/libide/ide-highlight-engine.c
@@ -36,6 +36,7 @@ struct _IdeHighlightEngine
IdeBuffer *buffer;
IdeHighlighter *highlighter;
+ GSettings *settings;
GtkTextMark *invalid_begin;
GtkTextMark *invalid_end;
@@ -46,6 +47,8 @@ struct _IdeHighlightEngine
guint64 quanta_expiration;
guint work_timeout;
+
+ guint enabled : 1;
};
G_DEFINE_TYPE (IdeHighlightEngine, ide_highlight_engine, G_TYPE_OBJECT)
@@ -357,10 +360,12 @@ ide_highlight_engine_work_timeout_handler (gpointer data)
g_assert (IDE_IS_HIGHLIGHT_ENGINE (self));
- if (ide_highlight_engine_tick (self))
- return G_SOURCE_CONTINUE;
-
- self->work_timeout = 0;
+ if (self->enabled)
+ {
+ if (ide_highlight_engine_tick (self))
+ return G_SOURCE_CONTINUE;
+ self->work_timeout = 0;
+ }
return G_SOURCE_REMOVE;
}
@@ -388,6 +393,9 @@ invalidate_and_highlight (IdeHighlightEngine *self,
g_assert (begin != NULL);
g_assert (end != NULL);
+ if (!self->enabled)
+ return FALSE;
+
if (get_invalidation_area (begin, end))
{
GtkTextIter begin_tmp;
@@ -551,6 +559,29 @@ ide_highlight_engine__notify_style_scheme_cb (IdeHighlightEngine *self,
}
static void
+ide_highlight_engine_clear (IdeHighlightEngine *self)
+{
+ GtkTextIter begin;
+ GtkTextIter end;
+
+ g_assert (IDE_IS_HIGHLIGHT_ENGINE (self));
+
+ if (self->buffer != NULL)
+ {
+ GtkTextBuffer *buffer = GTK_TEXT_BUFFER (self->buffer);
+ GSList *iter;
+
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (self->buffer), &begin, &end);
+
+ for (iter = self->private_tags; iter; iter = iter->next)
+ gtk_text_buffer_remove_tag (buffer, iter->data, &begin, &end);
+
+ for (iter = self->public_tags; iter; iter = iter->next)
+ gtk_text_buffer_remove_tag (buffer, iter->data, &begin, &end);
+ }
+}
+
+static void
ide_highlight_engine_connect_buffer (IdeHighlightEngine *self,
IdeBuffer *buffer)
{
@@ -679,6 +710,26 @@ ide_highlight_engine_set_buffer (IdeHighlightEngine *self,
}
static void
+ide_highlight_engine_settings_changed (IdeHighlightEngine *self,
+ const gchar *key,
+ GSettings *settings)
+{
+ g_assert (IDE_IS_HIGHLIGHT_ENGINE (self));
+ g_assert (G_IS_SETTINGS (settings));
+
+ if (g_settings_get_boolean (settings, "semantic-highlighting"))
+ {
+ self->enabled = TRUE;
+ ide_highlight_engine_rebuild (self);
+ }
+ else
+ {
+ self->enabled = FALSE;
+ ide_highlight_engine_clear (self);
+ }
+}
+
+static void
ide_highlight_engine_dispose (GObject *object)
{
IdeHighlightEngine *self = (IdeHighlightEngine *)object;
@@ -694,6 +745,7 @@ ide_highlight_engine_finalize (GObject *object)
IdeHighlightEngine *self = (IdeHighlightEngine *)object;
g_clear_object (&self->highlighter);
+ g_clear_object (&self->settings);
ide_clear_weak_pointer (&self->buffer);
G_OBJECT_CLASS (ide_highlight_engine_parent_class)->finalize (object);
@@ -777,6 +829,14 @@ ide_highlight_engine_class_init (IdeHighlightEngineClass *klass)
static void
ide_highlight_engine_init (IdeHighlightEngine *self)
{
+ self->settings = g_settings_new ("org.gnome.builder.code-insight");
+ self->enabled = g_settings_get_boolean (self->settings, "semantic-highlighting");
+
+ g_signal_connect_object (self->settings,
+ "changed::semantic-highlighting",
+ G_CALLBACK (ide_highlight_engine_settings_changed),
+ self,
+ G_CONNECT_SWAPPED);
}
IdeHighlightEngine *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]