[latexila/wip/gspell: 3/3] spell: use GspellLanguageDialog



commit d3507005ae80be8694688895be31c466e4465654
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Sep 15 11:51:05 2015 +0200

    spell: use GspellLanguageDialog

 src/document_view.vala     |   53 +++++++++++++++++++++++++------------------
 src/main_window_tools.vala |   15 ++++++++++--
 src/ui/ui.xml              |    1 +
 3 files changed, 44 insertions(+), 25 deletions(-)
---
diff --git a/src/document_view.vala b/src/document_view.vala
index 99f6ee0..3cd83b6 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -80,8 +80,10 @@ public class DocumentView : Gtk.SourceView
         }
 
         // spell checking
+        _spell_checker = new Gspell.Checker (null);
+
         if (_editor_settings.get_boolean ("spell-checking"))
-            activate_spell_checking ();
+            activate_inline_spell_checker ();
 
         // forward search
         button_release_event.connect (on_button_release_event);
@@ -172,16 +174,37 @@ public class DocumentView : Gtk.SourceView
         return "\t";
     }
 
-    public void activate_spell_checking ()
+    public void set_spell_language ()
     {
-        if (_spell_checker == null)
-        {
-            _spell_checker = new Gspell.Checker (null);
-        }
+        return_if_fail (_spell_checker != null);
+
+        Gspell.LanguageDialog dialog =
+            new Gspell.LanguageDialog (this.get_toplevel () as Window,
+                _spell_checker.get_language ());
+
+        int response = dialog.run ();
+
+        if (response == ResponseType.OK)
+            _spell_checker.set_language (dialog.get_selected_language ());
+
+        dialog.destroy ();
+    }
+
+    public void activate_inline_spell_checker ()
+    {
+        return_if_fail (_spell_checker != null);
 
         if (_spell_checker.get_language () != null)
         {
-            attach_spell_checker ();
+            if (_inline_spell_checker == null)
+            {
+                _inline_spell_checker =
+                    new Gspell.InlineCheckerGtv (this.buffer as Gtk.SourceBuffer,
+                        _spell_checker);
+
+                _inline_spell_checker.attach_view (this);
+            }
+
             return;
         }
 
@@ -215,21 +238,7 @@ public class DocumentView : Gtk.SourceView
         _editor_settings.set_boolean ("spell-checking", false);
     }
 
-    private void attach_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 ()
+    public void deactivate_inline_spell_checker ()
     {
         if (_inline_spell_checker != null)
         {
diff --git a/src/main_window_tools.vala b/src/main_window_tools.vala
index 0edd4da..198b848 100644
--- a/src/main_window_tools.vala
+++ b/src/main_window_tools.vala
@@ -25,7 +25,9 @@ public class MainWindowTools
 {
     private const Gtk.ActionEntry[] _action_entries =
     {
-        { "Tools", null, N_("_Tools") }
+        { "Tools", null, N_("_Tools") },
+        { "ToolsSetSpellLanguage", null, N_("_Set Language…"), null,
+            N_("Set the language used for the spell checking"), on_set_language }
     };
 
     private const ToggleActionEntry[] _toggle_action_entries =
@@ -62,6 +64,13 @@ public class MainWindowTools
 
     /* Gtk.Action callbacks */
 
+    public void on_set_language (Gtk.Action action)
+    {
+        return_if_fail (_main_window.active_view != null);
+
+        _main_window.active_view.set_spell_language ();
+    }
+
     public void on_inline_spell_checker (Gtk.Action action)
     {
         bool activate = (action as ToggleAction).active;
@@ -69,9 +78,9 @@ public class MainWindowTools
         foreach (DocumentView view in _main_window.get_views ())
         {
             if (activate)
-                view.activate_spell_checking ();
+                view.activate_inline_spell_checker ();
             else
-                view.disable_spell_checking ();
+                view.deactivate_inline_spell_checker ();
         }
     }
 }
diff --git a/src/ui/ui.xml b/src/ui/ui.xml
index 61e0538..289b908 100644
--- a/src/ui/ui.xml
+++ b/src/ui/ui.xml
@@ -371,6 +371,7 @@ along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
     </menu>
 
     <menu action="Tools">
+      <menuitem action="ToolsSetSpellLanguage" />
       <menuitem action="ToolsInlineSpellChecker" />
     </menu>
 


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