Revision: 591 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=591&view=rev Author: eht16 Date: 2009-04-17 13:16:02 +0000 (Fri, 17 Apr 2009)
Log Message: ----------- List the available languages in the Tools menu as radio items to easily indicate which language is currently in use. Show the default language also next to the 'Default' menu item.
Modified Paths: -------------- trunk/spellcheck/ChangeLog trunk/spellcheck/src/gui.c trunk/spellcheck/src/gui.h trunk/spellcheck/src/scplugin.c
Modified: trunk/spellcheck/ChangeLog =================================================================== --- trunk/spellcheck/ChangeLog 2009-04-13 19:32:20 UTC (rev 590) +++ trunk/spellcheck/ChangeLog 2009-04-17 13:16:02 UTC (rev 591) @@ -1,3 +1,11 @@ +2009-04-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/gui.c, src/scplugin.c, src/gui.h: + List the available languages in the Tools menu as radio items + to easily indicate which language is currently in use. + Show the default language also next to the 'Default' menu item. + + 2009-03-05 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* New release: Spell Check 0.3.
Modified: trunk/spellcheck/src/gui.c =================================================================== --- trunk/spellcheck/src/gui.c 2009-04-13 19:32:20 UTC (rev 590) +++ trunk/spellcheck/src/gui.c 2009-04-17 13:16:02 UTC (rev 591) @@ -56,7 +56,7 @@
/* Flag to indicate that a callback function will be triggered by generating the appropriate event * but the callback should be ignored. */ -static gboolean ignore_sc_callback = FALSE; +static gboolean sc_ignore_callback = FALSE;
@@ -71,7 +71,7 @@
static void toolbar_item_toggled_cb(GtkToggleToolButton *button, gpointer user_data) { - if (ignore_sc_callback) + if (sc_ignore_callback) return;
sc_info->check_while_typing = gtk_toggle_tool_button_get_active(button); @@ -108,10 +108,10 @@ } gtk_widget_show(GTK_WIDGET(sc_info->toolbar_button));
- ignore_sc_callback = TRUE; + sc_ignore_callback = TRUE; gtk_toggle_tool_button_set_active( GTK_TOGGLE_TOOL_BUTTON(sc_info->toolbar_button), sc_info->check_while_typing); - ignore_sc_callback = FALSE; + sc_ignore_callback = FALSE; } }
@@ -398,18 +398,25 @@ }
-static void menu_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata) +static void menu_item_toggled_cb(GtkCheckMenuItem *menuitem, gpointer gdata) { GeanyDocument *doc;
+ if (sc_ignore_callback) + return; + + if (menuitem != NULL && ! gtk_check_menu_item_get_active(menuitem)) + return; + doc = document_get_current();
/* Another language was chosen from the menu item, so make it default for this session. */ if (gdata != NULL) + { setptr(sc_info->default_language, g_strdup(gdata)); + sc_speller_reinit_enchant_dict(); + }
- sc_speller_reinit_enchant_dict(); - editor_indicator_clear(doc->editor, GEANY_INDICATOR_ERROR); if (sc_info->use_msgwin) { @@ -421,6 +428,12 @@ }
+static void menu_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata) +{ + menu_item_toggled_cb(NULL, gdata); +} + + void sc_gui_kb_run_activate_cb(guint key_id) { menu_item_activate_cb(NULL, NULL); @@ -451,32 +464,61 @@ }
-GtkWidget *sc_gui_create_menu(GtkWidget *sp_item) +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; +} + + +void sc_gui_create_menu(GtkWidget *sp_item) +{ GtkWidget *menu, *menu_item; guint i; + GSList *group = NULL; + gchar *label;
gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), sp_item);
menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(sp_item), menu);
- sc_info->submenu_item_default = gtk_menu_item_new_with_mnemonic(_("Default")); + label = g_strdup_printf(_("Default (%s)"), + (sc_info->default_language != NULL) ? sc_info->default_language : _("unknown")); + sc_info->submenu_item_default = gtk_menu_item_new_with_label(label); gtk_container_add(GTK_CONTAINER(menu), sc_info->submenu_item_default); - g_signal_connect(sc_info->submenu_item_default, "activate", G_CALLBACK(menu_item_activate_cb), NULL); + g_signal_connect(sc_info->submenu_item_default, "activate", G_CALLBACK(menu_item_toggled_cb), NULL); + g_free(label);
menu_item = gtk_separator_menu_item_new(); gtk_container_add(GTK_CONTAINER(menu), menu_item);
+ sc_ignore_callback = TRUE; for (i = 0; i < sc_info->dicts->len; i++) { - menu_item = gtk_menu_item_new_with_label(g_ptr_array_index(sc_info->dicts, i)); + label = g_ptr_array_index(sc_info->dicts, i); + menu_item = gtk_radio_menu_item_new_with_label(group, label); + 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); - g_signal_connect(menu_item, "activate", - G_CALLBACK(menu_item_activate_cb), g_ptr_array_index(sc_info->dicts, i)); + g_signal_connect(menu_item, "toggled", G_CALLBACK(menu_item_toggled_cb), label); } - - return sp_item; + sc_ignore_callback = FALSE; }
Modified: trunk/spellcheck/src/gui.h =================================================================== --- trunk/spellcheck/src/gui.h 2009-04-13 19:32:20 UTC (rev 590) +++ trunk/spellcheck/src/gui.h 2009-04-17 13:16:02 UTC (rev 591) @@ -41,13 +41,15 @@
void sc_gui_create_edit_menu(void);
-GtkWidget *sc_gui_create_menu(GtkWidget *sp_item); +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_toolbar_update(void);
+void sc_gui_update_menu(void); + void sc_gui_init(void);
void sc_gui_free(void);
Modified: trunk/spellcheck/src/scplugin.c =================================================================== --- trunk/spellcheck/src/scplugin.c 2009-04-13 19:32:20 UTC (rev 590) +++ trunk/spellcheck/src/scplugin.c 2009-04-17 13:16:02 UTC (rev 591) @@ -135,6 +135,7 @@ g_key_file_set_boolean(config, "spellcheck", "show_toolbar_item", sc_info->show_toolbar_item);
sc_gui_toolbar_update(); + sc_gui_update_menu();
if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { @@ -156,7 +157,6 @@
void plugin_init(GeanyData *data) { - GtkWidget *sp_item; GKeyFile *config = g_key_file_new(); gchar *default_lang;
@@ -188,8 +188,8 @@ sc_speller_init();
sc_gui_create_edit_menu(); - sp_item = sc_gui_create_menu(sc_info->menu_item); - gtk_widget_show_all(sp_item); + sc_gui_create_menu(sc_info->menu_item); + gtk_widget_show_all(sc_info->menu_item);
sc_info->signal_id = g_signal_connect(geany->main_widgets->window, "key-release-event", G_CALLBACK(sc_gui_key_release_cb), NULL);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.