[gnome-subtitles] Fix 164 - Autocheck Spelling not working when the app is opened



commit f7bbda75a4ebc694ea7a840bb7b4b157dc4d61aa
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Fri Jan 29 20:57:13 2021 +0000

    Fix 164 - Autocheck Spelling not working when the app is opened

 src/GnomeSubtitles/Core/SpellLanguages.cs          | 12 ++++----
 src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs     | 12 +++++---
 src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs | 36 ++++++++++------------
 .../Ui/Edit/SubtitleEditTranslation.cs             |  8 +++--
 4 files changed, 35 insertions(+), 33 deletions(-)
---
diff --git a/src/GnomeSubtitles/Core/SpellLanguages.cs b/src/GnomeSubtitles/Core/SpellLanguages.cs
index b7b2607..2f39b58 100644
--- a/src/GnomeSubtitles/Core/SpellLanguages.cs
+++ b/src/GnomeSubtitles/Core/SpellLanguages.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2008-2020 Pedro Castro
+ * Copyright (C) 2008-2021 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@ public class SpellLanguages {
        }
 
        /* Events */
-       public event BasicEventHandler ToggleEnabled = null;
+       public event BasicEventHandler EnabledToggled = null;
        public event BasicEventHandler TextLanguageChanged = null;
        public event BasicEventHandler TranslationLanguageChanged = null;
 
@@ -84,7 +84,7 @@ public class SpellLanguages {
                        if (value != enabled) {
                                enabled = value;
                                Base.Config.SpellCheckAuto = value;
-                               EmitToggleEnabled();
+                               EmitEnabledToggled();
                        }
                }
                get { return enabled; }
@@ -213,9 +213,9 @@ public class SpellLanguages {
 
        /* Event members */
 
-       private void EmitToggleEnabled () {
-       if (this.ToggleEnabled != null)
-               this.ToggleEnabled();
+       private void EmitEnabledToggled () {
+       if (this.EnabledToggled != null)
+               this.EnabledToggled();
     }
 
     private void EmitLanguageChanged (SubtitleTextType textType) {
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs
index d1c69bb..1e3a413 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2011 Pedro Castro
+ * Copyright (C) 2007-2021 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -71,15 +71,19 @@ public class SubtitleEditText : SubtitleEditTextView {
        private void OnBaseDocumentLoaded (Document document) {
                Base.Ui.View.Selection.Changed += OnSubtitleSelectionChanged;
 
-               Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
+               Base.SpellLanguages.EnabledToggled += OnSpellEnabledToggled;
                Base.SpellLanguages.TextLanguageChanged += OnSpellLanguageChanged;
+               
+               SetSpellLanguage();
        }
 
        private void OnBaseDocumentUnloaded (Document document) {
                Base.Ui.View.Selection.Changed -= OnSubtitleSelectionChanged;
 
-               Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
-               Base.SpellLanguages.TextLanguageChanged += OnSpellLanguageChanged;
+               Base.SpellLanguages.EnabledToggled -= OnSpellEnabledToggled;
+               Base.SpellLanguages.TextLanguageChanged -= OnSpellLanguageChanged;
+               
+               SetSpellLanguage();
        }
 }
 
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs 
b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs
index 7529936..1b4d0f4 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2018 Pedro Castro
+ * Copyright (C) 2006-2021 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -176,16 +176,7 @@ public abstract class SubtitleEditTextView {
                }
        }
 
-       private void SetSpellLanguage (SpellLanguage language) {
-               if (language == null) {
-                       spellChecker.Disable();
-                       return;
-               }
-
-               spellChecker.Enable(language.ID);
-       }
-
-
+               
        /* Private methods */
 
     private void SetText (string text) {
@@ -382,20 +373,25 @@ public abstract class SubtitleEditTextView {
     }
 
     /* Protected members */
-
-    protected void OnSpellLanguageChanged () {
+    
+    protected void SetSpellLanguage () {
                if (Base.SpellLanguages.Enabled) {
                        SpellLanguage language = GetSpellActiveLanguage();
-                       SetSpellLanguage(language);
+                       if (language != null) {
+                               spellChecker.Enable(language.ID);
+                               return;
+                       }
                }
+               
+               spellChecker.Disable();
        }
 
-       protected void OnSpellToggleEnabled () {
-               if (Base.SpellLanguages.Enabled) {
-                       SetSpellLanguage(GetSpellActiveLanguage());
-               } else {
-                       SetSpellLanguage(null);
-               }
+    protected void OnSpellLanguageChanged () {
+       SetSpellLanguage();
+       }
+
+       protected void OnSpellEnabledToggled () {
+               SetSpellLanguage();
        }
 
        protected void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) {
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs 
b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs
index e3848ce..6a06872 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2011 Pedro Castro
+ * Copyright (C) 2007-2021 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -67,8 +67,9 @@ public class SubtitleEditTranslation : SubtitleEditTextView {
        private void OnBaseTranslationLoaded () {
                Base.Ui.View.Selection.Changed += OnSubtitleSelectionChanged;
 
-       Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
+       Base.SpellLanguages.EnabledToggled += OnSpellEnabledToggled;
                Base.SpellLanguages.TranslationLanguageChanged += OnSpellLanguageChanged;
+               SetSpellLanguage();
 
                SetVisibility(true);
        }
@@ -76,8 +77,9 @@ public class SubtitleEditTranslation : SubtitleEditTextView {
        private void OnBaseTranslationUnloaded () {
                Base.Ui.View.Selection.Changed -= OnSubtitleSelectionChanged;
 
-               Base.SpellLanguages.ToggleEnabled -= OnSpellToggleEnabled;
+               Base.SpellLanguages.EnabledToggled -= OnSpellEnabledToggled;
                Base.SpellLanguages.TranslationLanguageChanged -= OnSpellLanguageChanged;
+               SetSpellLanguage();
 
        SetVisibility(false);
        }


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