From 1ee34606450cabd86a62ca5992775729e9dd098a Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 6 Apr 2010 01:54:46 +0200 Subject: Improved tabs --- doc/ranger.1 | 3 +++ ranger/core/actions.py | 25 ++++++++++++++----------- ranger/defaults/keys.py | 1 + ranger/gui/widgets/titlebar.py | 7 +++++++ ranger/help/movement.py | 1 + 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index e62cee54..2e03b729 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -124,6 +124,9 @@ g\fIN\fR Open a tab. N has to be a number from 0 to 9. If the tab doesn't exist yet, it will be created. .TP +gn +Create a new tab. +.TP gt, gT Go to the next or previous tab. You can also use TAB and SHIFT+TAB. .TP diff --git a/ranger/core/actions.py b/ranger/core/actions.py index d52dac2b..b40febc8 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -428,12 +428,15 @@ class Actions(EnvironmentAware, SettingsAware): 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) + def tab_open(self, name, path=None): + do_emit_signal = name != self.current_tab + self.current_tab = name + if path or (name in self.tabs): + self.enter_dir(path or self.tabs[name]) else: - self.tab_new(name) + self._update_current_tab() + if do_emit_signal: + self.signal_emit('tab.change') def tab_close(self, name=None): if name is None: @@ -454,12 +457,12 @@ class Actions(EnvironmentAware, SettingsAware): 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 tab_new(self): + for i in range(10): + i = (i + 1) % 10 + if not i in self.tabs: + self.tab_open(i) + break def _update_current_tab(self): self.tabs[self.current_tab] = self.env.cwd.path diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 9be42a78..63e09dfd 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -170,6 +170,7 @@ def initialize_commands(map): map('gc', ctrl('W'), fm.tab_close()) map('gt', TAB, fm.tab_move(1)) map('gT', KEY_BTAB, fm.tab_move(-1)) + map('gn', ctrl('N'), fm.tab_new()) for n in range(10): map('g' + str(n), fm.tab_open(n)) diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index 4bd15e0f..c643b8a8 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -33,6 +33,13 @@ class TitleBar(Widget): need_redraw = False tab_width = 0 + def __init__(self, *args, **keywords): + Widget.__init__(self, *args, **keywords) + self.fm.signal_bind('tab.change', self.request_redraw, weak=True) + + def request_redraw(self): + self.need_redraw = True + def draw(self): if self.need_redraw or \ self.env.cf != self.old_cf or\ diff --git a/ranger/help/movement.py b/ranger/help/movement.py index e9dd6fad..df5021f2 100644 --- a/ranger/help/movement.py +++ b/ranger/help/movement.py @@ -142,6 +142,7 @@ In Ranger, tabs are very simple though and only store the directory path. gt Go to the next tab. (also TAB) gT Go to the previous tab. (also Shift+TAB) + gn Create a new tab g Open a tab. N has to be a number from 0 to 9. If the tab doesn't exist yet, it will be created. gc, ^W Close the current tab. The last tab cannot be closed. -- cgit 1.4.1-2-gfad0