[gedit/wip/spell-checking: 1/4] spell-checker: extract get_default_language() from lazy_init()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/spell-checking: 1/4] spell-checker: extract get_default_language() from lazy_init()
- Date: Fri, 24 Jul 2015 05:19:31 +0000 (UTC)
commit 4698f8949b30ed54b5fcc1b46fcdfaa61bba8771
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jul 24 06:33:39 2015 +0200
spell-checker: extract get_default_language() from lazy_init()
plugins/spell/gedit-spell-checker.c | 93 ++++++++++++++++++-----------------
1 files changed, 47 insertions(+), 46 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-checker.c b/plugins/spell/gedit-spell-checker.c
index 0fafdba..4d2db42 100644
--- a/plugins/spell/gedit-spell-checker.c
+++ b/plugins/spell/gedit-spell-checker.c
@@ -199,79 +199,78 @@ gedit_spell_checker_new (void)
return spell;
}
-static gboolean
-lazy_init (GeditSpellChecker *spell,
- const GeditSpellCheckerLanguage *language)
+static const GeditSpellCheckerLanguage *
+get_default_language (void)
{
- if (spell->dict != NULL)
- return TRUE;
-
- g_return_val_if_fail (spell->broker != NULL, FALSE);
+ const GeditSpellCheckerLanguage *lang;
+ const gchar * const *lang_names;
+ const GSList *langs;
+ gint i;
- spell->active_lang = NULL;
+ /* Try with the current locale */
+ lang_names = g_get_language_names ();
- if (language != NULL)
+ for (i = 0; lang_names[i] != NULL; i++)
{
- spell->active_lang = language;
- }
- else
- {
- /* First try to get a default language */
- const GeditSpellCheckerLanguage *l;
- gint i = 0;
- const gchar * const *lang_tags = g_get_language_names ();
+ lang = gedit_spell_checker_language_from_key (lang_names[i]);
- while (lang_tags [i])
+ if (lang != NULL)
{
- l = gedit_spell_checker_language_from_key (lang_tags [i]);
-
- if (l != NULL)
- {
- spell->active_lang = l;
- break;
- }
-
- i++;
+ return lang;
}
}
+ /* Another try specific to Mac OS X */
#ifdef OS_OSX
- if (spell->active_lang == NULL)
{
- gchar *key;
+ gchar *key = gedit_spell_osx_get_preferred_spell_language ();
- key = gedit_spell_osx_get_preferred_spell_language ();
-
- if (key)
+ if (key != NULL)
{
- spell->active_lang = gedit_spell_checker_language_from_key (key);
+ lang = gedit_spell_checker_language_from_key (key);
+ g_free (key);
+ return lang;
}
-
- g_free (key);
}
#endif
- /* Second try to get a default language */
- if (spell->active_lang == NULL)
- spell->active_lang = gedit_spell_checker_language_from_key ("en_US");
+ /* Try English */
+ lang = gedit_spell_checker_language_from_key ("en_US");
+ if (lang != NULL)
+ {
+ return lang;
+ }
- /* Last try to get a default language */
- if (spell->active_lang == NULL)
+ /* Take the first available language */
+ langs = gedit_spell_checker_get_available_languages ();
+ if (langs != NULL)
{
- const GSList *langs;
- langs = gedit_spell_checker_get_available_languages ();
- if (langs != NULL)
- spell->active_lang = (const GeditSpellCheckerLanguage *)langs->data;
+ return langs->data;
}
+ return NULL;
+}
+
+static gboolean
+lazy_init (GeditSpellChecker *spell,
+ const GeditSpellCheckerLanguage *language)
+{
+ if (spell->dict != NULL)
+ {
+ return TRUE;
+ }
+
+ g_return_val_if_fail (spell->broker != NULL, FALSE);
+
+ spell->active_lang = language != NULL ? language : get_default_language ();
+
if (spell->active_lang != NULL)
{
const gchar *key;
key = gedit_spell_checker_language_to_key (spell->active_lang);
- spell->dict = enchant_broker_request_dict (spell->broker,
- key);
+ spell->dict = enchant_broker_request_dict (spell->broker, key);
}
if (spell->dict == NULL)
@@ -279,7 +278,9 @@ lazy_init (GeditSpellChecker *spell,
spell->active_lang = NULL;
if (language != NULL)
+ {
g_warning ("Spell checker plugin: cannot select a default language.");
+ }
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]