summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/ext/signals.py20
-rw-r--r--ranger/fsobject/directory.py4
2 files changed, 20 insertions, 4 deletions
diff --git a/ranger/ext/signals.py b/ranger/ext/signals.py
index ecb48de3..0df39fe0 100644
--- a/ranger/ext/signals.py
+++ b/ranger/ext/signals.py
@@ -126,7 +126,7 @@ class SignalDispatcher(object):
 				handler._function = None
 		self._signals = dict()
 
-	def signal_bind(self, signal_name, function, priority=0.5, weak=False):
+	def signal_bind(self, signal_name, function, priority=0.5, weak=False, autosort=True):
 		"""
 		Bind a function to the signal.
 
@@ -162,9 +162,25 @@ class SignalDispatcher(object):
 
 		handler = SignalHandler(signal_name, function, priority, nargs > 0)
 		handlers.append(handler)
-		handlers.sort(key=lambda handler: -handler._priority)
+		if autosort:
+			handlers.sort(key=lambda handler: -handler._priority)
 		return handler
 
+	def signal_force_sort(self, signal_name=None):
+		"""
+		Forces a sorting of signal handlers by priority.
+
+		This is only necessary if you used signal_bind with autosort=False
+		after finishing to bind many signals at once.
+		"""
+		if signal_name is None:
+			for handlers in self._signals.values():
+				handlers.sort(key=lambda handler: -handler._priority)
+		elif signal_name in self._signals:
+			self._signals[signal_name].sort(key=lambda handler: -handler._priority)
+		else:
+			return False
+
 	def signal_unbind(self, signal_handler):
 		"""
 		Removes a signal binding.
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index bc09b080..81e50ed9 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -103,11 +103,11 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 		for opt in ('sort_directories_first', 'sort', 'sort_reverse',
 				'sort_case_insensitive'):
 			self.settings.signal_bind('setopt.' + opt,
-					self.request_resort, weak=True)
+					self.request_resort, weak=True, autosort=False)
 
 		for opt in ('hidden_filter', 'show_hidden'):
 			self.settings.signal_bind('setopt.' + opt,
-				self.request_reload, weak=True)
+				self.request_reload, weak=True, autosort=False)
 		self.use()
 
 	def request_resort(self):