[gnome-builder] plugins: Introduce new quick-highlight plugin



commit 686ed940d375548566eba182e5642893921871d7
Author: Martin Blanchard <tchaik gmx com>
Date:   Sat Aug 27 13:16:58 2016 +0200

    plugins: Introduce new quick-highlight plugin
    
    Quick Highlight is a simple plugin that highlight every occurences of
    selected text. This first implementation relies on the GtkSourceView
    serch infrastructure for matching text.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770477

 configure.ac                                       |    2 +
 plugins/Makefile.am                                |    1 +
 plugins/quick-highlight/Makefile.am                |   22 ++
 plugins/quick-highlight/configure.ac               |   12 ++
 .../quick-highlight/gbp-quick-highlight-plugin.c   |   30 +++
 .../gbp-quick-highlight-view-addin.c               |  206 ++++++++++++++++++++
 .../gbp-quick-highlight-view-addin.h               |   32 +++
 plugins/quick-highlight/quick-highlight.plugin     |    7 +
 8 files changed, 312 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index eb1f022..7c33b2f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -304,6 +304,7 @@ m4_include([plugins/mingw/configure.ac])
 m4_include([plugins/project-tree/configure.ac])
 m4_include([plugins/python-gi-imports-completion/configure.ac])
 m4_include([plugins/python-pack/configure.ac])
+m4_include([plugins/quick-highlight/configure.ac])
 m4_include([plugins/support/configure.ac])
 m4_include([plugins/symbol-tree/configure.ac])
 m4_include([plugins/sysmon/configure.ac])
@@ -592,6 +593,7 @@ echo "  Project Tree ......................... : ${enable_project_tree_plugin}"
 echo "  Python GObject Introspection ......... : ${enable_python_gi_imports_completion_plugin}"
 echo "  Python Jedi Autocompletion ........... : ${enable_jedi_plugin}"
 echo "  Python Language Pack ................. : ${enable_python_pack_plugin}"
+echo "  Quick Highlight ...................... : ${enable_quick_highlight_plugin}"
 echo "  Support .............................. : ${enable_support_plugin}"
 echo "  System Monitor ....................... : ${enable_sysmon_plugin}"
 echo "  Sysprof System Profiler .............. : ${enable_sysprof_plugin}"
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 8d740e2..21ed04b 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -27,6 +27,7 @@ SUBDIRS = \
        project-tree \
        python-gi-imports-completion \
        python-pack \
+       quick-highlight \
        support \
        symbol-tree \
        sysmon \
diff --git a/plugins/quick-highlight/Makefile.am b/plugins/quick-highlight/Makefile.am
new file mode 100644
index 0000000..f067efd
--- /dev/null
+++ b/plugins/quick-highlight/Makefile.am
@@ -0,0 +1,22 @@
+if ENABLE_QUICK_HIGHLIGHT_PLUGIN
+
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-builder/plugins
+plugin_LTLIBRARIES = libquick-highlight-plugin.la
+dist_plugin_DATA = quick-highlight.plugin
+
+libquick_highlight_plugin_la_SOURCES = \
+       gbp-quick-highlight-plugin.c \
+       gbp-quick-highlight-view-addin.c \
+       gbp-quick-highlight-view-addin.h \
+       $(NULL)
+
+libquick_highlight_plugin_la_CFLAGS = $(PLUGIN_CFLAGS)
+libquick_highlight_plugin_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+
+include $(top_srcdir)/plugins/Makefile.plugin
+
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/quick-highlight/configure.ac b/plugins/quick-highlight/configure.ac
new file mode 100644
index 0000000..16e11d7
--- /dev/null
+++ b/plugins/quick-highlight/configure.ac
@@ -0,0 +1,12 @@
+# --enable-quick-highlight=yes/no
+AC_ARG_ENABLE([quick-highlight-plugin],
+              [AS_HELP_STRING([--enable-quick-highlight=@<:@yes/no@:>@],
+                              [Build with support for quick symbol highlight.])],
+              [enable_quick_highlight_plugin=$enableval],
+              [enable_quick_highlight_plugin=yes])
+
+# for if ENABLE_SYSMON_PLUGIN in Makefile.am
+AM_CONDITIONAL(ENABLE_QUICK_HIGHLIGHT_PLUGIN, test x$enable_quick_highlight_plugin != xno)
+
+# Ensure our makefile is generated by autoconf
+AC_CONFIG_FILES([plugins/quick-highlight/Makefile])
diff --git a/plugins/quick-highlight/gbp-quick-highlight-plugin.c 
b/plugins/quick-highlight/gbp-quick-highlight-plugin.c
new file mode 100644
index 0000000..d359ca3
--- /dev/null
+++ b/plugins/quick-highlight/gbp-quick-highlight-plugin.c
@@ -0,0 +1,30 @@
+/* gbp-quick-highlight-plugin.c
+ *
+ * Copyright (C) 2016 Martin Blanchard <tchaik gmx 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 <libpeas/peas.h>
+#include <ide.h>
+
+#include "gbp-quick-highlight-view-addin.h"
+
+void
+peas_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_EDITOR_VIEW_ADDIN,
+                                              GBP_TYPE_QUICK_HIGHLIGHT_VIEW_ADDIN);
+}
diff --git a/plugins/quick-highlight/gbp-quick-highlight-view-addin.c 
b/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
new file mode 100644
index 0000000..e68b25c
--- /dev/null
+++ b/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
@@ -0,0 +1,206 @@
+/* gbp-quick-highlight-view-addin.c
+ *
+ * Copyright (C) 2016 Martin Blanchard <tchaik gmx 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 <glib/gi18n.h>
+#include <ide.h>
+
+#include "gbp-quick-highlight-view-addin.h"
+
+struct _GbpQuickHighlightViewAddin
+{
+  GObject                  parent_instance;
+
+  IdeEditorView           *editor_view;
+
+  GtkSourceSearchContext  *search_context;
+  GtkSourceSearchSettings *search_settings;
+};
+
+static void editor_view_addin_iface_init (IdeEditorViewAddinInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GbpQuickHighlightViewAddin,
+                        gbp_quick_highlight_view_addin,
+                        G_TYPE_OBJECT,
+                        0,
+                        G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_VIEW_ADDIN,
+                                               editor_view_addin_iface_init))
+
+static void
+gbp_quick_highlight_view_addin_class_init (GbpQuickHighlightViewAddinClass *klass)
+{
+}
+
+static void
+gbp_quick_highlight_view_addin_init (GbpQuickHighlightViewAddin *self)
+{
+}
+
+static void
+gbp_quick_highlight_view_addin_change_style (GtkSourceBuffer *buffer,
+                                             GParamSpec      *pspec,
+                                             gpointer         user_data)
+{
+  GbpQuickHighlightViewAddin *self;
+  GtkSourceStyleScheme *style_scheme;
+  GtkSourceStyle *style;
+  gchar *text;
+
+  g_assert (GTK_SOURCE_IS_BUFFER (buffer));
+
+  self = GBP_QUICK_HIGHLIGHT_VIEW_ADDIN (user_data);
+
+  text = g_strdup (gtk_source_search_settings_get_search_text (self->search_settings));
+
+  gtk_source_search_settings_set_search_text (self->search_settings, NULL);
+  gtk_source_search_context_set_highlight (self->search_context, FALSE);
+
+  style_scheme = gtk_source_buffer_get_style_scheme (buffer);
+  style = gtk_source_style_scheme_get_style (style_scheme, "current-line");
+
+  gtk_source_search_context_set_match_style (self->search_context, style);
+
+  if (text != NULL && strlen (text) > 0)
+    {
+      gtk_source_search_settings_set_search_text (self->search_settings, text);
+      gtk_source_search_context_set_highlight (self->search_context, TRUE);
+    }
+
+  g_free (text);
+}
+
+static void
+gbp_quick_highlight_view_addin_match (GtkTextBuffer *buffer,
+                                      GtkTextIter   *location,
+                                      GtkTextMark   *mark,
+                                      gpointer       user_data)
+{
+  GbpQuickHighlightViewAddin *self;
+  GtkTextMark *insert_mark;
+  GtkTextIter begin;
+  GtkTextIter end;
+  gchar *text;
+
+  g_assert (GTK_IS_TEXT_BUFFER (buffer));
+
+  self = GBP_QUICK_HIGHLIGHT_VIEW_ADDIN (user_data);
+
+  insert_mark = gtk_text_buffer_get_insert (buffer);
+  if (insert_mark != mark)
+    return;
+
+  if (gtk_text_buffer_get_selection_bounds (buffer, &begin, &end))
+    {
+      text = gtk_text_buffer_get_text (buffer, &begin, &end, FALSE);
+
+      if (text != NULL && g_strstrip (text) != NULL)
+        {
+          gtk_source_search_settings_set_search_text (self->search_settings, text);
+          gtk_source_search_context_set_highlight (self->search_context, TRUE);
+        }
+      else
+        {
+          gtk_source_search_settings_set_search_text (self->search_settings, NULL);
+          gtk_source_search_context_set_highlight (self->search_context, FALSE);
+        }
+
+      g_free (text);
+    }
+  else
+    {
+      gtk_source_search_settings_set_search_text (self->search_settings, NULL);
+      gtk_source_search_context_set_highlight (self->search_context, FALSE);
+    }
+}
+
+static void
+gbp_quick_highlight_view_addin_load (IdeEditorViewAddin *addin,
+                                     IdeEditorView      *view)
+{
+  GbpQuickHighlightViewAddin *self;
+  GtkSourceStyleScheme *style_scheme;
+  GtkSourceStyle *style;
+  GtkSourceBuffer *buffer;
+
+  g_assert (GBP_IS_QUICK_HIGHLIGHT_VIEW_ADDIN (addin));
+  g_assert (IDE_IS_EDITOR_VIEW (view));
+
+  self = GBP_QUICK_HIGHLIGHT_VIEW_ADDIN (addin);
+
+  self->editor_view = view;
+
+  buffer = GTK_SOURCE_BUFFER (ide_editor_view_get_document (view));
+
+  self->search_settings = g_object_new (GTK_SOURCE_TYPE_SEARCH_SETTINGS,
+                                        "search-text", NULL,
+                                        NULL);
+  self->search_context = g_object_new (GTK_SOURCE_TYPE_SEARCH_CONTEXT,
+                                       "buffer", buffer,
+                                       "highlight", FALSE,
+                                       "settings", self->search_settings,
+                                       NULL);
+
+  style_scheme = gtk_source_buffer_get_style_scheme (buffer);
+  style = gtk_source_style_scheme_get_style (style_scheme, "current-line");
+
+  gtk_source_search_context_set_match_style (self->search_context, style);
+
+  g_signal_connect_object (buffer,
+                           "notify::style-scheme",
+                           G_CALLBACK (gbp_quick_highlight_view_addin_change_style),
+                           self,
+                           G_CONNECT_AFTER);
+  g_signal_connect_object (buffer,
+                           "mark-set",
+                           G_CALLBACK (gbp_quick_highlight_view_addin_match),
+                           self,
+                           G_CONNECT_AFTER);
+}
+
+static void
+gbp_quick_highlight_view_addin_unload (IdeEditorViewAddin *addin,
+                                       IdeEditorView      *view)
+{
+  GbpQuickHighlightViewAddin *self;
+  GtkSourceBuffer *buffer;
+
+  g_assert (GBP_IS_QUICK_HIGHLIGHT_VIEW_ADDIN (addin));
+
+  self = GBP_QUICK_HIGHLIGHT_VIEW_ADDIN (addin);
+
+  buffer = GTK_SOURCE_BUFFER (ide_editor_view_get_document (view));
+
+  g_signal_handlers_disconnect_by_func (buffer,
+                                        G_CALLBACK (gbp_quick_highlight_view_addin_change_style),
+                                        self);
+  g_signal_handlers_disconnect_by_func (buffer,
+                                        G_CALLBACK (gbp_quick_highlight_view_addin_match),
+                                        self);
+
+  g_clear_object (&self->search_settings);
+  g_clear_object (&self->search_context);
+
+  self->editor_view = NULL;
+}
+
+static void
+editor_view_addin_iface_init (IdeEditorViewAddinInterface *iface)
+{
+  iface->load = gbp_quick_highlight_view_addin_load;
+  iface->unload = gbp_quick_highlight_view_addin_unload;
+}
diff --git a/plugins/quick-highlight/gbp-quick-highlight-view-addin.h 
b/plugins/quick-highlight/gbp-quick-highlight-view-addin.h
new file mode 100644
index 0000000..cd830f8
--- /dev/null
+++ b/plugins/quick-highlight/gbp-quick-highlight-view-addin.h
@@ -0,0 +1,32 @@
+/* gbp-quick-highlight-view-addin.h
+ *
+ * Copyright (C) 2016 Martin Blanchard <tchaik gmx 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_VIEW_ADDIN_H
+#define GBP_QUICK_HIGHLIGHT_VIEW_ADDIN_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_QUICK_HIGHLIGHT_VIEW_ADDIN (gbp_quick_highlight_view_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpQuickHighlightViewAddin, gbp_quick_highlight_view_addin, GBP, 
QUICK_HIGHLIGHT_VIEW_ADDIN, GObject)
+
+G_END_DECLS
+
+#endif /* GBP_QUICK_HIGHLIGHT_VIEW_ADDIN_H */
diff --git a/plugins/quick-highlight/quick-highlight.plugin b/plugins/quick-highlight/quick-highlight.plugin
new file mode 100644
index 0000000..aaf78ae
--- /dev/null
+++ b/plugins/quick-highlight/quick-highlight.plugin
@@ -0,0 +1,7 @@
+[Plugin]
+Module=quick-highlight-plugin
+Name=Quick Highlight
+Description=Highlights every occurrences of selected text
+Authors=Martin Blanchard <tchaik gmx com>
+Copyright=Copyright © 2016 Martin Blanchard
+Builtin=true


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