[gtksourceview/wip/regex-search: 1/2] Add gtk_source_buffer_disable_search_highlighting()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/regex-search: 1/2] Add gtk_source_buffer_disable_search_highlighting()
- Date: Thu, 1 Aug 2013 13:53:07 +0000 (UTC)
commit e7b0ec4f7cbf64619b3addf5f7dbea75af17f749
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Aug 1 14:15:15 2013 +0200
Add gtk_source_buffer_disable_search_highlighting()
The buffer must have a list of search contexts. It is done with
_gtk_source_buffer_add_search_context(), and the buffer holds a weak
reference to the context. It must not be the other way around, the
context must have a strong reference to the buffer, because the context
needs the buffer. On the other hand, the buffer can work without search
contexts.
gtksourceview/gtksourcebuffer-private.h | 4 ++
gtksourceview/gtksourcebuffer.c | 69 ++++++++++++++++++++++++++++++-
gtksourceview/gtksourcebuffer.h | 2 +
gtksourceview/gtksourcesearchcontext.c | 19 ++++++++-
4 files changed, 91 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer-private.h b/gtksourceview/gtksourcebuffer-private.h
index 9273380..10ac6d4 100644
--- a/gtksourceview/gtksourcebuffer-private.h
+++ b/gtksourceview/gtksourcebuffer-private.h
@@ -46,6 +46,10 @@ GtkSourceMark *_gtk_source_buffer_source_mark_prev
(GtkSourceBuffer *bu
G_GNUC_INTERNAL
GtkTextTag *_gtk_source_buffer_get_bracket_match_tag (GtkSourceBuffer *buffer);
+G_GNUC_INTERNAL
+void _gtk_source_buffer_add_search_context (GtkSourceBuffer *buffer,
+ GtkSourceSearchContext
*search_context);
+
G_END_DECLS
#endif /* __GTK_SOURCE_BUFFER_PRIVATE_H__ */
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 737cf48..f7d50e2 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -153,6 +153,8 @@ struct _GtkSourceBufferPrivate
GtkSourceUndoManager *undo_manager;
gint max_undo_levels;
+ GList *search_contexts;
+
guint highlight_syntax : 1;
guint highlight_brackets : 1;
guint constructed : 1;
@@ -1539,6 +1541,8 @@ _gtk_source_buffer_update_highlight (GtkSourceBuffer *buffer,
const GtkTextIter *end,
gboolean synchronous)
{
+ GList *l;
+
g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
if (buffer->priv->highlight_engine != NULL)
@@ -1549,8 +1553,15 @@ _gtk_source_buffer_update_highlight (GtkSourceBuffer *buffer,
synchronous);
}
- /* TODO: update highlighting for the currently highlighted search
- * context. */
+ for (l = buffer->priv->search_contexts; l != NULL; l = l->next)
+ {
+ GtkSourceSearchContext *search_context = l->data;
+
+ _gtk_source_search_context_update_highlight (search_context,
+ start,
+ end,
+ synchronous);
+ }
}
/**
@@ -2491,3 +2502,57 @@ gtk_source_buffer_get_undo_manager (GtkSourceBuffer *buffer)
return buffer->priv->undo_manager;
}
+
+static void
+search_context_weak_notify_cb (GtkSourceBuffer *buffer,
+ GObject *search_context)
+{
+ buffer->priv->search_contexts = g_list_remove (buffer->priv->search_contexts,
+ search_context);
+}
+
+void
+_gtk_source_buffer_add_search_context (GtkSourceBuffer *buffer,
+ GtkSourceSearchContext *search_context)
+{
+ g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
+ g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search_context));
+ g_return_if_fail (gtk_source_search_context_get_buffer (search_context) == buffer);
+
+ if (g_list_find (buffer->priv->search_contexts, search_context) != NULL)
+ {
+ return;
+ }
+
+ buffer->priv->search_contexts = g_list_prepend (buffer->priv->search_contexts,
+ search_context);
+
+ g_object_weak_ref (G_OBJECT (search_context),
+ (GWeakNotify)search_context_weak_notify_cb,
+ buffer);
+}
+
+/**
+ * gtk_source_buffer_disable_search_highlighting:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Disables the search occurrences highlighting, for all
+ * #GtkSourceSearchContext<!-- -->s attached to @buffer. The search highlighting
+ * can be activated again with gtk_source_search_context_set_highlight().
+ *
+ * Since: 3.10
+ */
+void
+gtk_source_buffer_disable_search_highlighting (GtkSourceBuffer *buffer)
+{
+ GList *l;
+
+ g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
+
+ for (l = buffer->priv->search_contexts; l != NULL; l = l->next)
+ {
+ GtkSourceSearchContext *search_context = l->data;
+
+ gtk_source_search_context_set_highlight (search_context, FALSE);
+ }
+}
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 9026ca2..5810d0d 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -180,6 +180,8 @@ GtkSourceUndoManager *gtk_source_buffer_get_undo_manager
(GtkSourceBuffer *buf
void gtk_source_buffer_set_undo_manager (GtkSourceBuffer
*buffer,
GtkSourceUndoManager
*manager);
+void gtk_source_buffer_disable_search_highlighting (GtkSourceBuffer
*buffer);
+
G_END_DECLS
#endif /* __GTK_SOURCE_BUFFER_H__ */
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index b715548..6ec7259 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -22,6 +22,7 @@
#include "gtksourcesearchcontext.h"
#include "gtksourcesearchsettings.h"
#include "gtksourcebuffer.h"
+#include "gtksourcebuffer-private.h"
#include "gtksourcestylescheme.h"
#include "gtksourcestyle-private.h"
#include "gtksourceutils.h"
@@ -57,6 +58,19 @@
* matches, use gtk_source_search_context_replace() and
* gtk_source_search_context_replace_all().
*
+ * The search occurrences are highlighted by default. To disable it, use
+ * gtk_source_search_context_set_highlight(). The
+ * gtk_source_buffer_disable_search_highlighting() convenience function permits
+ * to disable the search highlighting in a buffer. The
+ * #GtkSourceSearchContext:highlight property is in the #GtkSourceSearchContext
+ * class. If the property was in #GtkSourceSearchSettings, calling
+ * gtk_source_buffer_disable_search_highlighting() might disable the
+ * highlighting in other buffers, which would be undesirable. It is therefore
+ * better to have the appearance settings in the #GtkSourceSearchContext class.
+ * You can enable the search highlighting for several
+ * #GtkSourceSearchContext<!-- -->s attached to the same buffer. But, currently,
+ * the same highlighting style is applied.
+ *
* In the GtkSourceView source code, there is an example of how to use the
* search and replace API: see the tests/test-search.c file. It is a mini
* application for the search and replace, with a basic user interface.
@@ -2437,6 +2451,8 @@ set_buffer (GtkSourceSearchContext *search,
G_CALLBACK (sync_found_tag),
search,
G_CONNECT_SWAPPED);
+
+ _gtk_source_buffer_add_search_context (buffer, search);
}
static gint
@@ -3492,7 +3508,8 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
g_return_if_fail (end != NULL);
if (dispose_has_run (search) ||
- is_text_region_empty (search->priv->scan_region))
+ is_text_region_empty (search->priv->scan_region) ||
+ !search->priv->highlight)
{
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]