summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-01-11 14:58:14 +0100
committerhut <hut@lavabit.com>2012-01-11 16:58:24 +0100
commit0374f709574d3db79887b86ca4486d65f5eb1c01 (patch)
treef39a48d77efbe511afb1d5ed0cb635850d37adb1
parent4904e06e6aa2278f96d9fd007c6ac3261f127f25 (diff)
downloadranger-0374f709574d3db79887b86ca4486d65f5eb1c01.tar.gz
ext.signals: no unnecessary sorting on signal_bind
-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):