xed-spell-checker.c: Clean up the code formatting
This commit is contained in:
parent
a13a573228
commit
a5af28a95d
|
@ -120,10 +120,14 @@ xed_spell_checker_finalize (GObject *object)
|
||||||
spell_checker = XED_SPELL_CHECKER (object);
|
spell_checker = XED_SPELL_CHECKER (object);
|
||||||
|
|
||||||
if (spell_checker->dict != NULL)
|
if (spell_checker->dict != NULL)
|
||||||
|
{
|
||||||
enchant_broker_free_dict (spell_checker->broker, spell_checker->dict);
|
enchant_broker_free_dict (spell_checker->broker, spell_checker->dict);
|
||||||
|
}
|
||||||
|
|
||||||
if (spell_checker->broker != NULL)
|
if (spell_checker->broker != NULL)
|
||||||
|
{
|
||||||
enchant_broker_free (spell_checker->broker);
|
enchant_broker_free (spell_checker->broker);
|
||||||
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (xed_spell_checker_parent_class)->finalize (object);
|
G_OBJECT_CLASS (xed_spell_checker_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
@ -206,8 +210,7 @@ xed_spell_checker_new (void)
|
||||||
{
|
{
|
||||||
XedSpellChecker *spell;
|
XedSpellChecker *spell;
|
||||||
|
|
||||||
spell = XED_SPELL_CHECKER (
|
spell = XED_SPELL_CHECKER (g_object_new (XED_TYPE_SPELL_CHECKER, NULL));
|
||||||
g_object_new (XED_TYPE_SPELL_CHECKER, NULL));
|
|
||||||
|
|
||||||
g_return_val_if_fail (spell != NULL, NULL);
|
g_return_val_if_fail (spell != NULL, NULL);
|
||||||
|
|
||||||
|
@ -219,7 +222,9 @@ lazy_init (XedSpellChecker *spell,
|
||||||
const XedSpellCheckerLanguage *language)
|
const XedSpellCheckerLanguage *language)
|
||||||
{
|
{
|
||||||
if (spell->dict != NULL)
|
if (spell->dict != NULL)
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (spell->broker != NULL, FALSE);
|
g_return_val_if_fail (spell->broker != NULL, FALSE);
|
||||||
|
|
||||||
|
@ -252,7 +257,9 @@ lazy_init (XedSpellChecker *spell,
|
||||||
|
|
||||||
/* Second try to get a default language */
|
/* Second try to get a default language */
|
||||||
if (spell->active_lang == NULL)
|
if (spell->active_lang == NULL)
|
||||||
|
{
|
||||||
spell->active_lang = xed_spell_checker_language_from_key ("en_US");
|
spell->active_lang = xed_spell_checker_language_from_key ("en_US");
|
||||||
|
}
|
||||||
|
|
||||||
/* Last try to get a default language */
|
/* Last try to get a default language */
|
||||||
if (spell->active_lang == NULL)
|
if (spell->active_lang == NULL)
|
||||||
|
@ -260,8 +267,10 @@ lazy_init (XedSpellChecker *spell,
|
||||||
const GSList *langs;
|
const GSList *langs;
|
||||||
langs = xed_spell_checker_get_available_languages ();
|
langs = xed_spell_checker_get_available_languages ();
|
||||||
if (langs != NULL)
|
if (langs != NULL)
|
||||||
|
{
|
||||||
spell->active_lang = (const XedSpellCheckerLanguage *)langs->data;
|
spell->active_lang = (const XedSpellCheckerLanguage *)langs->data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (spell->active_lang != NULL)
|
if (spell->active_lang != NULL)
|
||||||
{
|
{
|
||||||
|
@ -269,8 +278,7 @@ lazy_init (XedSpellChecker *spell,
|
||||||
|
|
||||||
key = xed_spell_checker_language_to_key (spell->active_lang);
|
key = xed_spell_checker_language_to_key (spell->active_lang);
|
||||||
|
|
||||||
spell->dict = enchant_broker_request_dict (spell->broker,
|
spell->dict = enchant_broker_request_dict (spell->broker, key);
|
||||||
key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spell->dict == NULL)
|
if (spell->dict == NULL)
|
||||||
|
@ -278,7 +286,9 @@ lazy_init (XedSpellChecker *spell,
|
||||||
spell->active_lang = NULL;
|
spell->active_lang = NULL;
|
||||||
|
|
||||||
if (language != NULL)
|
if (language != NULL)
|
||||||
|
{
|
||||||
g_warning ("Spell checker plugin: cannot select a default language.");
|
g_warning ("Spell checker plugin: cannot select a default language.");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -303,10 +313,13 @@ xed_spell_checker_set_language (XedSpellChecker *spell,
|
||||||
ret = lazy_init (spell, language);
|
ret = lazy_init (spell, language);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
|
{
|
||||||
g_signal_emit (G_OBJECT (spell), signals[SET_LANGUAGE], 0, language);
|
g_signal_emit (G_OBJECT (spell), signals[SET_LANGUAGE], 0, language);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
g_warning ("Spell checker plugin: cannot use language %s.",
|
{
|
||||||
xed_spell_checker_language_to_string (language));
|
g_warning ("Spell checker plugin: cannot use language %s.", xed_spell_checker_language_to_string (language));
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +330,9 @@ xed_spell_checker_get_language (XedSpellChecker *spell)
|
||||||
g_return_val_if_fail (XED_IS_SPELL_CHECKER (spell), NULL);
|
g_return_val_if_fail (XED_IS_SPELL_CHECKER (spell), NULL);
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return spell->active_lang;
|
return spell->active_lang;
|
||||||
}
|
}
|
||||||
|
@ -334,16 +349,24 @@ xed_spell_checker_check_word (XedSpellChecker *spell,
|
||||||
g_return_val_if_fail (word != NULL, FALSE);
|
g_return_val_if_fail (word != NULL, FALSE);
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
{
|
||||||
len = strlen (word);
|
len = strlen (word);
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp (word, "xed") == 0)
|
if (strcmp (word, "xed") == 0)
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (xed_spell_utils_is_digit (word, len))
|
if (xed_spell_utils_is_digit (word, len))
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
||||||
enchant_result = enchant_dict_check (spell->dict, word, len);
|
enchant_result = enchant_dict_check (spell->dict, word, len);
|
||||||
|
@ -389,24 +412,29 @@ xed_spell_checker_get_suggestions (XedSpellChecker *spell,
|
||||||
g_return_val_if_fail (word != NULL, NULL);
|
g_return_val_if_fail (word != NULL, NULL);
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (spell->dict != NULL, NULL);
|
g_return_val_if_fail (spell->dict != NULL, NULL);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
{
|
||||||
len = strlen (word);
|
len = strlen (word);
|
||||||
|
}
|
||||||
|
|
||||||
suggestions = enchant_dict_suggest (spell->dict, word, len, &n_suggestions);
|
suggestions = enchant_dict_suggest (spell->dict, word, len, &n_suggestions);
|
||||||
|
|
||||||
if (n_suggestions == 0)
|
if (n_suggestions == 0)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (suggestions != NULL, NULL);
|
g_return_val_if_fail (suggestions != NULL, NULL);
|
||||||
|
|
||||||
for (i = 0; i < (gint)n_suggestions; i++)
|
for (i = 0; i < (gint)n_suggestions; i++)
|
||||||
{
|
{
|
||||||
suggestions_list = g_slist_prepend (suggestions_list,
|
suggestions_list = g_slist_prepend (suggestions_list, suggestions[i]);
|
||||||
suggestions[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The single suggestions will be freed by the caller */
|
/* The single suggestions will be freed by the caller */
|
||||||
|
@ -426,12 +454,16 @@ xed_spell_checker_add_word_to_personal (XedSpellChecker *spell,
|
||||||
g_return_val_if_fail (word != NULL, FALSE);
|
g_return_val_if_fail (word != NULL, FALSE);
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
{
|
||||||
len = strlen (word);
|
len = strlen (word);
|
||||||
|
}
|
||||||
|
|
||||||
enchant_dict_add_to_pwl (spell->dict, word, len);
|
enchant_dict_add_to_pwl (spell->dict, word, len);
|
||||||
|
|
||||||
|
@ -449,12 +481,16 @@ xed_spell_checker_add_word_to_session (XedSpellChecker *spell,
|
||||||
g_return_val_if_fail (word != NULL, FALSE);
|
g_return_val_if_fail (word != NULL, FALSE);
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
{
|
||||||
len = strlen (word);
|
len = strlen (word);
|
||||||
|
}
|
||||||
|
|
||||||
enchant_dict_add_to_session (spell->dict, word, len);
|
enchant_dict_add_to_session (spell->dict, word, len);
|
||||||
|
|
||||||
|
@ -476,7 +512,9 @@ xed_spell_checker_clear_session (XedSpellChecker *spell)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_signal_emit (G_OBJECT (spell), signals[CLEAR_SESSION], 0);
|
g_signal_emit (G_OBJECT (spell), signals[CLEAR_SESSION], 0);
|
||||||
|
|
||||||
|
@ -499,15 +537,21 @@ xed_spell_checker_set_correction (XedSpellChecker *spell,
|
||||||
g_return_val_if_fail (replacement != NULL, FALSE);
|
g_return_val_if_fail (replacement != NULL, FALSE);
|
||||||
|
|
||||||
if (!lazy_init (spell, spell->active_lang))
|
if (!lazy_init (spell, spell->active_lang))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
g_return_val_if_fail (spell->dict != NULL, FALSE);
|
||||||
|
|
||||||
if (w_len < 0)
|
if (w_len < 0)
|
||||||
|
{
|
||||||
w_len = strlen (word);
|
w_len = strlen (word);
|
||||||
|
}
|
||||||
|
|
||||||
if (r_len < 0)
|
if (r_len < 0)
|
||||||
|
{
|
||||||
r_len = strlen (replacement);
|
r_len = strlen (replacement);
|
||||||
|
}
|
||||||
|
|
||||||
enchant_dict_store_replacement (spell->dict,
|
enchant_dict_store_replacement (spell->dict,
|
||||||
word,
|
word,
|
||||||
|
|
Loading…
Reference in New Issue