about summary refs log tree commit diff stats
path: root/ranger/core/fm.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-05 08:11:33 +0200
committerhut <hut@lavabit.com>2012-08-05 14:36:33 +0200
commit7f9df493dd6b0fd13abe93ddfea2755ee24c3d72 (patch)
treeeb3a6001afccb9822049aa8c5b5dbbba3d3e3fea /ranger/core/fm.py
parente38d42ca55285b61ed70722da92d9871c8686f88 (diff)
downloadranger-7f9df493dd6b0fd13abe93ddfea2755ee24c3d72.tar.gz
Replaced core.environment with core.tab
The Environment class was weird to begin with.  It had attributes and
methods that belonged to other classes. For example, keybinding
management (the attributes keybuffer and keymaps) should go to gui.ui,
directory management (garbage_collect, get_directory) should be in
core.fm whereas entering directories (enter_dir) and managing history
(history_go) should be the task of a separate Tab class.

This commit fixes it, all references to env should be only for backwards
compatibility now.  I still need to rewrite the tabbing API in
core.actions to work with the new system.  Every tab that is opened will
have its own Tab instance with its own history and pointer.  Tab, unlike
Environment, is no SignalDispatcher - Environment's signals were moved
to fm.

BEFORE: fm.env.cf
AFTER : fm.thisfile

BEFORE: fm.env.cwd
AFTER : fm.thisdir

BEFORE: fm.env.signal_bind("move", ...)   # same for the "cd" signal
AFTER : fm.signal_bind("move", ...)

BEFORE: fm.env.keybuffer                  # same for fm.env.keymaps
AFTER : fm.ui.keybuffer

BEFORE: fm.env.get_directory("/usr/lib")  # same for half of the env methods
AFTER : fm.get_directory("/usr/lib")

BEFORE: fm.env.get_selection()  # same for the other half of the env methods
AFTER : fm.thistab.get_selection()

Old configurations and hacks should still work because I added a
compatibility layer for the Environment class which translates all
getters and setters to the respective call of the new class.

What will NOT work are the Environment signals, please bind them to fm
instead.
Diffstat (limited to 'ranger/core/fm.py')
-rw-r--r--ranger/core/fm.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 814d16ba..34e761bd 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -16,6 +16,7 @@ import sys
 
 import ranger
 from ranger.core.actions import Actions
+from ranger.core.tab import Tab
 from ranger.container.tags import Tags
 from ranger.gui.ui import UI
 from ranger.container.bookmarks import Bookmarks
@@ -49,11 +50,11 @@ class FM(Actions, SignalDispatcher):
 		self.directories = dict()
 		self.log = deque(maxlen=20)
 		self.bookmarks = bookmarks
-		self.tags = tags
+		self.current_tab = 1
 		self.tabs = {}
+		self.tags = tags
 		self.py3 = sys.version_info >= (3, )
 		self.previews = {}
-		self.current_tab = 1
 		self.loader = Loader()
 		self.copy_buffer = set()
 		self.do_cut = False
@@ -76,6 +77,8 @@ class FM(Actions, SignalDispatcher):
 	def initialize(self):
 		"""If ui/bookmarks are None, they will be initialized here."""
 
+		self.thistab = Tab(".")
+		self.tabs[self.current_tab] = self.thistab
 		if not ranger.arg.clean and os.path.isfile(self.confpath('rifle.conf')):
 			rifleconf = self.confpath('rifle.conf')
 		else:
@@ -110,8 +113,6 @@ class FM(Actions, SignalDispatcher):
 			self.notify(text, bad=True)
 		self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)
 
-		self.env.signal_bind('cd', self._update_current_tab)
-
 		if self.settings.init_function:
 			self.settings.init_function(self)
 
@@ -130,6 +131,21 @@ class FM(Actions, SignalDispatcher):
 				if debug:
 					raise
 
+	def _get_thisfile(self):
+		return self.thistab.thisfile
+
+	def _set_thisfile(self, obj):
+		self.thistab.thisfile = obj
+
+	def _get_thisdir(self):
+		return self.thistab.thisdir
+
+	def _set_thisdir(self, obj):
+		self.thistab.thisdir = obj
+
+	thisfile = property(_get_thisfile, _set_thisfile)
+	thisdir  = property(_get_thisdir,  _set_thisdir)
+
 	def block_input(self, sec=0):
 		self.input_blocked = sec != 0
 		self.input_blocked_until = time() + sec
@@ -190,14 +206,13 @@ class FM(Actions, SignalDispatcher):
 			self.directories[path] = obj
 			return obj
 
-	def garbage_collect(self, age, tabs):
+	def garbage_collect(self, age, tabs=None):  # tabs=None is for COMPATibility
 		"""Delete unused directory objects"""
 		for key in tuple(self.directories):
 			value = self.directories[key]
 			if age != -1:
-				if not value.is_older_than(age) or value in self.pathway:
-					continue
-				if value in tabs.values():
+				if not value.is_older_than(age) \
+						or any(value in tab.pathway for tab in self.tabs.values()):
 					continue
 			del self.directories[key]
 			if value.is_directory:
@@ -215,7 +230,7 @@ class FM(Actions, SignalDispatcher):
 		5. after X loops: collecting unused directory objects
 		"""
 
-		self.env.enter_dir(self.env.path)
+		self.enter_dir(self.thistab.path)
 
 		gc_tick = 0
 
@@ -249,8 +264,7 @@ class FM(Actions, SignalDispatcher):
 				gc_tick += 1
 				if gc_tick > ranger.TICKS_BEFORE_COLLECTING_GARBAGE:
 					gc_tick = 0
-					self.garbage_collect(
-						ranger.TIME_BEFORE_FILE_BECOMES_GARBAGE, self.tabs)
+					self.garbage_collect(ranger.TIME_BEFORE_FILE_BECOMES_GARBAGE)
 
 		except KeyboardInterrupt:
 			# this only happens in --debug mode. By default, interrupts
@@ -258,9 +272,9 @@ class FM(Actions, SignalDispatcher):
 			raise SystemExit
 
 		finally:
-			if ranger.arg.choosedir and self.env.cwd and self.env.cwd.path:
+			if ranger.arg.choosedir and self.thisdir and self.thisdir.path:
 				# XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
 				# '\udcf6' in position 42: surrogates not allowed
-				open(ranger.arg.choosedir, 'w').write(self.env.cwd.path)
-			self.bookmarks.remember(self.env.cwd)
+				open(ranger.arg.choosedir, 'w').write(self.thisdir.path)
+			self.bookmarks.remember(self.thisdir)
 			self.bookmarks.save()