about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-02-06 20:12:30 +0100
committernfnty <git@nfnty.se>2017-02-06 20:25:32 +0100
commitabacb776a7aab93ccab66512975a465d4c28a5ee (patch)
tree7976476849d07e71532452cbb580692f80244a8a
parent2df8115223ebcd04403a17a067d543d5c097c701 (diff)
downloadranger-abacb776a7aab93ccab66512975a465d4c28a5ee.tar.gz
container.directory.Directory: Fix `setopt` signals when deleted
Fixes #366
-rw-r--r--ranger/container/directory.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 8c94ebe6..168a46c7 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -146,13 +146,17 @@ class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public
         Accumulator.__init__(self)
         FileSystemObject.__init__(self, path, **kw)
 
-        self.marked_items = list()
+        self.marked_items = []
 
+        self._signal_functions = []
+        func = self.signal_function_factory(self.sort)
+        self._signal_functions += [func]
         for opt in ('sort_directories_first', 'sort', 'sort_reverse', 'sort_case_insensitive'):
-            self.settings.signal_bind('setopt.' + opt, self.sort, weak=True, autosort=False)
-
+            self.settings.signal_bind('setopt.' + opt, func, weak=True, autosort=False)
+        func = self.signal_function_factory(self.refilter)
+        self._signal_functions += [func]
         for opt in ('hidden_filter', 'show_hidden'):
-            self.settings.signal_bind('setopt.' + opt, self.refilter, weak=True, autosort=False)
+            self.settings.signal_bind('setopt.' + opt, func, weak=True, autosort=False)
 
         self.settings = LocalSettings(path, self.settings)
 
@@ -161,6 +165,14 @@ class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public
 
         self.use()
 
+    def signal_function_factory(self, function):
+        def signal_function():
+            self.load_if_outdated()
+            if not self.exists:
+                return
+            function()
+        return signal_function
+
     def request_resort(self):
         self.order_outdated = True
 
@@ -656,7 +668,7 @@ class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public
 
     def empty(self):
         """Is the directory empty?"""
-        return self.files is None or len(self.files) == 0
+        return not self.files
 
     def set_linemode_of_children(self, mode):
         for fobj in self.files: