[latexila/wip/gspell: 2/3] Migrate from GtkSpell to gspell



commit 9d9140d6de3979e00b15ca1404693ec2df314fa1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Sep 14 18:08:26 2015 +0200

    Migrate from GtkSpell to gspell
    
    gspell has more features and has a better inline checker for
    GtkTextView.
    
    As a first step, use only GspellInlineCheckerGtv. It's not possible to
    change the language, this will come with a later commit by using
    GspellLanguageDialog.

 README.in              |    2 +-
 configure.ac           |   10 +++---
 src/Makefile.am        |    2 +-
 src/document_view.vala |   90 ++++++++++++++++++++----------------------------
 4 files changed, 44 insertions(+), 60 deletions(-)
---
diff --git a/README.in b/README.in
index fb1f2ea..9ccb791 100644
--- a/README.in
+++ b/README.in
@@ -18,7 +18,7 @@ Requirements
 GLib >= @GLIB_REQUIRED_VERSION@
 GTK+ >= @GTK_REQUIRED_VERSION@
 GtkSourceView >= @GTKSOURCEVIEW_REQUIRED_VERSION@
-GtkSpell >= @GTKSPELL_REQUIRED_VERSION@
+gspell >= @GSPELL_REQUIRED_VERSION@
 gee-0.8 >= @GEE_REQUIRED_VERSION@
 gettext
 gsettings-desktop-schemas
diff --git a/configure.ac b/configure.ac
index ecd5e2d..8313e01 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,14 +28,14 @@ LT_INIT
 GLIB_REQUIRED_VERSION="2.40"
 GTK_REQUIRED_VERSION="3.14"
 GTKSOURCEVIEW_REQUIRED_VERSION="3.17.5"
-GTKSPELL_REQUIRED_VERSION="3.0.4"
+GSPELL_REQUIRED_VERSION="0.0.1"
 VALA_REQUIRED_VERSION="0.26"
 GEE_REQUIRED_VERSION="0.10"
 
 AC_SUBST([GLIB_REQUIRED_VERSION])
 AC_SUBST([GTK_REQUIRED_VERSION])
 AC_SUBST([GTKSOURCEVIEW_REQUIRED_VERSION])
-AC_SUBST([GTKSPELL_REQUIRED_VERSION])
+AC_SUBST([GSPELL_REQUIRED_VERSION])
 AC_SUBST([VALA_REQUIRED_VERSION])
 AC_SUBST([GEE_REQUIRED_VERSION])
 
@@ -98,8 +98,8 @@ if ! pkg-config --atleast-version=${GTKSOURCEVIEW_REQUIRED_VERSION} gtksourcevie
        AC_MSG_ERROR([gtksourceview-3.0 >= ${GTKSOURCEVIEW_REQUIRED_VERSION} required.])
 fi
 
-if ! pkg-config --atleast-version=${GTKSPELL_REQUIRED_VERSION} gtkspell3-3.0; then
-       AC_MSG_ERROR([gtkspell3-3.0 >= ${GTKSPELL_REQUIRED_VERSION} required.])
+if ! pkg-config --atleast-version=${GSPELL_REQUIRED_VERSION} gspell-3.0; then
+       AC_MSG_ERROR([gspell-3.0 >= ${GSPELL_REQUIRED_VERSION} required.])
 fi
 
 if ! pkg-config gsettings-desktop-schemas; then
@@ -115,7 +115,7 @@ dependencies="
        gio-2.0
        gtk+-3.0
        gtksourceview-3.0
-       gtkspell3-3.0
+       gspell-3.0
        gsettings-desktop-schemas
        gee-0.8"
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 3f23d70..c77224a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,7 @@ bin_PROGRAMS = latexila
 VALAFLAGS =                    \
        --pkg gtk+-3.0          \
        --pkg gtksourceview-3.0 \
-       --pkg gtkspell3-3.0     \
+       --pkg gspell-3.0        \
        --pkg gee-0.8           \
        --pkg posix             \
        --target-glib=2.40      \
diff --git a/src/document_view.vala b/src/document_view.vala
index d198f59..99f6ee0 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -25,7 +25,8 @@ public class DocumentView : Gtk.SourceView
 
     private GLib.Settings _editor_settings;
     private Pango.FontDescription _font_desc;
-    private GtkSpell.Checker? _spell_checker = null;
+    private Gspell.Checker? _spell_checker = null;
+    private Gspell.InlineCheckerGtv? _inline_spell_checker = null;
 
     public DocumentView (Document doc)
     {
@@ -175,8 +176,7 @@ public class DocumentView : Gtk.SourceView
     {
         if (_spell_checker == null)
         {
-            _spell_checker = new GtkSpell.Checker ();
-            _spell_checker.decode_language_codes = true;
+            _spell_checker = new Gspell.Checker (null);
         }
 
         if (_spell_checker.get_language () != null)
@@ -185,73 +185,57 @@ public class DocumentView : Gtk.SourceView
             return;
         }
 
-        try
-        {
-            // Will try the best language depending on the LANG environment variable.
-            _spell_checker.set_language (null);
-            attach_spell_checker ();
-        }
-        catch (Error e)
-        {
-            GLib.List<string> language_list = GtkSpell.Checker.get_language_list ();
+        MessageDialog dialog = new MessageDialog (this.get_toplevel () as Window,
+            DialogFlags.DESTROY_WITH_PARENT,
+            MessageType.ERROR,
+            ButtonsType.NONE,
+            "%s", _("No dictionaries available for the spell checking."));
 
-            if (language_list == null || language_list.data == null)
-            {
-                MessageDialog dialog = new MessageDialog (this.get_toplevel () as Window,
-                    DialogFlags.DESTROY_WITH_PARENT,
-                    MessageType.ERROR,
-                    ButtonsType.NONE,
-                    "%s", _("No dictionaries available for the spell checking."));
-
-                dialog.add_buttons (_("_Help"), ResponseType.HELP,
-                    _("_OK"), ResponseType.OK,
-                    null);
-
-                int response = dialog.run ();
-
-                if (response == ResponseType.HELP)
-                {
-                    try
-                    {
-                        show_uri (this.get_screen (), "help:latexila/spell_checking",
-                            Gdk.CURRENT_TIME);
-                    }
-                    catch (Error e)
-                    {
-                        warning ("Impossible to open the documentation: %s", e.message);
-                    }
-                }
-
-                dialog.destroy ();
-
-                _editor_settings.set_boolean ("spell-checking", false);
-                return;
-            }
+        dialog.add_buttons (_("_Help"), ResponseType.HELP,
+            _("_OK"), ResponseType.OK,
+            null);
 
+        int response = dialog.run ();
+
+        if (response == ResponseType.HELP)
+        {
             try
             {
-                _spell_checker.set_language (language_list.data);
-                attach_spell_checker ();
+                show_uri (this.get_screen (), "help:latexila/spell_checking",
+                    Gdk.CURRENT_TIME);
             }
             catch (Error e)
             {
-                // Should not happen.
-                warning ("GtkSpell error: %s", e.message);
-                _editor_settings.set_boolean ("spell-checking", false);
+                warning ("Impossible to open the documentation: %s", e.message);
             }
         }
+
+        dialog.destroy ();
+
+        _editor_settings.set_boolean ("spell-checking", false);
     }
 
     private void attach_spell_checker ()
     {
-        if (! _spell_checker.attach (this))
-            warning ("Impossible to attach the spell checker.");
+        return_if_fail (_spell_checker != null);
+
+        if (_inline_spell_checker == null)
+        {
+            _inline_spell_checker =
+                new Gspell.InlineCheckerGtv (this.buffer as Gtk.SourceBuffer,
+                    _spell_checker);
+        }
+
+        _inline_spell_checker.attach_view (this);
     }
 
     public void disable_spell_checking ()
     {
-        if (_spell_checker != null)
-            _spell_checker.detach ();
+        if (_inline_spell_checker != null)
+        {
+            _inline_spell_checker.detach_view (this);
+            _inline_spell_checker = null;
+        }
     }
 
     private bool on_button_release_event (Gdk.EventButton event)


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