[latexila/wip/gspell] spell: use GspellLanguageDialog



commit 6f4dbbb5f4b4ae18ce819fe469d8231795f95366
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.vala       |    3 ++
 src/main_window_tools.vala |   33 ++++++++++++++++++++++++--
 src/ui/ui.xml              |    1 +
 4 files changed, 65 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.vala b/src/main_window.vala
index c4724dd..225991a 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -464,6 +464,7 @@ public class MainWindow : Window
         {
             _main_window_edit.update_sensitivity ();
             _main_window_build_tools.update_sensitivity ();
+            _main_window_tools.update_sensitivity ();
             update_config_project_sensitivity ();
             my_set_title ();
             update_cursor_position_statusbar ();
@@ -730,6 +731,7 @@ public class MainWindow : Window
         _documents_panel.add_tab (tab, -1, jump_to);
 
         _main_window_edit.update_sensitivity ();
+        _main_window_tools.update_sensitivity ();
 
         if (! this.get_visible ())
             this.present ();
@@ -1046,6 +1048,7 @@ public class MainWindow : Window
         _main_window_file.update_sensitivity (sensitive);
         _main_window_edit.update_sensitivity ();
         _main_window_build_tools.update_sensitivity ();
+        _main_window_tools.update_sensitivity ();
     }
 
     public void update_config_project_sensitivity ()
diff --git a/src/main_window_tools.vala b/src/main_window_tools.vala
index 0edd4da..04ffa59 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 =
@@ -60,8 +62,33 @@ public class MainWindowTools
             SettingsBindFlags.DEFAULT);
     }
 
+    /* Sensitivity */
+
+    public void update_sensitivity ()
+    {
+        bool sensitive = _main_window.active_tab != null;
+
+        string[] action_names =
+        {
+            "ToolsSetSpellLanguage"
+        };
+
+        foreach (string action_name in action_names)
+        {
+            Gtk.Action action = _action_group.get_action (action_name);
+            action.sensitive = sensitive;
+        }
+    }
+
     /* 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 +96,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]