[evolution/wip/webkit-composer: 648/966] ESpellEntry: Add a "spell-checker" property.
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer: 648/966] ESpellEntry: Add a "spell-checker" property.
- Date: Wed, 23 Apr 2014 10:47:54 +0000 (UTC)
commit cd26621de68272e2425229107a78eb2dc07024d7
Author: Matthew Barnes <mbarnes redhat com>
Date: Sun Jan 20 14:31:05 2013 -0500
ESpellEntry: Add a "spell-checker" property.
By default, ESpellEntry creates its own ESpellChecker instance. The
property is writable so a different ESpellChecker can be shared across
multiple spell checking widgets.
Listen for "notify::active-languages" signals from ESpellChecker to
trigger spelling rechecks, rather than monitoring GSettings directly.
Also, because ESpellChecker is configured automatically from GSettings
(via ESettingsSpellChecker), there's no need to do it ourselves.
New functions:
e_spell_entry_get_spell_checker()
e_spell_entry_set_spell_checker()
e-util/e-spell-entry.c | 154 ++++++++++++++++++------------------------------
1 files changed, 57 insertions(+), 97 deletions(-)
---
diff --git a/e-util/e-spell-entry.c b/e-util/e-spell-entry.c
index 8a9b250..0fb39e5 100644
--- a/e-util/e-spell-entry.c
+++ b/e-util/e-spell-entry.c
@@ -43,6 +43,7 @@ struct _ESpellEntryPrivate {
gint *word_ends;
ESpellChecker *spell_checker;
+ guint active_languages_handler_id;
};
enum {
@@ -76,16 +77,12 @@ word_misspelled (ESpellEntry *entry,
g_strlcpy (word, text + start, end - start + 1);
if (g_unichar_isalpha (*word)) {
- GList *li;
+ ESpellChecker *spell_checker;
gssize wlen = strlen (word);
- for (li = entry->priv->dictionaries; li; li = g_list_next (li)) {
- ESpellDictionary *dict = li->data;
- if (e_spell_dictionary_check (dict, word, wlen)) {
- result = FALSE;
- break;
- }
- }
+ spell_checker = e_spell_entry_get_spell_checker (entry);
+ if (e_spell_checker_check_word (spell_checker, word, wlen))
+ result = FALSE;
}
g_free (word);
@@ -160,8 +157,13 @@ spell_entry_recheck_all (ESpellEntry *entry)
pango_attr_list_unref (entry->priv->attr_list);
entry->priv->attr_list = pango_attr_list_new ();
- if (e_spell_entry_get_checking_enabled (entry))
- check_words = (entry->priv->dictionaries != NULL);
+ if (e_spell_entry_get_checking_enabled (entry)) {
+ ESpellChecker *spell_checker;
+
+ spell_checker = e_spell_entry_get_spell_checker (entry);
+ if (e_spell_checker_count_active_languages (spell_checker) > 0)
+ check_words = TRUE;
+ }
if (check_words) {
/* Loop through words */
@@ -303,16 +305,13 @@ ignore_all (GtkWidget *menuitem,
ESpellChecker *spell_checker;
gchar *word;
gint start, end;
- GList *li;
get_word_extents_from_position (
entry, &start, &end, entry->priv->mark_character);
word = gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
- for (li = entry->priv->dictionaries; li; li = g_list_next (li)) {
- ESpellDictionary *dict = li->data;
- e_spell_dictionary_ignore_word (dict, word, -1);
- }
+ spell_checker = e_spell_entry_get_spell_checker (entry);
+ e_spell_checker_ignore_word (spell_checker, word);
g_free (word);
@@ -429,6 +428,7 @@ static GtkWidget *
build_spelling_menu (ESpellEntry *entry,
const gchar *word)
{
+ ESpellChecker *spell_checker;
ESpellDictionary *dict;
GtkWidget *topmenu, *mi;
GQueue queue = G_QUEUE_INIT;
@@ -438,20 +438,35 @@ build_spelling_menu (ESpellEntry *entry,
topmenu = gtk_menu_new ();
- if (entry->priv->dictionaries == NULL)
- return topmenu;
+ spell_checker = e_spell_entry_get_spell_checker (entry);
+
+ active_languages = e_spell_checker_list_active_languages (
+ spell_checker, &n_active_languages);
+ for (ii = 0; ii < n_active_languages; ii++) {
+ dict = e_spell_checker_ref_dictionary (
+ spell_checker, active_languages[ii]);
+ if (dict != NULL)
+ g_queue_push_tail (&queue, dict);
+ }
+ g_strfreev (active_languages);
+
+ if (g_queue_is_empty (&queue))
+ goto exit;
/* Suggestions */
- if (entry->priv->dictionaries->next == NULL) {
- dict = entry->priv->dictionaries->data;
+ if (n_active_languages == 1) {
+ dict = g_queue_peek_head (&queue);
build_suggestion_menu (entry, topmenu, dict, word);
} else {
- GList *li;
GtkWidget *menu;
GList *list, *link;
- for (li = entry->priv->dictionaries; li; li = g_list_next (li)) {
- dict = li->data;
+ list = g_queue_peek_head_link (&queue);
+
+ for (link = list; link != NULL; link = g_list_next (link)) {
+ const gchar *lang_name;
+
+ dict = E_SPELL_DICTIONARY (link->data);
lang_name = e_spell_dictionary_get_name (dict);
if (lang_name == NULL)
@@ -483,22 +498,25 @@ build_spelling_menu (ESpellEntry *entry,
GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_MENU));
- if (entry->priv->dictionaries->next == NULL) {
- dict = entry->priv->dictionaries->data;
+ if (n_active_languages == 1) {
+ dict = g_queue_peek_head (&queue);
g_object_set_data (G_OBJECT (mi), "spell-entry-checker", dict);
g_signal_connect (
mi, "activate",
G_CALLBACK (add_to_dictionary), entry);
} else {
- GList *li;
GtkWidget *menu, *submi;
GList *list, *link;
menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu);
- for (li = entry->priv->dictionaries; li; li = g_list_next (li)) {
- dict = li->data;
+ list = g_queue_peek_head_link (&queue);
+
+ for (link = list; link != NULL; link = g_list_next (link)) {
+ const gchar *lang_name;
+
+ dict = E_SPELL_DICTIONARY (link->data);
lang_name = e_spell_dictionary_get_name (dict);
if (lang_name == NULL)
@@ -506,7 +524,7 @@ build_spelling_menu (ESpellEntry *entry,
if (lang_name == NULL)
lang_name = "???";
- submi = gtk_menu_item_new_with_label (lang_name ? lang_name : "???");
+ submi = gtk_menu_item_new_with_label (lang_name);
g_object_set_data (G_OBJECT (submi), "spell-entry-checker", dict);
g_signal_connect (
submi, "activate",
@@ -582,7 +600,8 @@ spell_entry_populate_popup (ESpellEntry *entry,
gint start, end;
gchar *word;
- if (entry->priv->dictionaries == NULL)
+ spell_checker = e_spell_entry_get_spell_checker (entry);
+ if (e_spell_checker_count_active_languages (spell_checker) == 0)
return;
get_word_extents_from_position (
@@ -607,7 +626,8 @@ spell_entry_changed (GtkEditable *editable)
ESpellEntry *entry = E_SPELL_ENTRY (editable);
ESpellChecker *spell_checker;
- if (entry->priv->dictionaries == NULL)
+ spell_checker = e_spell_entry_get_spell_checker (entry);
+ if (e_spell_checker_count_active_languages (spell_checker) == 0)
return;
if (entry->priv->words != NULL) {
@@ -633,71 +653,6 @@ spell_entry_notify_scroll_offset (ESpellEntry *spell_entry)
&spell_entry->priv->entry_scroll_offset, NULL);
}
-static GList *
-spell_entry_load_spell_languages (ESpellEntry *entry)
-{
- ESpellChecker *spell_checker;
- GSettings *settings;
- GList *list = NULL;
- gchar **strv;
- gint ii;
-
- /* Ask GSettings for a list of spell check language codes. */
- settings = g_settings_new ("org.gnome.evolution.mail");
- strv = g_settings_get_strv (settings, "composer-spell-languages");
- g_object_unref (settings);
-
- spell_checker = entry->priv->spell_checker;
-
- /* Convert the codes to spell language structs. */
- for (ii = 0; strv[ii] != NULL; ii++) {
- ESpellDictionary *dictionary;
- gchar *language_code = strv[ii];
-
- dictionary = e_spell_checker_ref_dictionary (
- spell_checker, language_code);
- if (dictionary != NULL)
- list = g_list_prepend (list, dictionary);
- }
-
- g_strfreev (strv);
-
- list = g_list_reverse (list);
-
- /* Pick a default spell language if it came back empty. */
- if (list == NULL) {
- ESpellDictionary *dictionary;
-
- dictionary = e_spell_checker_ref_dictionary (
- spell_checker, NULL);
- if (dictionary != NULL)
- list = g_list_prepend (list, dictionary);
- }
-
- return list;
-}
-
-static void
-spell_entry_settings_changed (ESpellEntry *spell_entry,
- const gchar *key)
-{
- GList *languages;
-
- g_return_if_fail (spell_entry != NULL);
-
- if (spell_entry->priv->custom_checkers)
- return;
-
- if (key && !g_str_equal (key, "composer-spell-languages"))
- return;
-
- languages = spell_entry_load_spell_languages (spell_entry);
- e_spell_entry_set_languages (spell_entry, languages);
- g_list_free_full (languages, (GDestroyNotify) g_object_unref);
-
- spell_entry->priv->custom_checkers = FALSE;
-}
-
static gint
spell_entry_find_position (ESpellEntry *spell_entry,
gint x)
@@ -786,7 +741,13 @@ spell_entry_dispose (GObject *object)
priv = E_SPELL_ENTRY_GET_PRIVATE (object);
- g_clear_object (&priv->settings);
+ if (priv->active_languages_handler_id > 0) {
+ g_signal_handler_disconnect (
+ priv->spell_checker,
+ priv->active_languages_handler_id);
+ priv->active_languages_handler_id = 0;
+ }
+
g_clear_object (&priv->spell_checker);
g_list_free_full (
@@ -918,7 +879,6 @@ e_spell_entry_init (ESpellEntry *spell_entry)
spell_entry->priv->attr_list = pango_attr_list_new ();
spell_entry->priv->dictionaries = NULL;
spell_entry->priv->checking_enabled = TRUE;
- spell_entry->priv->spell_checker = e_spell_checker_new ();
g_signal_connect (
spell_entry, "popup-menu",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]