SF.net SVN: geany-plugins:[971] branches/geany-plugins/geany-plugins-0.18/ spellcheck

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Sep 30 19:41:19 UTC 2009


Revision: 971
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=971&view=rev
Author:   eht16
Date:     2009-09-30 19:41:19 +0000 (Wed, 30 Sep 2009)

Log Message:
-----------
Merge changes from trunk:
   Allow setting a custom dictionary directory without reloading
   the plugin.
   Add an option to the preference dialog to select a custom
   directory to look for additional dictionary files.
   Minor fixes.
   Remove unused code.
   Use single header includes.

Modified Paths:
--------------
    branches/geany-plugins/geany-plugins-0.18/spellcheck/ChangeLog
    branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.c
    branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.h
    branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.c
    branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.h
    branches/geany-plugins/geany-plugins-0.18/spellcheck/src/speller.c

Modified: branches/geany-plugins/geany-plugins-0.18/spellcheck/ChangeLog
===================================================================
--- branches/geany-plugins/geany-plugins-0.18/spellcheck/ChangeLog	2009-09-30 19:35:07 UTC (rev 970)
+++ branches/geany-plugins/geany-plugins-0.18/spellcheck/ChangeLog	2009-09-30 19:41:19 UTC (rev 971)
@@ -1,3 +1,16 @@
+2009-09-30  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
+
+ * src/gui.c, src/gui.h, src/scplugin.c, src/scplugin.h, src/speller.c:
+   Merge changes from trunk:
+   Allow setting a custom dictionary directory without reloading
+   the plugin.
+   Add an option to the preference dialog to select a custom
+   directory to look for additional dictionary files.
+   Minor fixes.
+   Remove unused code.
+   Use single header includes.
+
+
 2009-06-28  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * src/gui.c:

Modified: branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.c
===================================================================
--- branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.c	2009-09-30 19:35:07 UTC (rev 970)
+++ branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.c	2009-09-30 19:41:19 UTC (rev 971)
@@ -23,22 +23,12 @@
  */
 
 
-#include "geany.h"
-#include "support.h"
+#include "geanyplugin.h"
 
 #include <ctype.h>
 #include <string.h>
 
-#include "plugindata.h"
 
-#include "document.h"
-#include "editor.h"
-#include "msgwindow.h"
-#include "utils.h"
-#include "ui_utils.h"
-
-#include "geanyfunctions.h"
-
 #include "gui.h"
 #include "scplugin.h"
 #include "speller.h"
@@ -81,11 +71,6 @@
 }
 
 
-void sc_gui_update_tooltip(void)
-{
-}
-
-
 void sc_gui_update_toolbar(void)
 {
 	/* toolbar item is not requested, so remove the item if it exists */
@@ -101,7 +86,6 @@
 		if (sc_info->toolbar_button == NULL)
 		{
 			sc_info->toolbar_button = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_SPELL_CHECK);
-			sc_gui_update_tooltip();
 
 			plugin_add_toolbar_item(geany_plugin, sc_info->toolbar_button);
 			ui_add_document_sensitive(GTK_WIDGET(sc_info->toolbar_button));
@@ -158,7 +142,7 @@
 }
 
 
-static void menu_addword_item_activate_cd(GtkMenuItem *menuitem, gpointer gdata)
+static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
 {
 	gint startword, endword, i, doc_len;
 	ScintillaObject *sci;
@@ -298,12 +282,12 @@
 		menu_item = image_menu_item_new(GTK_STOCK_ADD, label);
 		gtk_container_add(GTK_CONTAINER(sc_info->edit_menu_sub), menu_item);
 		g_signal_connect(menu_item, "activate",
-			G_CALLBACK(menu_addword_item_activate_cd), GINT_TO_POINTER(0));
+			G_CALLBACK(menu_addword_item_activate_cb), GINT_TO_POINTER(0));
 
 		menu_item = image_menu_item_new(GTK_STOCK_REMOVE, _("Ignore All"));
 		gtk_container_add(GTK_CONTAINER(sc_info->edit_menu_sub), menu_item);
 		g_signal_connect(menu_item, "activate",
-			G_CALLBACK(menu_addword_item_activate_cd), GINT_TO_POINTER(1));
+			G_CALLBACK(menu_addword_item_activate_cb), GINT_TO_POINTER(1));
 
 		gtk_widget_show(sc_info->edit_menu);
 		gtk_widget_show(sc_info->edit_menu_sep);
@@ -459,6 +443,7 @@
 	{
 		setptr(sc_info->default_language, g_strdup(gdata));
 		sc_speller_reinit_enchant_dict();
+		sc_gui_update_menu();
 		update_labels();
 	}
 
@@ -505,48 +490,33 @@
 
 void sc_gui_update_menu(void)
 {
-	GtkWidget *child, *menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(sc_info->menu_item));
-	GList *l, *children = gtk_container_get_children(GTK_CONTAINER(menu));
-
-	sc_ignore_callback = TRUE;
-	for (l = children; l != NULL; l = g_list_next(l))
-	{
-		if ((child = GTK_BIN(l->data)->child) != NULL)
-		{
-			if (GTK_IS_LABEL(child))
-			{
-				if (utils_str_equal(sc_info->default_language, gtk_label_get_text(GTK_LABEL(child))))
-					gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(l->data), TRUE);
-			}
-		}
-	}
-	sc_ignore_callback = FALSE;
-
-	update_labels();
-}
-
-
-void sc_gui_create_menu(GtkWidget *sp_item)
-{
-	GtkWidget *menu, *menu_item;
+	GtkWidget *menu_item;
 	guint i;
+	static gboolean need_init = TRUE;
 	GSList *group = NULL;
 	gchar *label;
 
-	gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), sp_item);
+	if (need_init)
+	{
+		gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), sc_info->menu_item);
+		need_init = FALSE;
+	}
 
-	menu = gtk_menu_new();
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(sp_item), menu);
+	if (sc_info->main_menu != NULL)
+		gtk_widget_destroy(sc_info->main_menu);
 
+	sc_info->main_menu = gtk_menu_new();
+	gtk_menu_item_set_submenu(GTK_MENU_ITEM(sc_info->menu_item), sc_info->main_menu);
+
 	sc_info->submenu_item_default = gtk_menu_item_new_with_label(NULL);
-	gtk_container_add(GTK_CONTAINER(menu), sc_info->submenu_item_default);
+	gtk_container_add(GTK_CONTAINER(sc_info->main_menu), sc_info->submenu_item_default);
 	g_signal_connect(sc_info->submenu_item_default, "activate",
 		G_CALLBACK(menu_item_toggled_cb), NULL);
 
 	update_labels();
 
 	menu_item = gtk_separator_menu_item_new();
-	gtk_container_add(GTK_CONTAINER(menu), menu_item);
+	gtk_container_add(GTK_CONTAINER(sc_info->main_menu), menu_item);
 
 	sc_ignore_callback = TRUE;
 	for (i = 0; i < sc_info->dicts->len; i++)
@@ -556,10 +526,11 @@
 		group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menu_item));
 		if (utils_str_equal(sc_info->default_language, label))
 			gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), TRUE);
-		gtk_container_add(GTK_CONTAINER(menu), menu_item);
+		gtk_container_add(GTK_CONTAINER(sc_info->main_menu), menu_item);
 		g_signal_connect(menu_item, "toggled", G_CALLBACK(menu_item_toggled_cb), label);
 	}
 	sc_ignore_callback = FALSE;
+	gtk_widget_show_all(sc_info->main_menu);
 }
 
 

Modified: branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.h
===================================================================
--- branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.h	2009-09-30 19:35:07 UTC (rev 970)
+++ branches/geany-plugins/geany-plugins-0.18/spellcheck/src/gui.h	2009-09-30 19:41:19 UTC (rev 971)
@@ -38,14 +38,12 @@
 
 void sc_gui_create_edit_menu(void);
 
-void sc_gui_create_menu(GtkWidget *sp_item);
-
 void sc_gui_update_editor_menu_cb(GObject *obj, const gchar *word, gint pos,
 								  GeanyDocument *doc, gpointer user_data);
 
 void sc_gui_update_toolbar(void);
 
-void sc_gui_update_menu(void);
+void sc_gui_update_menu();
 
 void sc_gui_init(void);
 

Modified: branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.c
===================================================================
--- branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.c	2009-09-30 19:35:07 UTC (rev 970)
+++ branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.c	2009-09-30 19:41:19 UTC (rev 971)
@@ -23,28 +23,9 @@
  */
 
 
-#include "geany.h"
-#include "support.h"
+#include "geanyplugin.h"
 
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
 
-/*
-#ifdef G_OS_WIN32
-# include <windows.h>
-#endif
-*/
-
-#include "plugindata.h"
-
-#include "keybindings.h"
-#include "utils.h"
-#include "ui_utils.h"
-#include "filetypes.h"
-
-#include "geanyfunctions.h"
-
 #include "scplugin.h"
 #include "gui.h"
 #include "speller.h"
@@ -55,8 +36,8 @@
 GeanyFunctions	*geany_functions;
 
 
-PLUGIN_VERSION_CHECK(132)
-PLUGIN_SET_INFO(_("Spell Check"), _("Checks the spelling of the current document."), "0.4",
+PLUGIN_VERSION_CHECK(147);
+PLUGIN_SET_INFO(_("Spell Check"), _("Checks the spelling of the current document."), VERSION,
 			_("The Geany developer team"))
 
 
@@ -83,27 +64,23 @@
 };
 
 
-/* currently unused */
-#ifdef G_OS_WIN32
-#warning TODO check Windows support
-/* On Windows we need to find the Aspell installation prefix via the Windows Registry
- * and then set the prefix in the Aspell config object. */
-static void set_up_aspell_prefix(AspellConfig *config)
+static void populate_dict_combo(GtkComboBox *combo)
 {
-	char sTemp[1024];
-	HKEY hkey;
-	DWORD len = sizeof(sTemp);
+	guint i;
+	GtkTreeModel *model = gtk_combo_box_get_model(combo);
 
-	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Aspell"), 0,
-			KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS)
-		return;
+	gtk_list_store_clear(GTK_LIST_STORE(model));
+	for (i = 0; i < sc_info->dicts->len; i++)
+	{
+		gtk_combo_box_append_text(GTK_COMBO_BOX(combo), g_ptr_array_index(sc_info->dicts, i));
 
-	if (RegQueryValueEx(hkey, NULL, 0, NULL, (LPBYTE)sTemp, &len) == ERROR_SUCCESS)
-		aspell_config_replace(config, "prefix", sTemp);
-
-	RegCloseKey(hkey);
+		if (utils_str_equal(g_ptr_array_index(sc_info->dicts, i), sc_info->default_language))
+			gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i);
+	}
+	/* if the default language couldn't be selected, select the first available language */
+	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) == -1)
+		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
 }
-#endif
 
 
 static void configure_response_cb(GtkDialog *dialog, gint response, gpointer user_data)
@@ -113,9 +90,13 @@
 		GKeyFile *config = g_key_file_new();
 		gchar *data;
 		gchar *config_dir = g_path_get_dirname(sc_info->config_file);
+		GtkComboBox *combo = GTK_COMBO_BOX(g_object_get_data(G_OBJECT(dialog), "combo"));
 
-		setptr(sc_info->default_language, gtk_combo_box_get_active_text(GTK_COMBO_BOX(
-			g_object_get_data(G_OBJECT(dialog), "combo"))));
+		setptr(sc_info->default_language, gtk_combo_box_get_active_text(combo));
+#ifdef HAVE_ENCHANT_1_5
+		setptr(sc_info->dictionary_dir, g_strdup(gtk_entry_get_text(GTK_ENTRY(
+			g_object_get_data(G_OBJECT(dialog), "dict_dir")))));
+#endif
 		sc_speller_reinit_enchant_dict();
 
 		sc_info->check_while_typing = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
@@ -133,9 +114,11 @@
 		g_key_file_set_boolean(config, "spellcheck", "check_while_typing", sc_info->check_while_typing);
 		g_key_file_set_boolean(config, "spellcheck", "use_msgwin", sc_info->use_msgwin);
 		g_key_file_set_boolean(config, "spellcheck", "show_toolbar_item", sc_info->show_toolbar_item);
+		g_key_file_set_string(config, "spellcheck", "dictionary_dir", sc_info->dictionary_dir);
 
 		sc_gui_update_toolbar();
 		sc_gui_update_menu();
+		populate_dict_combo(combo);
 
 		if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0)
 		{
@@ -173,6 +156,8 @@
 		"spellcheck", "check_while_typing", FALSE);
 	sc_info->show_toolbar_item = utils_get_setting_boolean(config,
 		"spellcheck", "show_toolbar_item", TRUE);
+	sc_info->dictionary_dir = utils_get_setting_string(config,
+		"spellcheck", "dictionary_dir", NULL);
 	sc_info->use_msgwin = utils_get_setting_boolean(config, "spellcheck", "use_msgwin", FALSE);
 	g_key_file_free(config);
 	g_free(default_lang);
@@ -188,7 +173,7 @@
 	sc_speller_init();
 
 	sc_gui_create_edit_menu();
-	sc_gui_create_menu(sc_info->menu_item);
+	sc_gui_update_menu();
 	gtk_widget_show_all(sc_info->menu_item);
 
 	sc_info->signal_id = g_signal_connect(geany->main_widgets->window,
@@ -203,10 +188,47 @@
 }
 
 
+#ifdef HAVE_ENCHANT_1_5
+static void dictionary_dir_button_clicked_cb(GtkButton *button, gpointer item)
+{
+	GtkWidget *dialog;
+	gchar *text;
+
+	/* initialize the dialog */
+	dialog = gtk_file_chooser_dialog_new(_("Select Directory"), NULL,
+					GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
+
+	text = utils_get_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(item)));
+	if (NZV(text))
+		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), text);
+
+	/* run it */
+	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
+	{
+		gchar *utf8_filename, *tmp;
+
+		tmp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+		utf8_filename = utils_get_utf8_from_locale(tmp);
+
+		gtk_entry_set_text(GTK_ENTRY(item), utf8_filename);
+
+		g_free(utf8_filename);
+		g_free(tmp);
+	}
+
+	gtk_widget_destroy(dialog);
+}
+#endif
+
+
 GtkWidget *plugin_configure(GtkDialog *dialog)
 {
 	GtkWidget *label, *vbox, *combo, *check_type, *check_msgwin, *check_toolbar;
-	guint i;
+#ifdef HAVE_ENCHANT_1_5
+	GtkWidget *entry_dir, *hbox, *button, *image;
+#endif
 
 	vbox = gtk_vbox_new(FALSE, 6);
 
@@ -228,24 +250,43 @@
 	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 3);
 
 	combo = gtk_combo_box_new_text();
+	populate_dict_combo(GTK_COMBO_BOX(combo));
 
-	for (i = 0; i < sc_info->dicts->len; i++)
-	{
-		gtk_combo_box_append_text(GTK_COMBO_BOX(combo), g_ptr_array_index(sc_info->dicts, i));
-
-		if (utils_str_equal(g_ptr_array_index(sc_info->dicts, i), sc_info->default_language))
-			gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i);
-	}
-	/* if the default language couldn't be selected, select the first available language */
-	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) == -1)
-		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
-
 	if (sc_info->dicts->len > 20)
 		gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo), 3);
 	else if (sc_info->dicts->len > 10)
 		gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo), 2);
 	gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 6);
 
+#ifdef HAVE_ENCHANT_1_5
+	label = gtk_label_new_with_mnemonic(_("_Directory to look for dictionary files:"));
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+
+	entry_dir = gtk_entry_new();
+	ui_entry_add_clear_icon(GTK_ENTRY(entry_dir));
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_dir);
+	ui_widget_set_tooltip_text(entry_dir,
+		_("Read additional dictionary files from this directory. "
+		  "For now, this only works with myspell dictionaries."));
+	if (NZV(sc_info->dictionary_dir))
+		gtk_entry_set_text(GTK_ENTRY(entry_dir), sc_info->dictionary_dir);
+
+	button = gtk_button_new();
+	g_signal_connect(button, "clicked",
+		G_CALLBACK(dictionary_dir_button_clicked_cb), entry_dir);
+
+	image = gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_BUTTON);
+	gtk_container_add(GTK_CONTAINER(button), image);
+
+	hbox = gtk_hbox_new(FALSE, 6);
+	gtk_box_pack_start_defaults(GTK_BOX(hbox), entry_dir);
+	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+	g_object_set_data(G_OBJECT(dialog), "dict_dir", entry_dir);
+#endif
 	g_object_set_data(G_OBJECT(dialog), "combo", combo);
 	g_object_set_data(G_OBJECT(dialog), "check_type", check_type);
 	g_object_set_data(G_OBJECT(dialog), "check_msgwin", check_msgwin);
@@ -279,14 +320,6 @@
 
 void plugin_cleanup(void)
 {
-	guint i;
-
-	for (i = 0; i < sc_info->dicts->len; i++)
-	{
-		g_free(g_ptr_array_index(sc_info->dicts, i));
-	}
-	g_ptr_array_free(sc_info->dicts, TRUE);
-
 	g_signal_handler_disconnect(geany->main_widgets->window, sc_info->signal_id);
 
 	gtk_widget_destroy(sc_info->edit_menu);
@@ -297,6 +330,7 @@
 	sc_gui_free();
 	sc_speller_free();
 
+	g_free(sc_info->dictionary_dir);
 	g_free(sc_info->default_language);
 	g_free(sc_info->config_file);
 	gtk_widget_destroy(sc_info->menu_item);

Modified: branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.h
===================================================================
--- branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.h	2009-09-30 19:35:07 UTC (rev 970)
+++ branches/geany-plugins/geany-plugins-0.18/spellcheck/src/scplugin.h	2009-09-30 19:41:19 UTC (rev 971)
@@ -32,11 +32,13 @@
 {
 	gchar *config_file;
 	gchar *default_language;
+	gchar *dictionary_dir;
 	gboolean use_msgwin;
 	gboolean check_while_typing;
 	gboolean show_toolbar_item;
 	gulong signal_id;
 	GPtrArray *dicts;
+	GtkWidget *main_menu;
 	GtkWidget *menu_item;
 	GtkWidget *submenu_item_default;
 	GtkWidget *edit_menu;

Modified: branches/geany-plugins/geany-plugins-0.18/spellcheck/src/speller.c
===================================================================
--- branches/geany-plugins/geany-plugins-0.18/spellcheck/src/speller.c	2009-09-30 19:35:07 UTC (rev 970)
+++ branches/geany-plugins/geany-plugins-0.18/spellcheck/src/speller.c	2009-09-30 19:41:19 UTC (rev 971)
@@ -23,24 +23,14 @@
  */
 
 
-#include "geany.h"
-#include "support.h"
+#include "geanyplugin.h"
 
+#include "scintilla/SciLexer.h"
+
 #include <string.h>
 #include <ctype.h>
 #include <enchant.h>
 
-#include "plugindata.h"
-
-#include "document.h"
-#include "editor.h"
-#include "msgwindow.h"
-#include "utils.h"
-#include "ui_utils.h"
-#include "scintilla/SciLexer.h"
-
-#include "geanyfunctions.h"
-
 #include "speller.h"
 #include "scplugin.h"
 
@@ -252,42 +242,6 @@
 }
 
 
-void sc_speller_reinit_enchant_dict(void)
-{
-	gchar *lang = sc_info->default_language;
-
-	/* Release a previous dict object */
-	if (sc_speller_dict != NULL)
-		enchant_broker_free_dict(sc_speller_broker, sc_speller_dict);
-
-	/* Check if the stored default dictionary is (still) avaiable, fall back to the first
-	 * one in the list if not */
-	if (! check_default_lang())
-	{
-		if (sc_info->dicts->len > 0)
-		{
-			lang = g_ptr_array_index(sc_info->dicts, 0);
-			g_warning("Stored language ('%s') could not be loaded. Falling back to '%s'",
-				sc_info->default_language, lang);
-		}
-		else
-			g_warning("Stored language ('%s') could not be loaded.", sc_info->default_language);
-	}
-
-	/* Request new dict object */
-	sc_speller_dict = enchant_broker_request_dict(sc_speller_broker, lang);
-	if (sc_speller_dict == NULL)
-	{
-		broker_init_failed();
-		gtk_widget_set_sensitive(sc_info->menu_item, FALSE);
-	}
-	else
-	{
-		gtk_widget_set_sensitive(sc_info->menu_item, TRUE);
-	}
-}
-
-
 gchar *sc_speller_get_default_lang(void)
 {
 	const gchar *lang = g_getenv("LANG");
@@ -343,8 +297,24 @@
 }
 
 
+static void sc_speller_dicts_free(void)
+{
+	guint i;
+	if (sc_info->dicts != NULL)
+	{
+		for (i = 0; i < sc_info->dicts->len; i++)
+		{
+			g_free(g_ptr_array_index(sc_info->dicts, i));
+		}
+		g_ptr_array_free(sc_info->dicts, TRUE);
+	}
+}
+
+
 static void create_dicts_array(void)
 {
+	sc_speller_dicts_free();
+
 	sc_info->dicts = g_ptr_array_new();
 
 	enchant_broker_list_dicts(sc_speller_broker, add_dict_array, sc_info->dicts);
@@ -406,18 +376,73 @@
 }
 
 
+void sc_speller_reinit_enchant_dict(void)
+{
+	gchar *lang = sc_info->default_language;
+
+	/* Release a previous dict object */
+	if (sc_speller_dict != NULL)
+		enchant_broker_free_dict(sc_speller_broker, sc_speller_dict);
+
+#if HAVE_ENCHANT_1_5
+	{
+		const gchar *old_path;
+		gchar *new_path;
+
+		/* add custom dictionary path for myspell (primarily used on Windows) */
+		old_path = enchant_broker_get_param(sc_speller_broker, "enchant.myspell.dictionary.path");
+		if (old_path != NULL)
+			new_path = g_strconcat(
+				old_path, G_SEARCHPATH_SEPARATOR_S, sc_info->dictionary_dir, NULL);
+		else
+			new_path = sc_info->dictionary_dir;
+
+		enchant_broker_set_param(sc_speller_broker, "enchant.myspell.dictionary.path", new_path);
+		if (new_path != sc_info->dictionary_dir)
+			g_free(new_path);
+	}
+#endif
+	create_dicts_array();
+
+	/* Check if the stored default dictionary is (still) avaiable, fall back to the first
+	 * one in the list if not */
+	if (! check_default_lang())
+	{
+		if (sc_info->dicts->len > 0)
+		{
+			lang = g_ptr_array_index(sc_info->dicts, 0);
+			g_warning("Stored language ('%s') could not be loaded. Falling back to '%s'",
+				sc_info->default_language, lang);
+		}
+		else
+			g_warning("Stored language ('%s') could not be loaded.", sc_info->default_language);
+	}
+
+	/* Request new dict object */
+	sc_speller_dict = enchant_broker_request_dict(sc_speller_broker, lang);
+	if (sc_speller_dict == NULL)
+	{
+		broker_init_failed();
+		gtk_widget_set_sensitive(sc_info->menu_item, FALSE);
+	}
+	else
+	{
+		gtk_widget_set_sensitive(sc_info->menu_item, TRUE);
+	}
+}
+
+
 void sc_speller_init(void)
 {
 	sc_speller_broker = enchant_broker_init();
 
-	create_dicts_array();
-
 	sc_speller_reinit_enchant_dict();
 }
 
 
 void sc_speller_free(void)
 {
+	sc_speller_dicts_free();
 	if (sc_speller_dict != NULL)
 		enchant_broker_free_dict(sc_speller_broker, sc_speller_dict);
 	enchant_broker_free(sc_speller_broker);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list