[gtksourceview/wip/search-start-signal: 1/2] Add private search-start signal
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/search-start-signal: 1/2] Add private search-start signal
- Date: Wed, 10 Aug 2016 13:42:38 +0000 (UTC)
commit 7cc855e82fe3452bcf4581a6138e61a50e9429fa
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Aug 10 12:57:11 2016 +0200
Add private search-start signal
https://bugzilla.gnome.org/show_bug.cgi?id=742550
docs/reference/Makefile.am | 1 +
gtksourceview/Makefile.am | 2 +
gtksourceview/gtksourcebufferinternal.c | 117 +++++++++++++++++++++++++++++++
gtksourceview/gtksourcebufferinternal.h | 48 +++++++++++++
gtksourceview/gtksourcesearchcontext.c | 9 +++
gtksourceview/gtksourcetypes-private.h | 1 +
gtksourceview/gtksourceview.c | 39 ++++++++++
po/POTFILES.in | 1 +
8 files changed, 218 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 1e85a23..7da1e9e 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -34,6 +34,7 @@ IGNORE_HFILES = \
gtksource.h \
gtksourcebuffer-private.h \
gtksourcebufferinputstream.h \
+ gtksourcebufferinternal.h \
gtksourcebufferoutputstream.h \
gtksourcecompletioncontainer.h \
gtksourcecompletionmodel.h \
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index e304301..b86eccf 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -99,6 +99,7 @@ libgtksourceview_private_headers = \
gconstructor.h \
gtksourcebuffer-private.h \
gtksourcebufferinputstream.h \
+ gtksourcebufferinternal.h \
gtksourcebufferoutputstream.h \
gtksourcecompletioncontainer.h \
gtksourcecompletionmodel.h \
@@ -124,6 +125,7 @@ libgtksourceview_private_headers = \
libgtksourceview_private_c_files = \
gtksourcebufferinputstream.c \
+ gtksourcebufferinternal.c \
gtksourcebufferoutputstream.c \
gtksourcecompletioncontainer.c \
gtksourcecompletionmodel.c \
diff --git a/gtksourceview/gtksourcebufferinternal.c b/gtksourceview/gtksourcebufferinternal.c
new file mode 100644
index 0000000..989f5f6
--- /dev/null
+++ b/gtksourceview/gtksourcebufferinternal.c
@@ -0,0 +1,117 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* gtksourcebufferinternal.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "gtksourcebufferinternal.h"
+#include "gtksourcebuffer.h"
+#include "gtksourcesearchcontext.h"
+
+/* A private extension of GtkSourceBuffer, to add private signals and
+ * properties.
+ */
+
+struct _GtkSourceBufferInternal
+{
+ GObject parent_instance;
+};
+
+enum
+{
+ SIGNAL_SEARCH_START,
+ N_SIGNALS
+};
+
+#define GTK_SOURCE_BUFFER_INTERNAL_KEY "gtk-source-buffer-internal-key"
+
+static guint signals[N_SIGNALS];
+
+G_DEFINE_TYPE (GtkSourceBufferInternal, _gtk_source_buffer_internal, G_TYPE_OBJECT)
+
+static void
+_gtk_source_buffer_internal_class_init (GtkSourceBufferInternalClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ /*
+ * GtkSourceBufferInternal::search-start:
+ * @buffer_internal: the object that received the signal.
+ * @search_context: the #GtkSourceSearchContext.
+ *
+ * The ::search-start signal is emitted when a search is starting.
+ */
+ signals[SIGNAL_SEARCH_START] =
+ g_signal_new ("search-start",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 1, GTK_SOURCE_TYPE_SEARCH_CONTEXT);
+}
+
+static void
+_gtk_source_buffer_internal_init (GtkSourceBufferInternal *buffer_internal)
+{
+}
+
+/*
+ * _gtk_source_buffer_internal_get_from_buffer:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns the #GtkSourceBufferInternal object of @buffer. The returned object
+ * is guaranteed to be the same for the lifetime of @buffer.
+ *
+ * Returns: (transfer none): the #GtkSourceBufferInternal object of @buffer.
+ */
+GtkSourceBufferInternal *
+_gtk_source_buffer_internal_get_from_buffer (GtkSourceBuffer *buffer)
+{
+ GtkSourceBufferInternal *buffer_internal;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
+
+ buffer_internal = g_object_get_data (G_OBJECT (buffer), GTK_SOURCE_BUFFER_INTERNAL_KEY);
+
+ if (buffer_internal == NULL)
+ {
+ buffer_internal = g_object_new (GTK_SOURCE_TYPE_BUFFER_INTERNAL, NULL);
+
+ g_object_set_data_full (G_OBJECT (buffer),
+ GTK_SOURCE_BUFFER_INTERNAL_KEY,
+ buffer_internal,
+ g_object_unref);
+ }
+
+ g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_INTERNAL (buffer_internal), NULL);
+ return buffer_internal;
+}
+
+void
+_gtk_source_buffer_internal_emit_search_start (GtkSourceBufferInternal *buffer_internal,
+ GtkSourceSearchContext *search_context)
+{
+ g_return_if_fail (GTK_SOURCE_IS_BUFFER_INTERNAL (buffer_internal));
+ g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search_context));
+
+ g_signal_emit (buffer_internal,
+ signals[SIGNAL_SEARCH_START],
+ 0,
+ search_context);
+}
diff --git a/gtksourceview/gtksourcebufferinternal.h b/gtksourceview/gtksourcebufferinternal.h
new file mode 100644
index 0000000..e6b0dbc
--- /dev/null
+++ b/gtksourceview/gtksourcebufferinternal.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* gtksourcebufferinternal.h
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef GTK_SOURCE_BUFFER_INTERNAL_H
+#define GTK_SOURCE_BUFFER_INTERNAL_H
+
+#include <glib-object.h>
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_BUFFER_INTERNAL (_gtk_source_buffer_internal_get_type ())
+
+G_GNUC_INTERNAL
+G_DECLARE_FINAL_TYPE (GtkSourceBufferInternal, _gtk_source_buffer_internal,
+ GTK_SOURCE, BUFFER_INTERNAL,
+ GObject)
+
+G_GNUC_INTERNAL
+GtkSourceBufferInternal *
+ _gtk_source_buffer_internal_get_from_buffer (GtkSourceBuffer *buffer);
+
+G_GNUC_INTERNAL
+void _gtk_source_buffer_internal_emit_search_start (GtkSourceBufferInternal
*buffer_internal,
+ GtkSourceSearchContext
*search_context);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_BUFFER_INTERNAL_H */
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 4f6b2f1..bc48630 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -27,6 +27,7 @@
#include "gtksourcesearchsettings.h"
#include "gtksourcebuffer.h"
#include "gtksourcebuffer-private.h"
+#include "gtksourcebufferinternal.h"
#include "gtksourcestyle.h"
#include "gtksourcestylescheme.h"
#include "gtksourceutils.h"
@@ -2332,6 +2333,7 @@ update (GtkSourceSearchContext *search)
{
GtkTextIter start;
GtkTextIter end;
+ GtkSourceBufferInternal *buffer_internal;
if (search->priv->buffer == NULL)
{
@@ -2345,6 +2347,13 @@ update (GtkSourceSearchContext *search)
gtk_text_buffer_get_bounds (search->priv->buffer, &start, &end);
add_subregion_to_scan (search, &start, &end);
+
+ /* Notify the GtkSourceViews that the search is starting, so that
+ * _gtk_source_search_context_update_highlight() can be called for the
+ * visible regions of the buffer.
+ */
+ buffer_internal = _gtk_source_buffer_internal_get_from_buffer (GTK_SOURCE_BUFFER
(search->priv->buffer));
+ _gtk_source_buffer_internal_emit_search_start (buffer_internal, search);
}
static void
diff --git a/gtksourceview/gtksourcetypes-private.h b/gtksourceview/gtksourcetypes-private.h
index 857a4b2..f613625 100644
--- a/gtksourceview/gtksourcetypes-private.h
+++ b/gtksourceview/gtksourcetypes-private.h
@@ -27,6 +27,7 @@
G_BEGIN_DECLS
typedef struct _GtkSourceBufferInputStream GtkSourceBufferInputStream;
+typedef struct _GtkSourceBufferInternal GtkSourceBufferInternal;
typedef struct _GtkSourceBufferOutputStream GtkSourceBufferOutputStream;
typedef struct _GtkSourceCompletionContainer GtkSourceCompletionContainer;
typedef struct _GtkSourceCompletionModel GtkSourceCompletionModel;
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 31daaaf..51e0547 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -36,6 +36,7 @@
#include "gtksourcebuffer.h"
#include "gtksourcebuffer-private.h"
+#include "gtksourcebufferinternal.h"
#include "gtksourceview-i18n.h"
#include "gtksourceview-enumtypes.h"
#include "gtksourcemark.h"
@@ -48,6 +49,7 @@
#include "gtksourcegutterrendererlines.h"
#include "gtksourcegutterrenderermarks.h"
#include "gtksourceiter.h"
+#include "gtksourcesearchcontext.h"
#include "gtksourcespacedrawer.h"
/**
@@ -1430,6 +1432,26 @@ highlight_updated_cb (GtkSourceBuffer *buffer,
}
static void
+search_start_cb (GtkSourceBufferInternal *buffer_internal,
+ GtkSourceSearchContext *search_context,
+ GtkSourceView *view)
+{
+ GtkTextIter visible_start;
+ GtkTextIter visible_end;
+ GtkSourceBuffer *buffer_search;
+
+ get_visible_region (GTK_TEXT_VIEW (view), &visible_start, &visible_end);
+
+ buffer_search = gtk_source_search_context_get_buffer (search_context);
+ g_assert (buffer_search == view->priv->source_buffer);
+
+ _gtk_source_search_context_update_highlight (search_context,
+ &visible_start,
+ &visible_end,
+ FALSE);
+}
+
+static void
source_mark_updated_cb (GtkSourceBuffer *buffer,
GtkSourceMark *mark,
GtkTextView *text_view)
@@ -1461,6 +1483,8 @@ remove_source_buffer (GtkSourceView *view)
{
if (view->priv->source_buffer != NULL)
{
+ GtkSourceBufferInternal *buffer_internal;
+
g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
highlight_updated_cb,
view);
@@ -1477,6 +1501,12 @@ remove_source_buffer (GtkSourceView *view)
implicit_trailing_newline_changed_cb,
view);
+ buffer_internal = _gtk_source_buffer_internal_get_from_buffer (view->priv->source_buffer);
+
+ g_signal_handlers_disconnect_by_func (buffer_internal,
+ search_start_cb,
+ view);
+
g_object_unref (view->priv->source_buffer);
view->priv->source_buffer = NULL;
}
@@ -1495,6 +1525,8 @@ set_source_buffer (GtkSourceView *view,
if (GTK_SOURCE_IS_BUFFER (buffer))
{
+ GtkSourceBufferInternal *buffer_internal;
+
view->priv->source_buffer = g_object_ref (buffer);
g_signal_connect (buffer,
@@ -1516,6 +1548,13 @@ set_source_buffer (GtkSourceView *view,
"notify::implicit-trailing-newline",
G_CALLBACK (implicit_trailing_newline_changed_cb),
view);
+
+ buffer_internal = _gtk_source_buffer_internal_get_from_buffer (view->priv->source_buffer);
+
+ g_signal_connect (buffer_internal,
+ "search-start",
+ G_CALLBACK (search_start_cb),
+ view);
}
gtk_source_view_update_style_scheme (view);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ad05598..aa0c00e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ data/styles/styles.pot
gtksourceview/completion-providers/words/gtksourcecompletionwords.c
gtksourceview/gtksourcebuffer.c
gtksourceview/gtksourcebufferinputstream.c
+gtksourceview/gtksourcebufferinternal.c
gtksourceview/gtksourcebufferoutputstream.c
gtksourceview/gtksourcecompletion.c
gtksourceview/gtksourcecompletioncontainer.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]