[gspell/wip/current-word-policy] Entry: connect to ::inserted-text



commit 17ac334e51fc60562f297e9a5dc6d418ec91c90d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Dec 21 15:25:48 2016 +0100

    Entry: connect to ::inserted-text

 gspell/gspell-entry.c |  103 ++++++++++++++++++++++---------------------------
 1 files changed, 46 insertions(+), 57 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index e5306af..8f298c9 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -431,6 +431,43 @@ notify_spell_checker_cb (GspellEntryBuffer *gspell_buffer,
 }
 
 static void
+inserted_text_cb (GtkEntryBuffer *buffer,
+                 guint           position,
+                 gchar          *chars,
+                 guint           n_chars,
+                 GspellEntry    *gspell_entry)
+{
+       g_message ("%s", G_STRFUNC);
+
+       if (n_chars > 1)
+       {
+               _gspell_current_word_policy_several_chars_inserted (gspell_entry->current_word_policy);
+       }
+       else
+       {
+               gunichar ch;
+               gboolean empty_selection;
+               gint cursor_pos;
+               gboolean at_cursor_pos;
+
+               ch = g_utf8_get_char (chars);
+
+               empty_selection = !gtk_editable_get_selection_bounds (GTK_EDITABLE (gspell_entry->entry),
+                                                                     NULL,
+                                                                     NULL);
+
+               cursor_pos = gtk_editable_get_position (GTK_EDITABLE (gspell_entry->entry));
+               at_cursor_pos = cursor_pos == (gint)position;
+               g_message ("%s: at_cursor_pos=%d", G_STRFUNC, at_cursor_pos);
+
+               _gspell_current_word_policy_single_char_inserted (gspell_entry->current_word_policy,
+                                                                 ch,
+                                                                 empty_selection,
+                                                                 at_cursor_pos);
+       }
+}
+
+static void
 set_buffer (GspellEntry    *gspell_entry,
            GtkEntryBuffer *gtk_buffer)
 {
@@ -449,6 +486,10 @@ set_buffer (GspellEntry    *gspell_entry,
                                                      notify_spell_checker_cb,
                                                      gspell_entry);
 
+               g_signal_handlers_disconnect_by_func (gspell_entry->buffer,
+                                                     inserted_text_cb,
+                                                     gspell_entry);
+
                g_object_unref (gspell_entry->buffer);
        }
 
@@ -463,6 +504,11 @@ set_buffer (GspellEntry    *gspell_entry,
                                  G_CALLBACK (notify_spell_checker_cb),
                                  gspell_entry);
 
+               g_signal_connect (gspell_entry->buffer,
+                                 "inserted-text",
+                                 G_CALLBACK (inserted_text_cb),
+                                 gspell_entry);
+
                g_object_ref (gspell_entry->buffer);
        }
 
@@ -680,58 +726,6 @@ move_cursor_cb (GspellEntry *gspell_entry)
        emit_changed_signal (gspell_entry);
 }
 
-static gboolean
-text_contains_several_chars (const gchar *text,
-                            gint         text_length)
-{
-       const gchar *end;
-
-       if (text_length < 0)
-       {
-               end = NULL;
-       }
-       else
-       {
-               end = text + text_length;
-       }
-
-       return g_utf8_find_next_char (text, end) != NULL;
-}
-
-static void
-insert_text_after_cb (GtkEditable *editable,
-                     gchar       *new_text,
-                     gint         new_text_length,
-                     gint        *position,
-                     GspellEntry *gspell_entry)
-{
-       g_message ("%s", G_STRFUNC);
-
-       if (text_contains_several_chars (new_text, new_text_length))
-       {
-               _gspell_current_word_policy_several_chars_inserted (gspell_entry->current_word_policy);
-       }
-       else
-       {
-               gunichar ch;
-               gboolean empty_selection;
-               gint cursor_pos;
-               gboolean at_cursor_pos;
-
-               ch = g_utf8_get_char (new_text);
-               empty_selection = !gtk_editable_get_selection_bounds (editable, NULL, NULL);
-
-               cursor_pos = gtk_editable_get_position (editable);
-               at_cursor_pos = cursor_pos == *position;
-               g_message ("%s: at_cursor_pos=%d", G_STRFUNC, at_cursor_pos);
-
-               _gspell_current_word_policy_single_char_inserted (gspell_entry->current_word_policy,
-                                                                 ch,
-                                                                 empty_selection,
-                                                                 at_cursor_pos);
-       }
-}
-
 static void
 set_entry (GspellEntry *gspell_entry,
           GtkEntry    *gtk_entry)
@@ -792,11 +786,6 @@ set_entry (GspellEntry *gspell_entry,
                                  G_CALLBACK (move_cursor_cb),
                                  gspell_entry);
 
-       g_signal_connect_after (GTK_EDITABLE (gtk_entry),
-                               "insert-text",
-                               G_CALLBACK (insert_text_after_cb),
-                               gspell_entry);
-
        update_buffer (gspell_entry);
 
        g_object_notify (G_OBJECT (gspell_entry), "entry");


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