[gtksourceview/wip/chergert/snippets] wip integrating snippet signals
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/snippets] wip integrating snippet signals
- Date: Tue, 21 Jan 2020 22:15:19 +0000 (UTC)
commit c499a62cb1dd766be84f0cf8a4340ffe6e1f953e
Author: Christian Hergert <chergert redhat com>
Date: Tue Jan 21 14:15:25 2020 -0800
wip integrating snippet signals
gtksourceview/gtksourceview.c | 128 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 128 insertions(+)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 3c316fd7..fb0018ab 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -1611,6 +1611,116 @@ implicit_trailing_newline_changed_cb (GtkSourceBuffer *buffer,
gtk_source_view_queue_draw (view);
}
+static void
+buffer_insert_text_cb (GtkSourceBuffer *buffer,
+ GtkTextIter *location,
+ gchar *text,
+ gint len,
+ GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+ GtkSourceSnippet *snippet;
+
+ g_assert (GTK_SOURCE_IS_BUFFER (buffer));
+ g_assert (location != NULL);
+ g_assert (text != NULL);
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+
+ snippet = g_queue_peek_head (&priv->snippets);
+
+ if (snippet != NULL)
+ {
+ gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
+ _gtk_source_snippet_before_insert_text (snippet,
+ GTK_TEXT_BUFFER (buffer),
+ location,
+ text,
+ len);
+ }
+}
+
+static void
+buffer_after_insert_text_cb (GtkSourceBuffer *buffer,
+ GtkTextIter *location,
+ gchar *text,
+ gint len,
+ GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+ GtkSourceSnippet *snippet;
+
+ g_assert (GTK_SOURCE_IS_BUFFER (buffer));
+ g_assert (location != NULL);
+ g_assert (text != NULL);
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+
+ snippet = g_queue_peek_head (&priv->snippets);
+
+ if (snippet != NULL)
+ {
+ _gtk_source_snippet_after_insert_text (snippet,
+ GTK_TEXT_BUFFER (buffer),
+ location,
+ text,
+ len);
+ gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
+ }
+}
+
+static void
+buffer_delete_range_cb (GtkSourceBuffer *buffer,
+ GtkTextIter *begin,
+ GtkTextIter *end,
+ GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+ GtkSourceSnippet *snippet;
+
+ g_assert (GTK_SOURCE_IS_BUFFER (buffer));
+ g_assert (begin != NULL);
+ g_assert (end != NULL);
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+
+ snippet = g_queue_peek_head (&priv->snippets);
+
+ if (snippet != NULL)
+ {
+ //ide_source_view_block_handlers (self);
+ _gtk_source_snippet_before_delete_range (snippet,
+ GTK_TEXT_BUFFER (buffer),
+ begin,
+ end);
+ //ide_source_view_unblock_handlers (self);
+ }
+}
+
+static void
+buffer_delete_range_after_cb (GtkSourceBuffer *buffer,
+ GtkTextIter *begin,
+ GtkTextIter *end,
+ GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+ GtkSourceSnippet *snippet;
+
+ g_assert (GTK_SOURCE_IS_BUFFER (buffer));
+ g_assert (begin != NULL);
+ g_assert (end != NULL);
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+
+ snippet = g_queue_peek_head (&priv->snippets);
+
+ if (snippet != NULL)
+ {
+ //ide_source_view_block_handlers (self);
+ _gtk_source_snippet_after_delete_range (snippet,
+ GTK_TEXT_BUFFER (buffer),
+ begin,
+ end);
+ //ide_source_view_unblock_handlers (self);
+ }
+}
+
static void
remove_source_buffer (GtkSourceView *view)
{
@@ -1640,6 +1750,14 @@ remove_source_buffer (GtkSourceView *view)
implicit_trailing_newline_changed_cb,
view);
+ g_signal_handlers_disconnect_by_func (priv->source_buffer,
+ buffer_insert_text_cb,
+ view);
+
+ g_signal_handlers_disconnect_by_func (priv->source_buffer,
+ buffer_after_insert_text_cb,
+ view);
+
buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
g_signal_handlers_disconnect_by_func (buffer_internal,
@@ -1695,6 +1813,16 @@ set_source_buffer (GtkSourceView *view,
G_CALLBACK (buffer_has_selection_changed_cb),
view);
+ g_signal_connect (buffer,
+ "insert-text",
+ G_CALLBACK (buffer_insert_text_cb),
+ view);
+
+ g_signal_connect_after (buffer,
+ "insert-text",
+ G_CALLBACK (buffer_after_insert_text_cb),
+ view);
+
buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
g_signal_connect (buffer_internal,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]