[latexila/wip/gspell] spell: menu entry affects only current tab



commit 1a56057c88b6589a2c638892b9445f94148e97c7
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Sep 15 13:37:13 2015 +0200

    spell: menu entry affects only current tab
    
    The "highlight misspelled words" menu entry now affects only the current
    tab. If we use the inline checker to spell check several files, it is
    useful to know where the spell checking is finished, i.e. where the
    inline checker is disabled. It's just one example, there are probably
    many other examples where the inline checker should be activated on a
    file-by-file basis.
    
    A later commit will store the spell checking settings to the file
    metadata.

 src/document_view.vala     |   25 +++++++++++++++++++++----
 src/main_window_tools.vala |   34 ++++++++++++++++++++--------------
 2 files changed, 41 insertions(+), 18 deletions(-)
---
diff --git a/src/document_view.vala b/src/document_view.vala
index e8eb0f0..63b6fe9 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -28,6 +28,22 @@ public class DocumentView : Gtk.SourceView
     private Gspell.Checker? _spell_checker = null;
     private Gspell.InlineCheckerGtv? _inline_spell_checker = null;
 
+    public bool highlight_misspelled_words
+    {
+        get
+        {
+            return _inline_spell_checker != null;
+        }
+
+        set
+        {
+            if (value)
+                this.activate_inline_spell_checker ();
+            else
+                this.deactivate_inline_spell_checker ();
+        }
+    }
+
     public DocumentView (Document doc)
     {
         this.buffer = doc;
@@ -204,7 +220,7 @@ public class DocumentView : Gtk.SourceView
         dialog.destroy ();
     }
 
-    public void activate_inline_spell_checker ()
+    private void activate_inline_spell_checker ()
     {
         return_if_fail (_spell_checker != null);
 
@@ -217,6 +233,8 @@ public class DocumentView : Gtk.SourceView
                         _spell_checker);
 
                 _inline_spell_checker.attach_view (this);
+
+                notify_property ("highlight-misspelled-words");
             }
 
             return;
@@ -248,16 +266,15 @@ public class DocumentView : Gtk.SourceView
         }
 
         dialog.destroy ();
-
-        _editor_settings.set_boolean ("highlight-misspelled-words", false);
     }
 
-    public void deactivate_inline_spell_checker ()
+    private void deactivate_inline_spell_checker ()
     {
         if (_inline_spell_checker != null)
         {
             _inline_spell_checker.detach_view (this);
             _inline_spell_checker = null;
+            notify_property ("highlight-misspelled-words");
         }
     }
 
diff --git a/src/main_window_tools.vala b/src/main_window_tools.vala
index f74db72..07ba90d 100644
--- a/src/main_window_tools.vala
+++ b/src/main_window_tools.vala
@@ -52,16 +52,23 @@ public class MainWindowTools
 
         ui_manager.insert_action_group (_action_group, 0);
 
-        /* Bind spell checking setting */
+        update_inline_spell_checker_action_state ();
+        _main_window.notify["active-tab"].connect (() =>
+        {
+            update_inline_spell_checker_action_state ();
+        });
+    }
+
+    private void update_inline_spell_checker_action_state ()
+    {
+        if (_main_window.active_tab == null)
+            return;
 
         ToggleAction spell_checking_action =
             _action_group.get_action ("ToolsInlineSpellChecker") as ToggleAction;
 
-        GLib.Settings editor_settings =
-            new GLib.Settings ("org.gnome.latexila.preferences.editor");
-
-        editor_settings.bind ("highlight-misspelled-words", spell_checking_action,
-            "active", SettingsBindFlags.DEFAULT);
+        spell_checking_action.active =
+            _main_window.active_view.highlight_misspelled_words;
     }
 
     /* Sensitivity */
@@ -73,7 +80,8 @@ public class MainWindowTools
         string[] action_names =
         {
             "ToolsSpellCheckerDialog",
-            "ToolsSetSpellLanguage"
+            "ToolsSetSpellLanguage",
+            "ToolsInlineSpellChecker"
         };
 
         foreach (string action_name in action_names)
@@ -101,14 +109,12 @@ public class MainWindowTools
 
     public void on_inline_spell_checker (Gtk.Action action)
     {
+        return_if_fail (_main_window.active_view != null);
+
         bool activate = (action as ToggleAction).active;
 
-        foreach (DocumentView view in _main_window.get_views ())
-        {
-            if (activate)
-                view.activate_inline_spell_checker ();
-            else
-                view.deactivate_inline_spell_checker ();
-        }
+        _main_window.active_view.highlight_misspelled_words = activate;
+
+        update_inline_spell_checker_action_state ();
     }
 }


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