[gnome-builder] quick-highlight: add preference in Editor section
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] quick-highlight: add preference in Editor section
- Date: Sat, 27 Aug 2016 19:48:14 +0000 (UTC)
commit 52ba38f0deb68cade223423ecfd2e4dfd42abf48
Author: Christian Hergert <chergert redhat com>
Date: Sat Aug 27 12:44:53 2016 -0700
quick-highlight: add preference in Editor section
This allows us to enable/disable the feature of the plugin without
unloading the plugin.
plugins/quick-highlight/Makefile.am | 2 +
.../quick-highlight/gbp-quick-highlight-plugin.c | 4 +
.../gbp-quick-highlight-preferences.c | 86 ++++++++++++++++++++
.../gbp-quick-highlight-preferences.h | 32 +++++++
.../gbp-quick-highlight-view-addin.c | 49 +++++++++++
5 files changed, 173 insertions(+), 0 deletions(-)
---
diff --git a/plugins/quick-highlight/Makefile.am b/plugins/quick-highlight/Makefile.am
index f067efd..e8c8ebd 100644
--- a/plugins/quick-highlight/Makefile.am
+++ b/plugins/quick-highlight/Makefile.am
@@ -10,6 +10,8 @@ libquick_highlight_plugin_la_SOURCES = \
gbp-quick-highlight-plugin.c \
gbp-quick-highlight-view-addin.c \
gbp-quick-highlight-view-addin.h \
+ gbp-quick-highlight-preferences.c \
+ gbp-quick-highlight-preferences.h \
$(NULL)
libquick_highlight_plugin_la_CFLAGS = $(PLUGIN_CFLAGS)
diff --git a/plugins/quick-highlight/gbp-quick-highlight-plugin.c
b/plugins/quick-highlight/gbp-quick-highlight-plugin.c
index d359ca3..1d38adb 100644
--- a/plugins/quick-highlight/gbp-quick-highlight-plugin.c
+++ b/plugins/quick-highlight/gbp-quick-highlight-plugin.c
@@ -20,6 +20,7 @@
#include <ide.h>
#include "gbp-quick-highlight-view-addin.h"
+#include "gbp-quick-highlight-preferences.h"
void
peas_register_types (PeasObjectModule *module)
@@ -27,4 +28,7 @@ peas_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_EDITOR_VIEW_ADDIN,
GBP_TYPE_QUICK_HIGHLIGHT_VIEW_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_PREFERENCES_ADDIN,
+ GBP_TYPE_QUICK_HIGHLIGHT_PREFERENCES);
}
diff --git a/plugins/quick-highlight/gbp-quick-highlight-preferences.c
b/plugins/quick-highlight/gbp-quick-highlight-preferences.c
new file mode 100644
index 0000000..0f57c08
--- /dev/null
+++ b/plugins/quick-highlight/gbp-quick-highlight-preferences.c
@@ -0,0 +1,86 @@
+/* gbp-quick-highlight-preferences.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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-quick-highlight-preferences"
+
+#include <glib/gi18n.h>
+
+#include "gbp-quick-highlight-preferences.h"
+
+struct _GbpQuickHighlightPreferences
+{
+ GObject parent_instance;
+ guint enable_switch;
+};
+
+static void
+gbp_quick_highlight_preferences_load (IdePreferencesAddin *addin,
+ IdePreferences *preferences)
+{
+ GbpQuickHighlightPreferences *self = (GbpQuickHighlightPreferences *)addin;
+
+ g_assert (IDE_IS_PREFERENCES_ADDIN (self));
+ g_assert (IDE_IS_PREFERENCES (preferences));
+
+ self->enable_switch =
+ ide_preferences_add_switch (preferences,
+ "editor",
+ "highlight",
+ "org.gnome.builder.extension-type",
+ "enabled",
+
"/org/gnome/builder/extension-types/quick-highlight-plugin/GbpQuickHighlightViewAddin/",
+ NULL,
+ _("Words matching selection"),
+ _("Highlight all occurrences of words matching the current selection"),
+ /* Translators: the following are keywords used for searching to locate this
preference */
+ _("quick highlight words matching current selection"),
+ 10);
+}
+
+static void
+gbp_quick_highlight_preferences_unload (IdePreferencesAddin *addin,
+ IdePreferences *preferences)
+{
+ GbpQuickHighlightPreferences *self = (GbpQuickHighlightPreferences *)addin;
+
+ g_assert (IDE_IS_PREFERENCES_ADDIN (self));
+ g_assert (IDE_IS_PREFERENCES (preferences));
+
+ ide_preferences_remove_id (preferences, self->enable_switch);
+ self->enable_switch = 0;
+}
+
+static void
+preferences_addin_iface_init (IdePreferencesAddinInterface *iface)
+{
+ iface->load = gbp_quick_highlight_preferences_load;
+ iface->unload = gbp_quick_highlight_preferences_unload;
+}
+
+G_DEFINE_TYPE_EXTENDED (GbpQuickHighlightPreferences, gbp_quick_highlight_preferences, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, preferences_addin_iface_init))
+
+static void
+gbp_quick_highlight_preferences_class_init (GbpQuickHighlightPreferencesClass *klass)
+{
+}
+
+static void
+gbp_quick_highlight_preferences_init (GbpQuickHighlightPreferences *self)
+{
+}
diff --git a/plugins/quick-highlight/gbp-quick-highlight-preferences.h
b/plugins/quick-highlight/gbp-quick-highlight-preferences.h
new file mode 100644
index 0000000..30c4c95
--- /dev/null
+++ b/plugins/quick-highlight/gbp-quick-highlight-preferences.h
@@ -0,0 +1,32 @@
+/* gbp-quick-highlight-preferences.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 GBP_QUICK_HIGHLIGHT_PREFERENCES_H
+#define GBP_QUICK_HIGHLIGHT_PREFERENCES_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_QUICK_HIGHLIGHT_PREFERENCES (gbp_quick_highlight_preferences_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpQuickHighlightPreferences, gbp_quick_highlight_preferences, GBP,
QUICK_HIGHLIGHT_PREFERENCES, GObject)
+
+G_END_DECLS
+
+#endif /* GBP_QUICK_HIGHLIGHT_PREFERENCES_H */
diff --git a/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
b/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
index 428593c..4a8da14 100644
--- a/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
+++ b/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
@@ -30,9 +30,13 @@ struct _GbpQuickHighlightViewAddin
GtkSourceSearchContext *search_context;
GtkSourceSearchSettings *search_settings;
+ GSettings *settings;
gulong notify_style_scheme_handler;
gulong mark_set_handler;
+ gulong changed_enabled_handler;
+
+ guint enabled : 1;
};
static void editor_view_addin_iface_init (IdeEditorViewAddinInterface *iface);
@@ -131,6 +135,36 @@ gbp_quick_highlight_view_addin_match (GtkTextBuffer *buffer,
}
static void
+gbp_quick_highlight_view_addin_enabled_changed (GbpQuickHighlightViewAddin *self,
+ const gchar *key,
+ GSettings *settings)
+{
+ IdeBuffer *buffer;
+ gboolean enabled;
+
+ g_assert (GBP_IS_QUICK_HIGHLIGHT_VIEW_ADDIN (self));
+ g_assert (G_IS_SETTINGS (settings));
+
+ buffer = ide_editor_view_get_document (self->editor_view);
+ enabled = g_settings_get_boolean (settings, "enabled");
+
+ if (!self->enabled && enabled)
+ {
+ g_signal_handler_unblock (buffer, self->notify_style_scheme_handler);
+ g_signal_handler_unblock (buffer, self->mark_set_handler);
+ }
+ else if (self->enabled && !enabled)
+ {
+ g_signal_handler_block (buffer, self->notify_style_scheme_handler);
+ g_signal_handler_block (buffer, self->mark_set_handler);
+ gtk_source_search_settings_set_search_text (self->search_settings, NULL);
+ gtk_source_search_context_set_highlight (self->search_context, FALSE);
+ }
+
+ self->enabled = enabled;
+}
+
+static void
gbp_quick_highlight_view_addin_load (IdeEditorViewAddin *addin,
IdeEditorView *view)
{
@@ -178,6 +212,19 @@ gbp_quick_highlight_view_addin_load (IdeEditorViewAddin *addin,
G_CALLBACK (gbp_quick_highlight_view_addin_match),
self,
G_CONNECT_AFTER);
+
+ /* Use conventions from IdeExtensionSetAdapter */
+ self->settings = g_settings_new_with_path ("org.gnome.builder.extension-type",
+
"/org/gnome/builder/extension-types/quick-highlight-plugin/GbpQuickHighlightViewAddin/");
+
+ self->changed_enabled_handler =
+ g_signal_connect_object (self->settings,
+ "changed::enabled",
+ G_CALLBACK (gbp_quick_highlight_view_addin_enabled_changed),
+ self,
+ G_CONNECT_SWAPPED);
+
+ self->enabled = TRUE;
}
static void
@@ -195,9 +242,11 @@ gbp_quick_highlight_view_addin_unload (IdeEditorViewAddin *addin,
g_signal_handler_disconnect (buffer, self->notify_style_scheme_handler);
g_signal_handler_disconnect (buffer, self->mark_set_handler);
+ g_signal_handler_disconnect (self->settings, self->changed_enabled_handler);
g_clear_object (&self->search_settings);
g_clear_object (&self->search_context);
+ g_clear_object (&self->settings);
self->editor_view = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]