Revision: 969 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=969&view=rev Author: eht16 Date: 2009-09-30 19:26:03 +0000 (Wed, 30 Sep 2009)
Log Message: ----------- Allow setting a custom dictionary directory without reloading the plugin. Minor fixes.
Modified Paths: -------------- trunk/geany-plugins/spellcheck/ChangeLog trunk/geany-plugins/spellcheck/src/gui.c trunk/geany-plugins/spellcheck/src/gui.h trunk/geany-plugins/spellcheck/src/scplugin.c trunk/geany-plugins/spellcheck/src/scplugin.h trunk/geany-plugins/spellcheck/src/speller.c
Modified: trunk/geany-plugins/spellcheck/ChangeLog =================================================================== --- trunk/geany-plugins/spellcheck/ChangeLog 2009-09-30 19:16:56 UTC (rev 968) +++ trunk/geany-plugins/spellcheck/ChangeLog 2009-09-30 19:26:03 UTC (rev 969) @@ -1,3 +1,11 @@ +2009-09-30 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/scplugin.c, src/scplugin.h, src/gui.c, src/gui.h, src/speller.c: + Allow setting a custom dictionary directory without reloading + the plugin. + Minor fixes. + + 2009-09-27 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/scplugin.c, src/speller.c, src/scplugin.h:
Modified: trunk/geany-plugins/spellcheck/src/gui.c =================================================================== --- trunk/geany-plugins/spellcheck/src/gui.c 2009-09-30 19:16:56 UTC (rev 968) +++ trunk/geany-plugins/spellcheck/src/gui.c 2009-09-30 19:26:03 UTC (rev 969) @@ -142,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; @@ -282,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); @@ -443,6 +443,7 @@ { setptr(sc_info->default_language, g_strdup(gdata)); sc_speller_reinit_enchant_dict(); + sc_gui_update_menu(); update_labels(); }
@@ -489,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++) @@ -540,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: trunk/geany-plugins/spellcheck/src/gui.h =================================================================== --- trunk/geany-plugins/spellcheck/src/gui.h 2009-09-30 19:16:56 UTC (rev 968) +++ trunk/geany-plugins/spellcheck/src/gui.h 2009-09-30 19:26:03 UTC (rev 969) @@ -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: trunk/geany-plugins/spellcheck/src/scplugin.c =================================================================== --- trunk/geany-plugins/spellcheck/src/scplugin.c 2009-09-30 19:16:56 UTC (rev 968) +++ trunk/geany-plugins/spellcheck/src/scplugin.c 2009-09-30 19:26:03 UTC (rev 969) @@ -64,6 +64,25 @@ };
+static void populate_dict_combo(GtkComboBox *combo) +{ + guint i; + GtkTreeModel *model = gtk_combo_box_get_model(combo); + + 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 (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); +} + + static void configure_response_cb(GtkDialog *dialog, gint response, gpointer user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) @@ -71,11 +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( @@ -97,6 +118,7 @@
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) { @@ -151,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, @@ -207,7 +229,6 @@ #ifdef HAVE_ENCHANT_1_5 GtkWidget *entry_dir, *hbox, *button, *image; #endif - guint i;
vbox = gtk_vbox_new(FALSE, 6);
@@ -229,18 +250,8 @@ 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) @@ -253,6 +264,7 @@ 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. " @@ -308,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);
Modified: trunk/geany-plugins/spellcheck/src/scplugin.h =================================================================== --- trunk/geany-plugins/spellcheck/src/scplugin.h 2009-09-30 19:16:56 UTC (rev 968) +++ trunk/geany-plugins/spellcheck/src/scplugin.h 2009-09-30 19:26:03 UTC (rev 969) @@ -38,6 +38,7 @@ gboolean show_toolbar_item; gulong signal_id; GPtrArray *dicts; + GtkWidget *main_menu; GtkWidget *menu_item; GtkWidget *submenu_item_default; GtkWidget *edit_menu;
Modified: trunk/geany-plugins/spellcheck/src/speller.c =================================================================== --- trunk/geany-plugins/spellcheck/src/speller.c 2009-09-30 19:16:56 UTC (rev 968) +++ trunk/geany-plugins/spellcheck/src/speller.c 2009-09-30 19:26:03 UTC (rev 969) @@ -242,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"); @@ -333,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); @@ -396,35 +376,73 @@ }
-void sc_speller_init(void) +void sc_speller_reinit_enchant_dict(void) { - sc_speller_broker = enchant_broker_init(); + 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, *dict_dir; + gchar *new_path;
/* add custom dictionary path for myspell (primarily used on Windows) */ - dict_dir = sc_info->dictionary_dir; 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, dict_dir, NULL); + new_path = g_strconcat( + old_path, G_SEARCHPATH_SEPARATOR_S, sc_info->dictionary_dir, NULL); else - new_path = dict_dir; + new_path = sc_info->dictionary_dir;
enchant_broker_set_param(sc_speller_broker, "enchant.myspell.dictionary.path", new_path); - if (new_path != dict_dir) + 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(); + 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.
plugins-commits@lists.geany.org