[meld: 2/4] Change global _cache variable to class variable




commit 2c62e8741c6778c1581dd9909b191400a6500edd
Author: Jack <jack vanier16 outlook com>
Date:   Sat Jan 16 14:57:01 2021 -0500

    Change global _cache variable to class variable

 meld/ui/findbar.py | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
---
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index 966bf3c7..ab47bb50 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -15,8 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from gi.repository import GObject, Gtk, GtkSource
-
-_cache = None  # Global variable to hold the most recent searched for text
+from typing import ClassVar, Optional
 
 
 @Gtk.Template(resource_path='/org/gnome/meld/ui/findbar.ui')
@@ -36,6 +35,7 @@ class FindBar(Gtk.Grid):
     wrap_box = Gtk.Template.Child()
 
     replace_mode = GObject.Property(type=bool, default=False)
+    _cached_search: ClassVar[Optional[str]] = None
 
     @GObject.Signal(
         name='activate-secondary',
@@ -103,14 +103,13 @@ class FindBar(Gtk.Grid):
             self.search_context = None
 
     def start_find(self, *, textview: Gtk.TextView, replace: bool, text: str):
-        global _cache
         self.replace_mode = replace
         self.set_text_view(textview)
         if text:
             self.find_entry.set_text(text)
-            _cache = text
-        elif _cache:
-            self.find_entry.set_text(_cache)
+            FindBar._cached_search = text
+        elif FindBar._cached_search:
+            self.find_entry.set_text(FindBar._cached_search)
         self.show()
         self.find_entry.grab_focus()
 
@@ -160,8 +159,7 @@ class FindBar(Gtk.Grid):
 
     @Gtk.Template.Callback()
     def on_find_entry_changed(self, entry):
-        global _cache
-        _cache = entry.get_text()
+        FindBar._cached_search = entry.get_text()
         self._find_text(0)
 
     @Gtk.Template.Callback()


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