diff options
author | hut <hut@lavabit.com> | 2010-04-06 01:03:08 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-06 01:03:08 +0200 |
commit | 227f75db399276f6395469937e60a96db45f8089 (patch) | |
tree | 6b5d32c888675a9d2abdcdd45dc873f78b4896a2 /ranger/core | |
parent | c72c8a9a1023515e1a732f156a02096155f8bbc5 (diff) | |
download | ranger-227f75db399276f6395469937e60a96db45f8089.tar.gz |
added tabs
The hotkeys are: g<n> to open a tab, gt/gT to move through tabs, gc/^W to close tabs.
Diffstat (limited to 'ranger/core')
-rw-r--r-- | ranger/core/actions.py | 45 | ||||
-rw-r--r-- | ranger/core/environment.py | 4 | ||||
-rw-r--r-- | ranger/core/fm.py | 4 |
3 files changed, 53 insertions, 0 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 7da029cd..d52dac2b 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -419,6 +419,51 @@ class Actions(EnvironmentAware, SettingsAware): if hasattr(self.ui, 'status'): self.ui.status.need_redraw = True + # -------------------------- + # -- Tabs + # -------------------------- + # This implementation of tabs is very simple and keeps track of + # directory paths only. + + def _get_tab_list(self): + return sorted(self.tabs) + + def tab_open(self, name): + if name in self.tabs: + self.current_tab = name + self.enter_dir(self.tabs[name], remember=False) + else: + self.tab_new(name) + + def tab_close(self, name=None): + if name is None: + name = self.current_tab + if name == self.current_tab: + previous = self.current_tab + self.tab_move(-1) + if previous == self.current_tab: + return # can't close last tab + if name in self.tabs: + del self.tabs[name] + + def tab_move(self, offset): + assert isinstance(offset, int) + tablist = self._get_tab_list() + current_index = tablist.index(self.current_tab) + newtab = tablist[(current_index + offset) % len(tablist)] + if newtab != self.current_tab: + self.tab_open(newtab) + + def tab_new(self, name, path=None): + self.current_tab = name + if path: + self.enter_dir(path, remember=False) + else: + self._update_current_tab() + + def _update_current_tab(self): + self.tabs[self.current_tab] = self.env.cwd.path + # ------------------------------------ filesystem operations def copy(self): diff --git a/ranger/core/environment.py b/ranger/core/environment.py index 1d1464d2..00b152d3 100644 --- a/ranger/core/environment.py +++ b/ranger/core/environment.py @@ -172,6 +172,8 @@ class Environment(SettingsAware, SignalDispatcher): if path is None: return path = str(path) + previous = self.cwd + # get the absolute path path = normpath(join(self.path, expanduser(path))) @@ -215,4 +217,6 @@ class Environment(SettingsAware, SignalDispatcher): if history: self.history.add(new_cwd) + self.signal_emit('cd', previous=previous, new=self.cwd) + return True diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 2e65c776..a38b9147 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -47,10 +47,14 @@ class FM(Actions, SignalDispatcher): self.log = deque(maxlen=20) self.bookmarks = bookmarks self.tags = tags + self.tabs = {} + self.current_tab = 1 self.loader = Loader() self._executables = None self.apps = self.settings.apps.CustomApplications() + self.env.signal_bind('cd', self._update_current_tab) + def mylogfunc(text): self.notify(text, bad=True) self.run = Runner(ui=self.ui, apps=self.apps, |