[gspell/wip/current-word-policy: 2/2] Entry: do not check word currently typed
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/current-word-policy: 2/2] Entry: do not check word currently typed
- Date: Thu, 8 Dec 2016 16:57:43 +0000 (UTC)
commit 50357010a3eec1e0e02fb9fc9d24d65cb890637b
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Dec 8 17:09:21 2016 +0100
Entry: do not check word currently typed
gspell/gspell-entry.c | 116 +++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 108 insertions(+), 8 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 0e7e2b6..0addd98 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -22,6 +22,7 @@
#include "gspell-entry-buffer.h"
#include "gspell-entry-utils.h"
#include "gspell-context-menu.h"
+#include "gspell-current-word-policy.h"
/**
* SECTION:entry
@@ -54,6 +55,8 @@ struct _GspellEntry
GtkEntryBuffer *buffer;
GspellChecker *checker;
+ GspellCurrentWordPolicy *current_word_policy;
+
/* List elements: GspellEntryWord*.
* Used for unit tests.
*/
@@ -323,6 +326,23 @@ notify_attributes_cb (GtkEntry *gtk_entry,
}
static void
+language_notify_cb (GspellChecker *checker,
+ GParamSpec *pspec,
+ GspellEntry *gspell_entry)
+{
+ _gspell_current_word_policy_language_changed (gspell_entry->current_word_policy);
+ emit_changed_signal (gspell_entry);
+}
+
+static void
+session_cleared_cb (GspellChecker *checker,
+ GspellEntry *gspell_entry)
+{
+ _gspell_current_word_policy_session_cleared (gspell_entry->current_word_policy);
+ emit_changed_signal (gspell_entry);
+}
+
+static void
set_checker (GspellEntry *gspell_entry,
GspellChecker *checker)
{
@@ -334,6 +354,14 @@ set_checker (GspellEntry *gspell_entry,
if (gspell_entry->checker != NULL)
{
g_signal_handlers_disconnect_by_func (gspell_entry->checker,
+ language_notify_cb,
+ gspell_entry);
+
+ g_signal_handlers_disconnect_by_func (gspell_entry->checker,
+ session_cleared_cb,
+ gspell_entry);
+
+ g_signal_handlers_disconnect_by_func (gspell_entry->checker,
emit_changed_signal,
gspell_entry);
@@ -344,15 +372,15 @@ set_checker (GspellEntry *gspell_entry,
if (gspell_entry->checker != NULL)
{
- g_signal_connect_swapped (gspell_entry->checker,
- "notify::language",
- G_CALLBACK (emit_changed_signal),
- gspell_entry);
+ g_signal_connect (gspell_entry->checker,
+ "notify::language",
+ G_CALLBACK (language_notify_cb),
+ gspell_entry);
- g_signal_connect_swapped (gspell_entry->checker,
- "session-cleared",
- G_CALLBACK (emit_changed_signal),
- gspell_entry);
+ g_signal_connect (gspell_entry->checker,
+ "session-cleared",
+ G_CALLBACK (session_cleared_cb),
+ gspell_entry);
g_signal_connect_swapped (gspell_entry->checker,
"word-added-to-personal",
@@ -366,6 +394,8 @@ set_checker (GspellEntry *gspell_entry,
g_object_ref (gspell_entry->checker);
}
+
+ _gspell_current_word_policy_checker_changed (gspell_entry->current_word_policy);
}
static void
@@ -622,6 +652,63 @@ populate_popup_cb (GtkEntry *gtk_entry,
}
static void
+cursor_position_notify_cb (GtkEntry *gtk_entry,
+ GParamSpec *pspec,
+ GspellEntry *gspell_entry)
+{
+ _gspell_current_word_policy_cursor_moved (gspell_entry->current_word_policy);
+}
+
+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)
+{
+ 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;
+
+ _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)
{
@@ -670,6 +757,16 @@ set_entry (GspellEntry *gspell_entry,
G_CALLBACK (populate_popup_cb),
gspell_entry);
+ g_signal_connect (gtk_entry,
+ "notify::cursor-position",
+ G_CALLBACK (cursor_position_notify_cb),
+ gspell_entry);
+
+ g_signal_connect_after (gtk_entry,
+ "insert-text",
+ G_CALLBACK (insert_text_after_cb),
+ gspell_entry);
+
update_buffer (gspell_entry);
g_object_notify (G_OBJECT (gspell_entry), "entry");
@@ -732,6 +829,8 @@ gspell_entry_dispose (GObject *object)
set_buffer (gspell_entry, NULL);
set_checker (gspell_entry, NULL);
+ g_clear_object (&gspell_entry->current_word_policy);
+
if (gspell_entry->notify_attributes_idle_id != 0)
{
g_source_remove (gspell_entry->notify_attributes_idle_id);
@@ -787,6 +886,7 @@ gspell_entry_class_init (GspellEntryClass *klass)
static void
gspell_entry_init (GspellEntry *gspell_entry)
{
+ gspell_entry->current_word_policy = _gspell_current_word_policy_new ();
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]