summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-05 16:10:09 +0200
committerhut <hut@lavabit.com>2012-08-05 16:11:56 +0200
commit8d6c23f785d3e1ac9be8855ccc4e0df6c240c8bd (patch)
treecfbeda1fbbd08bfe040aeca6f899abe888b62a27
parent90ce9ed7545b733fb1ec9e769c10bba6e3fd4ab2 (diff)
downloadranger-8d6c23f785d3e1ac9be8855ccc4e0df6c240c8bd.tar.gz
add keybinding 'uq' to restore a closed tab
This is added to compensate for the fact that the history is not shared
anymore and you can't simply type gnHH to restore a closed tab.
-rw-r--r--ranger/__init__.py1
-rw-r--r--ranger/config/rc.conf1
-rw-r--r--ranger/core/actions.py17
-rw-r--r--ranger/core/fm.py1
4 files changed, 20 insertions, 0 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py
index 85ec0b5e..d3c39946 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -21,6 +21,7 @@ __email__ = 'romanz@lavabit.com'
 RANGERDIR = os.path.dirname(__file__)
 TICKS_BEFORE_COLLECTING_GARBAGE = 100
 TIME_BEFORE_FILE_BECOMES_GARBAGE = 1200
+MAX_RESTORABLE_TABS = 3
 MACRO_DELIMITER = '%'
 DEFAULT_PAGER = 'less'
 LOGFILE = '/tmp/ranger_errorlog'
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 1b802fd5..1b344465 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -191,6 +191,7 @@ map gt        tab_move 1
 map gT        tab_move -1
 map gn        tab_new ~
 map gc        tab_close
+map uq        tab_restore
 map <a-1>     tab_open 1
 map <a-2>     tab_open 2
 map <a-3>     tab_open 3
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index b0e5bf02..b7205dc5 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -42,6 +42,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	def reset(self):
 		"""Reset the filemanager, clearing the directory buffer"""
 		old_path = self.thisdir.path
+		self.restorable_tabs = {}
 		self.previews = {}
 		self.garbage_collect(-1, self.tabs)
 		self.enter_dir(old_path)
@@ -855,6 +856,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	def tab_close(self, name=None):
 		if name is None:
 			name = self.current_tab
+		tab = self.tabs[name]
 		if name == self.current_tab:
 			direction = -1 if name == self._get_tab_list()[-1] else 1
 			previous = self.current_tab
@@ -863,6 +865,21 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 				return  # can't close last tab
 		if name in self.tabs:
 			del self.tabs[name]
+		self.restorable_tabs.append(tab)
+
+	def tab_restore(self):
+		# NOTE: The name of the tab is not restored.
+		if self.restorable_tabs:
+			tab = self.restorable_tabs.pop()
+			for name in range(1, len(self.tabs) + 2):
+				if not name in self.tabs:
+					self.current_tab = name
+					self.tabs[name] = tab
+					tab.enter_dir(tab.path)
+					self.thistab = tab
+					self.change_mode('normal')
+					self.signal_emit('tab.change')
+					break
 
 	def tab_move(self, offset):
 		assert isinstance(offset, int)
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 34e761bd..dda125d0 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -53,6 +53,7 @@ class FM(Actions, SignalDispatcher):
 		self.current_tab = 1
 		self.tabs = {}
 		self.tags = tags
+		self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
 		self.py3 = sys.version_info >= (3, )
 		self.previews = {}
 		self.loader = Loader()