From: Melvin Hadasht Date: Wed, 6 Feb 2002 23:11:35 +0000 (+0000) Subject: Made possible fast switching with last dictionary. X-Git-Tag: rel_0_7_1~30 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=7ca5f14a2499189af457af146abd99e7e3cbddb0 Made possible fast switching with last dictionary. --- diff --git a/ChangeLog.claws b/ChangeLog.claws index 85cfed4d9..df143d624 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,4 +1,12 @@ -2002-02-06 |melvin] 0.7.0claws52 +2002-02-06 [melvin] 0.7.0claws53 + + * src/prefs_common.[ch] + * src/gtkspell.[ch] + * src/compose.c + Made possible to switch quickly to last used dictionary + which makes checking bilingual documents easier. + +2002-02-06 [melvin] 0.7.0claws52 * po/POTFILES.in Added forgotten new file src/prefs_actions.c diff --git a/configure.in b/configure.in index 537a4e89c..a4b6cb0c5 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=7 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws52 +EXTRA_VERSION=claws53 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/compose.c b/src/compose.c index 55ac1702f..8e36fe79c 100644 --- a/src/compose.c +++ b/src/compose.c @@ -4678,6 +4678,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode) conv_get_current_charset_str(), prefs_common.misspelled_col, prefs_common.check_while_typing, + prefs_common.use_alternate, GTK_STEXT(text)); if (!gtkpspell) { alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message); diff --git a/src/gtkspell.c b/src/gtkspell.c index 09e3bff83..30854bc5a 100644 --- a/src/gtkspell.c +++ b/src/gtkspell.c @@ -132,6 +132,9 @@ static void replace_word_cb (GtkWidget *w, gpointer data); static void replace_real_word (GtkPspell *gtkpspell, gchar *newword); +static void check_with_alternate_cb (GtkWidget *w, + gpointer data); +static void use_alternate_dict (GtkPspell *gtkpspell); static void toggle_check_while_typing_cb (GtkWidget *w, gpointer data); @@ -151,6 +154,8 @@ static gboolean cancel_menu_cb (GtkMenuShell *w, gpointer data); static void change_dict_cb (GtkWidget *w, GtkPspell *gtkpspell); +static void switch_to_alternate_cb (GtkWidget *w, + gpointer data); /* Misc. helper functions */ static void set_point_continue (GtkPspell *gtkpspell); @@ -256,6 +261,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary, const gchar *encoding, gint misspelled_color, gboolean check_while_typing, + gboolean use_alternate, GtkSText *gtktext) { Dictionary *dict = g_new0(Dictionary, 1); @@ -275,6 +281,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary, gtkpspell = g_new(GtkPspell, 1); gtkpspell->gtkpspeller = gtkpspeller; + gtkpspell->alternate_speller = NULL; gtkpspell->theword[0] = 0x00; gtkpspell->start_pos = 0; gtkpspell->end_pos = 0; @@ -291,6 +298,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary, gtkpspell->default_sug_mode = PSPELL_FASTMODE; gtkpspell->max_sug = -1; gtkpspell->suggestions_list = NULL; + gtkpspell->use_alternate = use_alternate; allocate_color(gtkpspell, misspelled_color); @@ -324,6 +332,9 @@ void gtkpspell_delete(GtkPspell * gtkpspell) gtkpspeller_delete(gtkpspell->gtkpspeller); + if (gtkpspell->use_alternate && gtkpspell->alternate_speller) + gtkpspeller_delete(gtkpspell->alternate_speller); + if (gtkpspell->sug_menu) gtk_widget_destroy(gtkpspell->sug_menu); if (gtkpspell->popup_config_menu) @@ -580,6 +591,8 @@ static GtkPspeller *gtkpspeller_real_delete(GtkPspeller *gtkpspeller) dictionary_delete(gtkpspeller->dictionary); + debug_print(_("Pspell: gtkpspeller %0x deleted.\n"), + (gint) gtkpspeller); g_free(gtkpspeller); return NULL; @@ -1033,7 +1046,6 @@ static void continue_check(gpointer *data) { GtkPspell *gtkpspell = (GtkPspell *) data; gint pos = gtk_editable_get_position(GTK_EDITABLE(gtkpspell->gtktext)); - if (pos < gtkpspell->end_check_pos && gtkpspell->misspelled) gtkpspell->misspelled = check_next_prev(gtkpspell, TRUE); else @@ -1258,6 +1270,35 @@ static void deactivate_sug_menu_cb(GtkObject *w, gpointer data) gtk_menu_shell_deactivate(menu_shell); } +static void check_with_alternate_cb(GtkWidget *w, + gpointer data) +{ + GtkPspell *gtkpspell = (GtkPspell *) data; + gint misspelled; + gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent)); + + use_alternate_dict(gtkpspell); + misspelled = check_at(gtkpspell, gtkpspell->start_pos); + + if (!gtkpspell->continue_check) { + gtkpspell->misspelled = misspelled; + if (gtkpspell->misspelled) { + misspelled_suggest(gtkpspell, gtkpspell->theword); + gtk_stext_set_point(GTK_STEXT(gtkpspell->gtktext), + gtkpspell->end_pos); + gtk_editable_set_position(GTK_EDITABLE(gtkpspell->gtktext), + gtkpspell->end_pos); + gtk_menu_popup(make_sug_menu(gtkpspell), NULL, NULL, + set_menu_pos, gtkpspell, 0, + GDK_CURRENT_TIME); + return; + } + } else + gtkpspell->orig_pos = gtkpspell->start_pos; + + set_point_continue(gtkpspell); +} + static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data) { GtkWidget *dialog; @@ -1588,6 +1629,20 @@ gint gtkpspell_get_sugmode_from_option_menu(GtkOptionMenu *optmenu) return sugmode; } + +static void use_alternate_dict(GtkPspell *gtkpspell) +{ + GtkPspeller *tmp; + + tmp = gtkpspell->gtkpspeller; + gtkpspell->gtkpspeller = gtkpspell->alternate_speller; + gtkpspell->alternate_speller = tmp; + + if (gtkpspell->config_menu) + populate_submenu(gtkpspell, gtkpspell->config_menu); +} + + #if 0 /* Experimenal */ void gtkpspell_set_primary_dict(GtkPspell *gtkpspell, gchar *dict, gchar *encoding) { @@ -1709,8 +1764,9 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell) gtk_signal_connect(GTK_OBJECT(menu), "cancel", GTK_SIGNAL_FUNC(cancel_menu_cb), gtkpspell); - caption = g_strdup_printf(_("Unknown word: \"%s\""), - (unsigned char*) l->data); + caption = g_strdup_printf(_("\"%s\" unknown in %s"), + (unsigned char*) l->data, + gtkpspell->gtkpspeller->dictionary->dictname); item = gtk_menu_item_new_with_label(caption); gtk_widget_show(item); gtk_menu_append(GTK_MENU(menu), item); @@ -1748,6 +1804,19 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell) gtk_widget_add_accelerator(item, "activate", accel, GDK_R, 0, GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE); + if (gtkpspell->use_alternate && gtkpspell->alternate_speller) { + caption = g_strdup_printf(_("Check with %s"), + gtkpspell->alternate_speller->dictionary->dictname); + item = gtk_menu_item_new_with_label(caption); + g_free(caption); + gtk_widget_show(item); + gtk_menu_append(GTK_MENU(menu), item); + gtk_signal_connect(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(check_with_alternate_cb), + gtkpspell); + gtk_widget_add_accelerator(item, "activate", accel, GDK_X, 0, + GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE); + } item = gtk_menu_item_new(); gtk_widget_show(item); gtk_menu_append(GTK_MENU(menu), item); @@ -1838,7 +1907,19 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu) item = gtk_menu_item_new(); gtk_widget_show(item); gtk_menu_append(GTK_MENU(menu), item); - + + if (gtkpspell->use_alternate && gtkpspell->alternate_speller) { + dictname = g_strdup_printf(_("Use alternate (%s)"), + gtkpspell->alternate_speller->dictionary->dictname); + item = gtk_menu_item_new_with_label(dictname); + g_free(dictname); + gtk_signal_connect(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(switch_to_alternate_cb), + gtkpspell); + gtk_widget_show(item); + gtk_menu_append(GTK_MENU(menu), item); + } + item = gtk_check_menu_item_new_with_label(_("Fast Mode")); if (ispell || gtkpspell->gtkpspeller->sug_mode == PSPELL_FASTMODE) gtk_widget_set_sensitive(GTK_WIDGET(item),FALSE); @@ -2037,6 +2118,13 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell) dict = g_new0(Dictionary, 1); dict->fullname = g_strdup(fullname); dict->encoding = g_strdup(gtkpspell->gtkpspeller->dictionary->encoding); + + if (gtkpspell->use_alternate && gtkpspell->alternate_speller && + dict == gtkpspell->alternate_speller->dictionary) { + use_alternate_dict(gtkpspell); + dictionary_delete(dict); + return; + } gtkpspeller = gtkpspeller_new(dict); @@ -2048,7 +2136,13 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell) gtkpspell_alert_dialog(message); g_free(message); } else { - gtkpspeller_delete(gtkpspell->gtkpspeller); + if (gtkpspell->use_alternate) { + if (gtkpspell->alternate_speller) + gtkpspeller_delete(gtkpspell->alternate_speller); + gtkpspell->alternate_speller = gtkpspell->gtkpspeller; + } else + gtkpspeller_delete(gtkpspell->gtkpspeller); + gtkpspell->gtkpspeller = gtkpspeller; gtkpspell_set_sug_mode(gtkpspell, sug_mode); } @@ -2060,6 +2154,13 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell) } +static void switch_to_alternate_cb(GtkWidget *w, + gpointer data) +{ + GtkPspell *gtkpspell = (GtkPspell *) data; + use_alternate_dict(gtkpspell); +} + /******************************************************************************/ /* Misc. helper functions */ diff --git a/src/gtkspell.h b/src/gtkspell.h index 5f98d81eb..0ec1b650b 100644 --- a/src/gtkspell.h +++ b/src/gtkspell.h @@ -65,6 +65,7 @@ typedef void (*ContCheckFunc) (gpointer *gtkpspell); #define GTKPSPELLWORDSIZE 1024 typedef struct _GtkPspell { GtkPspeller *gtkpspeller; + GtkPspeller *alternate_speller; gchar theword[GTKPSPELLWORDSIZE]; gint start_pos; gint end_pos; @@ -72,6 +73,7 @@ typedef struct _GtkPspell { gint end_check_pos; gboolean misspelled; gboolean check_while_typing; + gboolean use_alternate; ContCheckFunc continue_check; #if 0 @@ -108,6 +110,7 @@ GtkPspell* gtkpspell_new (const gchar *dictionary, const gchar *encoding, gint misspelled_color, gboolean check_while_typing, + gboolean use_alternate, GtkSText *gtktext); void gtkpspell_delete (GtkPspell *gtkpspell); diff --git a/src/prefs_common.c b/src/prefs_common.c index d4847c06e..c98aae84d 100644 --- a/src/prefs_common.c +++ b/src/prefs_common.c @@ -132,6 +132,7 @@ static struct Spelling { GtkWidget *optmenu_dictionary; GtkWidget *optmenu_sugmode; GtkWidget *misspelled_btn; + GtkWidget *checkbtn_use_alternate; GtkWidget *checkbtn_check_while_typing; } spelling; #endif @@ -363,6 +364,9 @@ static PrefParam param[] = { {"pspell_sugmode", "1", &prefs_common.pspell_sugmode, P_INT, &spelling.optmenu_sugmode, prefs_speller_sugmode_set_data_from_optmenu, prefs_speller_sugmode_set_optmenu }, + {"use_alternate_dict", "FALSE", &prefs_common.use_alternate, + P_BOOL, &spelling.checkbtn_use_alternate, + prefs_set_data_from_toggle, prefs_set_toggle}, {"check_while_typing", "TRUE", &prefs_common.check_while_typing, P_BOOL, &spelling.checkbtn_check_while_typing, prefs_set_data_from_toggle, prefs_set_toggle}, @@ -1299,7 +1303,8 @@ static void prefs_dictionary_set_optmenu(PrefParam *pparam) for (cur = GTK_MENU_SHELL(menu)->children; cur != NULL; cur = cur->next) { menuitem = GTK_WIDGET(cur->data); - dict_name = gtk_object_get_data(GTK_OBJECT(menuitem), "dict_name"); + dict_name = gtk_object_get_data(GTK_OBJECT(menuitem), + "dict_name"); if (!strcmp2(dict_name, *((gchar **)pparam->data))) { gtk_option_menu_set_history(optmenu, n); return; @@ -1352,8 +1357,9 @@ static void prefs_spelling_checkbtn_enable_pspell_toggle_cb gtk_widget_set_sensitive(spelling.optmenu_dictionary, toggled); gtk_widget_set_sensitive(spelling.optmenu_sugmode, toggled); gtk_widget_set_sensitive(spelling.btn_pspell_path, toggled); - gtk_widget_set_sensitive(spelling.misspelled_btn, toggled); - gtk_widget_set_sensitive(spelling.checkbtn_check_while_typing, toggled); + gtk_widget_set_sensitive(spelling.misspelled_btn, toggled); + gtk_widget_set_sensitive(spelling.checkbtn_use_alternate, toggled); + gtk_widget_set_sensitive(spelling.checkbtn_check_while_typing, toggled); } static void prefs_spelling_btn_pspell_path_clicked_cb(GtkWidget *widget, @@ -1372,23 +1378,28 @@ static void prefs_spelling_btn_pspell_path_clicked_cb(GtkWidget *widget, if (prefs_common.pspell_path) g_free(prefs_common.pspell_path); - prefs_common.pspell_path = g_strdup_printf("%s%s",tmp,G_DIR_SEPARATOR_S); + prefs_common.pspell_path = g_strdup_printf("%s%s",tmp, + G_DIR_SEPARATOR_S); new_menu = gtkpspell_dictionary_option_menu_new(prefs_common.pspell_path); gtk_option_menu_set_menu(GTK_OPTION_MENU(spelling.optmenu_dictionary), new_menu); - gtk_entry_set_text(GTK_ENTRY(spelling.entry_pspell_path), prefs_common.pspell_path); + gtk_entry_set_text(GTK_ENTRY(spelling.entry_pspell_path), + prefs_common.pspell_path); /* select first one */ - gtk_option_menu_set_history(GTK_OPTION_MENU(spelling.optmenu_dictionary), 0); + gtk_option_menu_set_history(GTK_OPTION_MENU( + spelling.optmenu_dictionary), 0); if (prefs_common.dictionary) g_free(prefs_common.dictionary); - prefs_common.dictionary = gtkpspell_get_dictionary_menu_active_item( - gtk_option_menu_get_menu(GTK_OPTION_MENU(spelling.optmenu_dictionary))); + prefs_common.dictionary = + gtkpspell_get_dictionary_menu_active_item( + gtk_option_menu_get_menu( + GTK_OPTION_MENU( + spelling.optmenu_dictionary))); g_free(tmp); - } } @@ -1409,10 +1420,13 @@ static void prefs_spelling_create() GtkWidget *optmenu_dictionary; GtkWidget *sugmode_label; GtkWidget *sugmode_optmenu; + GtkWidget *checkbtn_use_alternate; + GtkWidget *help_label; GtkWidget *checkbtn_check_while_typing; GtkWidget *color_label; GtkWidget *hbox_col; GtkWidget *col_align; + GtkWidget *hline; vbox1 = gtk_vbox_new (FALSE, VSPACING); @@ -1438,32 +1452,35 @@ static void prefs_spelling_create() PACK_CHECK_BUTTON(vbox_spell, checkbtn_check_while_typing, _("Check while typing")); - gtk_signal_connect(GTK_OBJECT(checkbtn_enable_pspell), "toggled", - GTK_SIGNAL_FUNC(prefs_spelling_checkbtn_enable_pspell_toggle_cb), - NULL); + PACK_CHECK_BUTTON(vbox_spell, checkbtn_use_alternate, + _("Enable alternate dictionary")); + help_label = gtk_label_new(_("Enabling alternate dictionary makes switching\nwith the last used dictionary faster.")); + gtk_widget_show(help_label); + gtk_box_pack_start(GTK_BOX(vbox_spell), help_label, FALSE, TRUE, 0); + spell_table = gtk_table_new(4, 3, FALSE); - gtk_container_set_border_width (GTK_CONTAINER (spell_table), 0); + gtk_container_set_border_width (GTK_CONTAINER (spell_table), VSPACING); gtk_table_set_row_spacings(GTK_TABLE(spell_table), 8); gtk_table_set_col_spacings(GTK_TABLE(spell_table), 8); gtk_box_pack_start(GTK_BOX(vbox_spell), spell_table, TRUE, TRUE, 0); - label_pspell_path = gtk_label_new (_("Dictionaries path:")); gtk_misc_set_alignment(GTK_MISC(label_pspell_path), 1.0, 0.5); gtk_widget_show(label_pspell_path); - gtk_table_attach (GTK_TABLE (spell_table), label_pspell_path, 0, 1, 0, 1, - GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); + gtk_table_attach (GTK_TABLE (spell_table), label_pspell_path, 0, 1, 0, + 1, GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); hbox_pspell_path = gtk_hbox_new (FALSE, 8); - gtk_table_attach (GTK_TABLE (spell_table), hbox_pspell_path, 1, 2, 0, 1, - GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); + gtk_table_attach (GTK_TABLE (spell_table), hbox_pspell_path, 1, 2, 0, + 1, GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); gtk_widget_show(hbox_pspell_path); entry_pspell_path = gtk_entry_new(); gtk_widget_show(entry_pspell_path); - gtk_box_pack_start(GTK_BOX(hbox_pspell_path), entry_pspell_path, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox_pspell_path), entry_pspell_path, TRUE, + TRUE, 0); gtk_widget_set_sensitive(entry_pspell_path, prefs_common.enable_pspell); @@ -1485,9 +1502,10 @@ static void prefs_spelling_create() optmenu_dictionary = gtk_option_menu_new(); gtk_widget_show(optmenu_dictionary); gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_dictionary), - gtkpspell_dictionary_option_menu_new(prefs_common.pspell_path)); - gtk_table_attach (GTK_TABLE (spell_table), optmenu_dictionary, 1, 2, 1, 2, - GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); + gtkpspell_dictionary_option_menu_new( + prefs_common.pspell_path)); + gtk_table_attach (GTK_TABLE (spell_table), optmenu_dictionary, 1, 2, 1, + 2, GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); gtk_widget_set_sensitive(optmenu_dictionary, prefs_common.enable_pspell); /* Suggestion mode */ @@ -1532,6 +1550,7 @@ static void prefs_spelling_create() spelling.btn_pspell_path = btn_pspell_path; spelling.optmenu_dictionary = optmenu_dictionary; spelling.optmenu_sugmode = sugmode_optmenu; + spelling.checkbtn_use_alternate = checkbtn_use_alternate; spelling.checkbtn_check_while_typing = checkbtn_check_while_typing; } diff --git a/src/prefs_common.h b/src/prefs_common.h index 05434576f..d7af40a12 100644 --- a/src/prefs_common.h +++ b/src/prefs_common.h @@ -97,6 +97,7 @@ struct _PrefsCommon gint misspelled_col; gint pspell_sugmode; gboolean check_while_typing; + gboolean use_alternate; #endif /* Display */