2012-08-29 [colin] 3.8.1cvs42
authorColin Leroy <colin@colino.net>
Wed, 29 Aug 2012 15:25:43 +0000 (15:25 +0000)
committerColin Leroy <colin@colino.net>
Wed, 29 Aug 2012 15:25:43 +0000 (15:25 +0000)
* src/gtk/gtkaspell.c
Fix bug #2596, "Spell checker does not work properly"

ChangeLog
PATCHSETS
configure.ac
src/gtk/gtkaspell.c

index 0e8300d..86a0794 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-08-29 [colin]     3.8.1cvs42
+
+       * src/gtk/gtkaspell.c
+               Fix bug #2596, "Spell checker does not work properly"
+
 2012-08-29 [colin]     3.8.1cvs41
 
        * src/plugins/pgpcore/sgpgme.c
index 2968480..09e8254 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.115.2.252 -r 1.115.2.253 src/main.c;  ) > 3.8.1cvs39.patchset
 ( cvs diff -u -r 1.274.2.348 -r 1.274.2.349 src/mainwindow.c;  cvs diff -u -r 1.94.2.237 -r 1.94.2.238 src/messageview.c;  cvs diff -u -r 1.83.2.192 -r 1.83.2.193 src/mimeview.c;  cvs diff -u -r 1.20.2.37 -r 1.20.2.38 src/mimeview.h;  cvs diff -u -r 1.395.2.450 -r 1.395.2.451 src/summaryview.c;  cvs diff -u -r 1.96.2.244 -r 1.96.2.245 src/textview.c;  cvs diff -u -r 1.5.2.46 -r 1.5.2.47 src/gtk/menu.c;  cvs diff -u -r 1.4.2.26 -r 1.4.2.27 src/gtk/menu.h;  ) > 3.8.1cvs40.patchset
 ( cvs diff -u -r 1.1.2.72 -r 1.1.2.73 src/plugins/pgpcore/sgpgme.c;  ) > 3.8.1cvs41.patchset
+( cvs diff -u -r 1.9.2.79 -r 1.9.2.80 src/gtk/gtkaspell.c;  ) > 3.8.1cvs42.patchset
index 9b8b4cf..9e196e7 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=8
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=41
+EXTRA_VERSION=42
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index f57be61..0ac6efb 100644 (file)
@@ -89,6 +89,9 @@ static GtkAspellCheckers *gtkaspellcheckers;
 static void gtkaspell_checkers_error_message   (gchar  *message);
 
 /* Callbacks */
+static gboolean key_press_cb                   (GtkWidget    *text_view,
+                                                GdkEventKey  *event,
+                                                 GtkAspell      *gtkaspell);
 static void entry_insert_cb                    (GtkTextBuffer  *textbuf,
                                                 GtkTextIter    *iter,
                                                 gchar          *newtext, 
@@ -423,6 +426,8 @@ GtkAspell *gtkaspell_new(const gchar *dictionary,
 
        allocate_color(gtkaspell, misspelled_color);
 
+       g_signal_connect(G_OBJECT(gtktext), "key_press_event",
+                              G_CALLBACK(key_press_cb), gtkaspell);
        g_signal_connect_after(G_OBJECT(buffer), "insert-text",
                               G_CALLBACK(entry_insert_cb), gtkaspell);
        g_signal_connect_after(G_OBJECT(buffer), "delete-range",
@@ -442,6 +447,9 @@ void gtkaspell_delete(GtkAspell *gtkaspell)
 {
        GtkTextView *gtktext = gtkaspell->gtktext;
        
+        g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
+                                            G_CALLBACK(key_press_cb),
+                                            gtkaspell);
         g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
                                             G_CALLBACK(entry_insert_cb),
                                             gtkaspell);
@@ -478,6 +486,41 @@ void gtkaspell_dict_changed(GtkAspell *gtkaspell)
        gtkaspell->dict_changed_cb(gtkaspell->menu_changed_data);
 }
 
+static gboolean key_press_cb                   (GtkWidget    *text_view,
+                                                GdkEventKey  *event,
+                                                 GtkAspell    *gtkaspell)
+{
+       gint pos;
+       GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text_view);
+
+       cm_return_val_if_fail(gtkaspell->gtkaspeller->speller, FALSE);
+
+       if (!gtkaspell->check_while_typing)
+               return FALSE;
+
+       switch (event->keyval) {
+               case GDK_KEY_Home:
+               case GDK_KEY_Left:
+               case GDK_KEY_Up:
+               case GDK_KEY_Right:
+               case GDK_KEY_Down:
+               case GDK_KEY_Page_Up:
+               case GDK_KEY_Page_Down:
+               case GDK_KEY_End:
+               case GDK_KEY_Begin:
+                       pos = get_textview_buffer_offset(text_view);
+                       if (pos > 0)
+                               check_at(gtkaspell, pos - 1);
+                       else
+                               check_at(gtkaspell, pos);
+                       break;
+               default:
+                       break;
+       }
+
+       return FALSE;
+}
+
 static void entry_insert_cb(GtkTextBuffer *textbuf,
                            GtkTextIter *iter,
                            gchar *newtext,
@@ -1197,6 +1240,9 @@ void gtkaspell_block_check(GtkAspell *gtkaspell)
                return;
                
        gtktext = gtkaspell->gtktext;
+       g_signal_handlers_block_by_func(G_OBJECT(gtktext),
+                                        G_CALLBACK(key_press_cb),
+                                        gtkaspell);
        g_signal_handlers_block_by_func(G_OBJECT(gtktext),
                                         G_CALLBACK(entry_insert_cb),
                                         gtkaspell);
@@ -1213,6 +1259,9 @@ void gtkaspell_unblock_check(GtkAspell *gtkaspell)
                return;
                
        gtktext = gtkaspell->gtktext;
+       g_signal_handlers_unblock_by_func(G_OBJECT(gtktext),
+                                        G_CALLBACK(key_press_cb),
+                                        gtkaspell);
        g_signal_handlers_unblock_by_func(G_OBJECT(gtktext),
                                         G_CALLBACK(entry_insert_cb),
                                         gtkaspell);
@@ -1242,12 +1291,7 @@ static void replace_real_word(GtkAspell *gtkaspell, const gchar *newword)
 
        newlen = strlen(newword); /* FIXME: multybyte characters? */
 
-       g_signal_handlers_block_by_func(G_OBJECT(gtktext),
-                                        G_CALLBACK(entry_insert_cb),
-                                        gtkaspell);
-       g_signal_handlers_block_by_func(G_OBJECT(gtktext),
-                                        G_CALLBACK(entry_delete_cb),
-                                        gtkaspell);
+       gtkaspell_block_check(gtkaspell);
 
        gtk_text_buffer_get_iter_at_offset(textbuf, &startiter,
                                           gtkaspell->start_pos);
@@ -1258,12 +1302,7 @@ static void replace_real_word(GtkAspell *gtkaspell, const gchar *newword)
        g_signal_emit_by_name(G_OBJECT(textbuf), "insert-text",
                              &startiter, newword, newlen, gtkaspell);
 
-       g_signal_handlers_unblock_by_func(G_OBJECT(gtktext),
-                                          G_CALLBACK(entry_insert_cb),
-                                          gtkaspell);
-       g_signal_handlers_unblock_by_func(G_OBJECT(gtktext),
-                                          G_CALLBACK(entry_delete_cb),
-                                          gtkaspell);
+       gtkaspell_unblock_check(gtkaspell);
 
        /* Put the point and the position where we clicked with the mouse
         * It seems to be a hack, as I must thaw,freeze,thaw the widget