[gspell/wip/current-word-policy: 16/17] 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: 16/17] Entry: do not check word currently typed
- Date: Tue, 20 Dec 2016 18:19:14 +0000 (UTC)
commit 148e06b627eb7114cd6a0d7e2711116bdfff5291
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 | 133 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 125 insertions(+), 8 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 0e7e2b6..cab28ea 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.
*/
@@ -242,6 +245,17 @@ update_misspelled_words_list (GspellEntry *gspell_entry)
gspell_entry->misspelled_words = g_slist_reverse (gspell_entry->misspelled_words);
}
+static gboolean
+is_current_word (GspellEntry *gspell_entry,
+ GspellEntryWord *word)
+{
+ gint cursor_pos;
+
+ cursor_pos = gtk_editable_get_position (GTK_EDITABLE (gspell_entry->entry));
+
+ return (word->char_start <= cursor_pos && cursor_pos <= word->char_end);
+}
+
static void
recheck_all (GspellEntry *gspell_entry)
{
@@ -253,6 +267,12 @@ recheck_all (GspellEntry *gspell_entry)
{
GspellEntryWord *cur_word = l->data;
+ if (!_gspell_current_word_policy_get_check_current_word (gspell_entry->current_word_policy) &&
+ is_current_word (gspell_entry, cur_word))
+ {
+ continue;
+ }
+
insert_underline (gspell_entry,
cur_word->byte_start,
cur_word->byte_end);
@@ -323,6 +343,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 +371,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 +389,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 +411,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 +669,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 +774,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_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");
@@ -732,6 +846,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 +903,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]