[evolution/webkit-composer: 63/147] Various fixes in the spell-checking classes
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit-composer: 63/147] Various fixes in the spell-checking classes
- Date: Mon, 21 Jan 2013 02:15:26 +0000 (UTC)
commit ff473da15ebde3ce7975f4e56f62853b962fb141
Author: Dan VrÃtil <dvratil redhat com>
Date: Mon Aug 27 13:52:34 2012 +0200
Various fixes in the spell-checking classes
e-util/e-spell-checker.c | 9 ++-
e-util/e-spell-dictionary.c | 6 +-
e-util/e-spell-entry.c | 184 +++++++++++++++++++++----------------------
3 files changed, 101 insertions(+), 98 deletions(-)
---
diff --git a/e-util/e-spell-checker.c b/e-util/e-spell-checker.c
index 4fd6849..f55a8ca 100644
--- a/e-util/e-spell-checker.c
+++ b/e-util/e-spell-checker.c
@@ -45,6 +45,7 @@ struct _ESpellCheckerPrivate {
};
enum {
+ PROP_0,
PROP_ACTIVE_DICTIONARIES
};
@@ -341,6 +342,8 @@ e_spell_checker_init (ESpellChecker *checker)
{
checker->priv = G_TYPE_INSTANCE_GET_PRIVATE (
checker, E_TYPE_SPELL_CHECKER, ESpellCheckerPrivate);
+
+ checker->priv->broker = enchant_broker_init ();
}
typedef struct {
@@ -383,7 +386,9 @@ GList *
e_spell_checker_list_available_dicts (ESpellChecker *checker)
{
ESpellChecker *e_checker;
- ListAvailDictsData data;
+ ListAvailDictsData data = { 0 };
+
+ g_return_val_if_fail (E_IS_SPELL_CHECKER (checker), NULL);
e_checker = E_SPELL_CHECKER (checker);
@@ -411,6 +416,8 @@ e_spell_checker_lookup_dictionary (ESpellChecker *checker,
ESpellChecker *e_checker;
ESpellDictionary *e_dict;
+ g_return_val_if_fail (E_IS_SPELL_CHECKER (checker), NULL);
+
e_checker = E_SPELL_CHECKER (checker);
e_dict = NULL;
diff --git a/e-util/e-spell-dictionary.c b/e-util/e-spell-dictionary.c
index aed60ce..e5ed02a 100644
--- a/e-util/e-spell-dictionary.c
+++ b/e-util/e-spell-dictionary.c
@@ -39,6 +39,7 @@ G_DEFINE_TYPE (
enum {
+ PROP_0,
PROP_SPELLCHECKER
};
@@ -317,6 +318,7 @@ spell_dictionary_set_enchant_dict (ESpellDictionary *dictionary,
enchant_dict_describe (enchant_dict, describe_dictionary, &data);
+ dictionary->priv->dict = enchant_dict;
dictionary->priv->code = data.language_tag;
dictionary->priv->name = data.dict_name;
dictionary->priv->collate_key = g_utf8_collate_key (data.dict_name, -1);
@@ -364,9 +366,7 @@ spell_dictionary_dispose (GObject *object)
{
ESpellDictionaryPrivate *priv = E_SPELL_DICTIONARY (object)->priv;
- e_spell_checker_free_dict (
- e_spell_dictionary_get_parent_checker (E_SPELL_DICTIONARY (object)),
- priv->dict);
+ e_spell_checker_free_dict (priv->spell_checker, priv->dict);
priv->dict = NULL;
g_free (priv->name);
diff --git a/e-util/e-spell-entry.c b/e-util/e-spell-entry.c
index f9949c0..a1c00ca 100644
--- a/e-util/e-spell-entry.c
+++ b/e-util/e-spell-entry.c
@@ -25,8 +25,7 @@
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
-#include <editor/gtkhtml-spell-language.h>
-#include <editor/gtkhtml-spell-checker.h>
+#include <e-util/e-spell-checker.h>
#include "e-spell-entry.h"
@@ -43,10 +42,12 @@ struct _ESpellEntryPrivate
GSettings *settings;
gboolean custom_checkers;
gboolean checking_enabled;
- GSList *checkers;
+ GSList *dictionaries;
gchar **words;
gint *word_starts;
gint *word_ends;
+
+ ESpellChecker *spell_checker;
};
#define E_SPELL_ENTRY_GET_PRIVATE(obj) \
@@ -76,9 +77,9 @@ word_misspelled (ESpellEntry *entry,
GSList *li;
gssize wlen = strlen (word);
- for (li = entry->priv->checkers; li; li = g_slist_next (li)) {
- GtkhtmlSpellChecker *checker = li->data;
- if (gtkhtml_spell_checker_check_word (checker, word, wlen)) {
+ for (li = entry->priv->dictionaries; li; li = g_slist_next (li)) {
+ EnchantDict *dict = li->data;
+ if (enchant_dict_check (dict, word, wlen)) {
result = FALSE;
break;
}
@@ -149,7 +150,7 @@ spell_entry_recheck_all (ESpellEntry *entry)
pango_attr_list_unref (entry->priv->attr_list);
entry->priv->attr_list = pango_attr_list_new ();
- if (entry->priv->checkers && entry->priv->checking_enabled) {
+ if (entry->priv->dictionaries && entry->priv->checking_enabled) {
/* Loop through words */
for (i = 0; entry->priv->words[i]; i++) {
length = strlen (entry->priv->words[i]);
@@ -252,14 +253,15 @@ add_to_dictionary (GtkWidget *menuitem,
{
gchar *word;
gint start, end;
- GtkhtmlSpellChecker *checker;
+ EnchantDict *dict;
get_word_extents_from_position (entry, &start, &end, entry->priv->mark_character);
word = gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
- checker = g_object_get_data (G_OBJECT (menuitem), "spell-entry-checker");
- if (checker)
- gtkhtml_spell_checker_add_word (checker, word, -1);
+ dict = g_object_get_data (G_OBJECT (menuitem), "spell-entry-checker");
+ if (dict) {
+ enchant_dict_add_to_personal (dict, word, -1);
+ }
g_free (word);
@@ -284,9 +286,9 @@ ignore_all (GtkWidget *menuitem,
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->checkers; li; li = g_slist_next (li)) {
- GtkhtmlSpellChecker *checker = li->data;
- gtkhtml_spell_checker_add_word_to_session (checker, word, -1);
+ for (li = entry->priv->dictionaries; li; li = g_slist_next (li)) {
+ EnchantDict *dict = li->data;
+ enchant_dict_add_to_session (dict, word, -1);
}
g_free (word);
@@ -308,7 +310,7 @@ replace_word (GtkWidget *menuitem,
const gchar *newword;
gint start, end;
gint cursor;
- GtkhtmlSpellChecker *checker;
+ EnchantDict *dict;
get_word_extents_from_position (entry, &start, &end, entry->priv->mark_character);
oldword = gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
@@ -323,15 +325,14 @@ replace_word (GtkWidget *menuitem,
gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
gtk_editable_set_position (GTK_EDITABLE (entry), start);
- gtk_editable_insert_text (
- GTK_EDITABLE (entry), newword, strlen (newword),
- &start);
+ gtk_editable_insert_text (GTK_EDITABLE (entry), newword, strlen (newword),
+ &start);
gtk_editable_set_position (GTK_EDITABLE (entry), cursor);
- checker = g_object_get_data (G_OBJECT (menuitem), "spell-entry-checker");
+ dict = g_object_get_data (G_OBJECT (menuitem), "spell-entry-checker");
- if (checker != NULL)
- gtkhtml_spell_checker_store_replacement (checker, oldword, -1, newword, -1);
+ if (dict != NULL)
+ enchant_dict_store_replacement (dict, oldword, -1, newword, -1);
g_free (oldword);
}
@@ -339,13 +340,13 @@ replace_word (GtkWidget *menuitem,
static void
build_suggestion_menu (ESpellEntry *entry,
GtkWidget *menu,
- GtkhtmlSpellChecker *checker,
+ ESpellDictionary *dict,
const gchar *word)
{
GtkWidget *mi;
- GList *suggestions, *iter;
+ GList *suggestions;
- suggestions = gtkhtml_spell_checker_get_suggestions (checker, word, -1);
+ suggestions = e_spell_dictionary_get_suggestions (dict, word, -1);
if (!suggestions) {
/* no suggestions. Put something in the menu anyway... */
@@ -364,10 +365,13 @@ build_suggestion_menu (ESpellEntry *entry,
gtk_widget_show_all (mi);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi);
} else {
- gint ii = 0;
+ GList *iter;
+ gint ii;
/* build a set of menus with suggestions */
- for (iter = suggestions; iter; iter = g_list_next (iter), ii++) {
+ for (iter = suggestions, ii = 0; iter; iter = iter->next, ii++) {
+ gchar *suggestion = iter->data;
+
if ((ii != 0) && (ii % 10 == 0)) {
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
@@ -381,50 +385,45 @@ build_suggestion_menu (ESpellEntry *entry,
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu);
}
- mi = gtk_menu_item_new_with_label (iter->data);
- g_object_set_data (G_OBJECT (mi), "spell-entry-checker", checker);
- g_signal_connect (mi, "activate", G_CALLBACK (replace_word), entry);
+ mi = gtk_menu_item_new_with_label (suggestion);
+ g_object_set_data (G_OBJECT (mi), "spell-entry-checker", dict);
+ g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (replace_word), entry);
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
}
}
- g_list_free_full (suggestions, g_free);
+ e_spell_dictionary_free_suggestions (suggestions);
}
static GtkWidget *
build_spelling_menu (ESpellEntry *entry,
const gchar *word)
{
- GtkhtmlSpellChecker *checker;
+ ESpellDictionary *dict;
GtkWidget *topmenu, *mi;
gchar *label;
topmenu = gtk_menu_new ();
- if (!entry->priv->checkers)
+ if (!entry->priv->dictionaries)
return topmenu;
/* Suggestions */
- if (!entry->priv->checkers->next) {
- checker = entry->priv->checkers->data;
- build_suggestion_menu (entry, topmenu, checker, word);
+ if (!entry->priv->dictionaries->next) {
+ dict = entry->priv->dictionaries->data;
+ build_suggestion_menu (entry, topmenu, dict, word);
} else {
GSList *li;
GtkWidget *menu;
const gchar *lang_name;
- for (li = entry->priv->checkers; li; li = g_slist_next (li)) {
- const GtkhtmlSpellLanguage *language;
-
- checker = li->data;
- language = gtkhtml_spell_checker_get_language (checker);
- if (!language)
- continue;
+ for (li = entry->priv->dictionaries; li; li = g_slist_next (li)) {
+ dict = li->data;
- lang_name = gtkhtml_spell_language_get_name (language);
+ lang_name = e_spell_dictionary_get_name (dict);
if (!lang_name)
- lang_name = gtkhtml_spell_language_get_code (language);
+ lang_name = e_spell_dictionary_get_code (dict);
mi = gtk_menu_item_new_with_label (lang_name ? lang_name : "???");
@@ -432,7 +431,7 @@ build_spelling_menu (ESpellEntry *entry,
gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi);
menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu);
- build_suggestion_menu (entry, menu, checker, word);
+ build_suggestion_menu (entry, menu, dict, word);
}
}
@@ -448,10 +447,10 @@ build_spelling_menu (ESpellEntry *entry,
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
- if (!entry->priv->checkers->next) {
- checker = entry->priv->checkers->data;
- g_object_set_data (G_OBJECT (mi), "spell-entry-checker", checker);
- g_signal_connect (mi, "activate", G_CALLBACK (add_to_dictionary), entry);
+ if (!entry->priv->dictionaries->next) {
+ dict = entry->priv->dictionaries->data;
+ g_object_set_data (G_OBJECT (mi), "spell-entry-checker", dict);
+ g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (add_to_dictionary), entry);
} else {
GSList *li;
GtkWidget *menu, *submi;
@@ -460,21 +459,16 @@ build_spelling_menu (ESpellEntry *entry,
menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu);
- for (li = entry->priv->checkers; li; li = g_slist_next (li)) {
- const GtkhtmlSpellLanguage *language;
-
- checker = li->data;
- language = gtkhtml_spell_checker_get_language (checker);
- if (!language)
- continue;
+ for (li = entry->priv->dictionaries; li; li = g_slist_next (li)) {
+ dict = li->data;
- lang_name = gtkhtml_spell_language_get_name (language);
+ lang_name = e_spell_dictionary_get_name (dict);
if (!lang_name)
- lang_name = gtkhtml_spell_language_get_code (language);
+ lang_name = e_spell_dictionary_get_code (dict);
submi = gtk_menu_item_new_with_label (lang_name ? lang_name : "???");
- g_object_set_data (G_OBJECT (submi), "spell-entry-checker", checker);
- g_signal_connect (submi, "activate", G_CALLBACK (add_to_dictionary), entry);
+ g_object_set_data (G_OBJECT (submi), "spell-entry-checker", dict);
+ g_signal_connect (G_OBJECT (submi), "activate", G_CALLBACK (add_to_dictionary), entry);
gtk_widget_show (submi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), submi);
@@ -487,7 +481,7 @@ build_spelling_menu (ESpellEntry *entry,
/* - Ignore All */
mi = gtk_image_menu_item_new_with_label (_("Ignore All"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
- g_signal_connect (mi, "activate", G_CALLBACK (ignore_all), entry);
+ g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (ignore_all), entry);
gtk_widget_show_all (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi);
@@ -538,7 +532,7 @@ spell_entry_populate_popup (ESpellEntry *entry,
gint start, end;
gchar *word;
- if (!entry->priv->checkers)
+ if (!entry->priv->dictionaries)
return;
get_word_extents_from_position (entry, &start, &end, entry->priv->mark_character);
@@ -561,7 +555,7 @@ spell_entry_changed (GtkEditable *editable)
{
ESpellEntry *entry = E_SPELL_ENTRY (editable);
- if (!entry->priv->checkers)
+ if (!entry->priv->dictionaries)
return;
if (entry->priv->words) {
@@ -582,10 +576,11 @@ spell_entry_notify_scroll_offset (ESpellEntry *spell_entry)
}
static GList *
-spell_entry_load_spell_languages (void)
+spell_entry_load_spell_languages (ESpellEntry *entry)
{
+ ESpellChecker *spell_checker;
GSettings *settings;
- GList *spell_languages = NULL;
+ GList *dicts = NULL;
gchar **strv;
gint ii;
@@ -594,34 +589,36 @@ spell_entry_load_spell_languages (void)
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++) {
gchar *language_code = strv[ii];
- const GtkhtmlSpellLanguage *language;
+ ESpellDictionary *dict;
- language = gtkhtml_spell_language_lookup (language_code);
- if (language != NULL)
- spell_languages = g_list_prepend (
- spell_languages, (gpointer) language);
+ dict = e_spell_checker_lookup_dictionary (spell_checker, language_code);
+ if (dict != NULL)
+ dicts = g_list_prepend (
+ dicts, (gpointer) dict);
}
g_strfreev (strv);
- spell_languages = g_list_reverse (spell_languages);
+ dicts = g_list_reverse (dicts);
/* Pick a default spell language if it came back empty. */
- if (spell_languages == NULL) {
- const GtkhtmlSpellLanguage *language;
+ if (dicts == NULL) {
+ ESpellDictionary *dict;
- language = gtkhtml_spell_language_lookup (NULL);
+ dict = e_spell_checker_lookup_dictionary (spell_checker, NULL);
- if (language) {
- spell_languages = g_list_prepend (
- spell_languages, (gpointer) language);
+ if (dict) {
+ dicts = g_list_prepend (
+ dicts, (gpointer) dict);
}
}
- return spell_languages;
+ return dicts;
}
static void
@@ -638,7 +635,7 @@ spell_entry_settings_changed (ESpellEntry *spell_entry,
if (key && !g_str_equal (key, "composer-spell-languages"))
return;
- languages = spell_entry_load_spell_languages ();
+ languages = spell_entry_load_spell_languages (spell_entry);
e_spell_entry_set_languages (spell_entry, languages);
g_list_free (languages);
@@ -735,8 +732,9 @@ e_spell_entry_init (ESpellEntry *spell_entry)
{
spell_entry->priv = E_SPELL_ENTRY_GET_PRIVATE (spell_entry);
spell_entry->priv->attr_list = pango_attr_list_new ();
- spell_entry->priv->checkers = NULL;
+ spell_entry->priv->dictionaries = NULL;
spell_entry->priv->checking_enabled = TRUE;
+ spell_entry->priv->spell_checker = g_object_new (E_TYPE_SPELL_CHECKER, NULL);
g_signal_connect (spell_entry, "popup-menu", G_CALLBACK (spell_entry_popup_menu), NULL);
g_signal_connect (spell_entry, "populate-popup", G_CALLBACK (spell_entry_populate_popup), NULL);
@@ -761,10 +759,10 @@ e_spell_entry_finalize (GObject *object)
entry = E_SPELL_ENTRY (object);
- if (entry->priv->settings)
- g_object_unref (entry->priv->settings);
+ g_clear_object (&entry->priv->settings);
+ g_clear_object (&entry->priv->spell_checker);
- g_slist_free_full (entry->priv->checkers, g_object_unref);
+ g_slist_free_full (entry->priv->dictionaries, g_object_unref);
if (entry->priv->attr_list)
pango_attr_list_unref (entry->priv->attr_list);
@@ -810,7 +808,6 @@ e_spell_entry_new (void)
return g_object_new (E_TYPE_SPELL_ENTRY, NULL);
}
-/* 'languages' consists of 'const GtkhtmlSpellLanguage *' */
void
e_spell_entry_set_languages (ESpellEntry *spell_entry,
GList *languages)
@@ -821,20 +818,19 @@ e_spell_entry_set_languages (ESpellEntry *spell_entry,
spell_entry->priv->custom_checkers = TRUE;
- if (spell_entry->priv->checkers)
- g_slist_free_full (spell_entry->priv->checkers, g_object_unref);
- spell_entry->priv->checkers = NULL;
+ if (spell_entry->priv->dictionaries)
+ g_slist_free_full (spell_entry->priv->dictionaries, g_object_unref);
+ spell_entry->priv->dictionaries = NULL;
for (iter = languages; iter; iter = g_list_next (iter)) {
- const GtkhtmlSpellLanguage *language = iter->data;
+ ESpellDictionary *dict = iter->data;
- if (language)
- spell_entry->priv->checkers = g_slist_prepend (
- spell_entry->priv->checkers,
- gtkhtml_spell_checker_new (language));
+ if (dict)
+ spell_entry->priv->dictionaries =
+ g_slist_prepend (spell_entry->priv->dictionaries, dict);
}
- spell_entry->priv->checkers = g_slist_reverse (spell_entry->priv->checkers);
+ spell_entry->priv->dictionaries = g_slist_reverse (spell_entry->priv->dictionaries);
if (gtk_widget_get_realized (GTK_WIDGET (spell_entry)))
spell_entry_recheck_all (spell_entry);
@@ -854,7 +850,7 @@ e_spell_entry_set_checking_enabled (ESpellEntry *spell_entry,
{
g_return_if_fail (E_IS_SPELL_ENTRY (spell_entry));
- if (spell_entry->priv->checking_enabled == enable_checking)
+ if ((enable_checking ? 1 : 0) == (spell_entry->priv->checking_enabled ? 1 : 0))
return;
spell_entry->priv->checking_enabled = enable_checking;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]