Re: GtkSpell problems

On Mon, Jun 02, 2003 at 03:58:01PM -0700, Evan Martin wrote:
On Mon, 2003-06-02 at 15:13, René Seindal wrote:
It indicates all numbers as misspelled.  I have no idea about how to
change that.  It is a major nuisance.

When right-clicking on a word, I have the option of adding the word to
the dictionary, but the addition is not persistent.  The next time I
open the document, the words are indicated as misspelled again.  How do
I get it to save these additions to a user specific dictionary.

I've been distracted with other projects for a while (it looks like I
made the last release almost exactly a half year ago), so there are a
number of GtkSpell bugs piling up that I ought to get to.  I'll add
these to the list.

If anyone is interested in a project to hack, feel free to email me or
the gtkspell-devel list (see  :)


Could you all please have a look at this patch for gtkspell.c
Here's what it is supposed to do:

1) Don't check words starting with digits.  Pango might think they are
words, but I know they aren't :-) 

2) The context menu entry 'Add "WORD" to Dictionary' now adds the word
to the user's persistent personal dictionary.  There appears to be two
files in $HOME for this: .aspell.LANG.pwd and .aspell.LANG.prepl

3) The context menu now has an 'Ignore "WORD" for this session' which
adds the word to the non persistent personal dictionary.  This is just
the same as the old behaviour.

I use a property on the menuitems to distinguish the two cases, so I
don't need two separate callbacks.

I use the GTK_STOCK_ADD icon for the 'add to dictionary' and the
GTK_STOCK_REMOVE icon for the 'ignore for this session'.  I think they
illustrate the two functions fairly well.

Words are added to the persistent dictionary immediately.  It would be
more efficient to just add the words later, but the only possible place
would be in the detach() function, but who says it is going to be

Anyway, what do you think?

René Seindal (rene seindal dk)

*** gtkspell.c~ Thu Dec 12 06:07:13 2002
--- gtkspell.c  Wed Jun  4 00:56:30 2003
*** 51,56 ****
--- 51,57 ----
  static void gtkspell_free(GtkSpell *spell);
  #define GTKSPELL_OBJECT_KEY "gtkspell"
+ #define GTKSPELL_SAVE_OBJECT_KEY "gtkspell_save"
  gtkspell_error_quark(void) {
*** 114,119 ****
--- 115,123 ----
             GtkTextIter *start, GtkTextIter *end) {
        char *text;
        text = gtk_text_buffer_get_text(buffer, start, end, FALSE);
+       if (g_unichar_isdigit(*text)) /* don't check numbers */
+               return;
        if (debug) g_print("checking: %s\n", text);
        if (aspell_speller_check(spell->speller, text, -1) == FALSE)
                gtk_text_buffer_apply_tag(buffer, spell->tag_highlight, start, end);
*** 237,245 ****
        get_cur_word_extents(buffer, &start, &end);
        word = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
-       aspell_speller_add_to_session(spell->speller, word, strlen(word));
        gtk_text_buffer_remove_tag(buffer, spell->tag_highlight, &start, &end);
--- 241,253 ----
        get_cur_word_extents(buffer, &start, &end);
        word = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+       if (g_object_get_data(G_OBJECT(menuitem), GTKSPELL_SAVE_OBJECT_KEY)) {
+               aspell_speller_add_to_personal(spell->speller, word, strlen(word));
+               aspell_speller_save_all_word_lists(spell->speller);
+       } else {
+               aspell_speller_add_to_session(spell->speller, word, strlen(word));
+       }
        gtk_text_buffer_remove_tag(buffer, spell->tag_highlight, &start, &end);
*** 293,298 ****
--- 301,307 ----
        label = g_strdup_printf("Add \"%s\" to Dictionary", word);
        mi = gtk_image_menu_item_new_with_label(label);
+       g_object_set_data(G_OBJECT(mi), GTKSPELL_SAVE_OBJECT_KEY, GINT_TO_POINTER(1));
                        gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
        g_signal_connect(G_OBJECT(mi), "activate",
*** 300,305 ****
--- 309,325 ----
        gtk_menu_shell_append(GTK_MENU_SHELL(topmenu), mi);
+       /* + Ignore All */
+       label = g_strdup_printf("Ignore \"%s\" for this session", word);
+       mi = gtk_image_menu_item_new_with_label(label);
+       g_free(label);
+       gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), 
+                       gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
+       g_signal_connect(G_OBJECT(mi), "activate",
+                       G_CALLBACK(add_to_dictionary), spell);
+       gtk_widget_show_all(mi);
+       gtk_menu_shell_append(GTK_MENU_SHELL(topmenu), mi);
        /* Separator */
        mi = gtk_menu_item_new();

René Seindal (rene seindal dk)        

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]