summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-31 15:18:55 +0200
committerhut <hut@lavabit.com>2010-03-31 15:18:55 +0200
commit9e63489ab8bf81ec394e3248a2ef96ee1dc6e640 (patch)
tree0e12b183970275a74d706bd01cfdb11b2a1d27c2
parentd9c5f33bc1b1b6e4c7ce82cf8d28c1af62be78cf (diff)
downloadranger-9e63489ab8bf81ec394e3248a2ef96ee1dc6e640.tar.gz
add "move" signal to environment
-rw-r--r--ranger/core/environment.py22
-rw-r--r--ranger/gui/widgets/browserview.py26
2 files changed, 33 insertions, 15 deletions
diff --git a/ranger/core/environment.py b/ranger/core/environment.py
index 89088c45..1d1464d2 100644
--- a/ranger/core/environment.py
+++ b/ranger/core/environment.py
@@ -21,15 +21,15 @@ from os.path import abspath, normpath, join, expanduser, isdir
 
 from ranger.fsobject.directory import Directory, NoDirectoryGiven
 from ranger.container import KeyBuffer, History
+from ranger.ext.signal_dispatcher import SignalDispatcher
 from ranger.shared import SettingsAware
 
-class Environment(SettingsAware):
+class Environment(SettingsAware, SignalDispatcher):
 	"""A collection of data which is relevant for more than
 	one class.
 	"""
 
 	cwd = None  # current directory
-	cf = None  # current file
 	copy = None
 	cmd = None
 	cut = None
@@ -42,7 +42,9 @@ class Environment(SettingsAware):
 	keybuffer = None
 
 	def __init__(self, path):
+		SignalDispatcher.__init__(self)
 		self.path = abspath(expanduser(path))
+		self._cf = None
 		self.pathway = ()
 		self.directories = {}
 		self.keybuffer = KeyBuffer()
@@ -59,6 +61,22 @@ class Environment(SettingsAware):
 		from ranger.shared import EnvironmentAware
 		EnvironmentAware.env = self
 
+		self.signal_bind('move', self._set_cf_from_signal, priority=0.1,
+				weak=True)
+
+	def _set_cf_from_signal(self, signal):
+		self._cf = signal.new
+
+	def _set_cf(self, value):
+		if value is not self._cf:
+			previous = self._cf
+			self.signal_emit('move', previous=previous, new=value)
+
+	def _get_cf(self):
+		return self._cf
+
+	cf = property(_get_cf, _set_cf)
+
 	def key_append(self, key):
 		"""Append a key to the keybuffer"""
 
diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py
index e31a21ff..13142be4 100644
--- a/ranger/gui/widgets/browserview.py
+++ b/ranger/gui/widgets/browserview.py
@@ -31,9 +31,6 @@ class BrowserView(Widget, DisplayableContainer):
 		DisplayableContainer.__init__(self, win)
 		self.ratios = ratios
 		self.preview = preview
-		self.old_cf = self.env.cf
-		self.old_prevfile = None
-		self.old_prevdir = None
 
 		# normalize ratios:
 		ratio_sum = float(sum(ratios))
@@ -63,25 +60,28 @@ class BrowserView(Widget, DisplayableContainer):
 		self.pager.visible = False
 		self.add_child(self.pager)
 
+		for option in ('preview_directories', 'preview_files'):
+			self.settings.signal_bind('setopt.' + option,
+					self._request_clear_if_has_borders, weak=True)
+
+		self.fm.env.signal_bind('move', self.request_clear)
+
+	def _request_clear_if_has_borders(self):
+		if self.settings.draw_borders:
+			self.request_clear()
+
+	def request_clear(self):
+		self.need_clear = True
+
 	def draw(self):
 		try:
 			if self.env.cmd.show_obj.draw_bookmarks:
 				self._draw_bookmarks()
 		except AttributeError:
-			if self.old_cf != self.env.cf:
-				self.need_clear = True
-			if self.settings.draw_borders:
-				if self.old_prevdir != self.settings.preview_directories:
-					self.need_clear = True
-				if self.old_prevfile != self.settings.preview_files:
-					self.need_clear = True
 			if self.need_clear:
 				self.win.erase()
 				self.need_redraw = True
 				self.need_clear = False
-				self.old_cf = self.env.cf
-				self.old_prevfile = self.settings.preview_files
-				self.old_prevdir = self.settings.preview_directories
 			DisplayableContainer.draw(self)
 			if self.settings.draw_borders:
 				self._draw_borders()