From 364a833324f6dad601f0093d82c35a2eaccbce3f Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 2 Apr 2010 16:45:32 +0100 Subject: [PATCH] Add support for preserving cwd across tab creation events. Fixes a regression reported by jkaker --- terminatorlib/notebook.py | 13 ++++++++++--- terminatorlib/paned.py | 2 +- terminatorlib/terminal.py | 6 +++++- terminatorlib/terminal_popup_menu.py | 7 ++++--- terminatorlib/terminator.py | 7 +++++++ terminatorlib/window.py | 27 ++++++++++++++++++++++----- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index 5ca87704..8208f1f7 100755 --- a/terminatorlib/notebook.py +++ b/terminatorlib/notebook.py @@ -148,13 +148,15 @@ class Notebook(Container, gtk.Notebook): children.append(self.get_nth_page(page)) return(children) - def newtab(self, debugtab=False, widget=None): + def newtab(self, debugtab=False, widget=None, cwd=None): """Add a new tab, optionally supplying a child widget""" maker = Factory() top_window = get_top_window(self) if not widget: widget = maker.make('Terminal') + if cwd: + widget.set_cwd(cwd) widget.spawn_child(debugserver=debugtab) signals = {'close-term': self.wrapcloseterm, @@ -168,12 +170,17 @@ class Notebook(Container, gtk.Notebook): 'group-tab': top_window.group_tab, 'ungroup-tab': top_window.ungroup_tab, 'move-tab': top_window.move_tab, - 'tab-new': top_window.tab_new, + 'tab-new': [top_window.tab_new, widget], 'navigate': top_window.navigate_terminal} if maker.isinstance(widget, 'Terminal'): for signal in signals: - self.connect_child(widget, signal, signals[signal]) + args = [] + handler = signals[signal] + if isinstance(handler, list): + args = handler[1:] + handler = handler[0] + self.connect_child(widget, signal, handler, *args) self.set_tab_reorderable(widget, True) label = TabLabel(self.window.get_title(), self) diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index f2f066cf..2a82db86 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -100,7 +100,7 @@ class Paned(Container): 'ungroup-tab': top_window.ungroup_tab, 'move-tab': top_window.move_tab, 'maximise': [top_window.zoom, False], - 'tab-new': top_window.tab_new, + 'tab-new': [top_window.tab_new, widget], 'navigate': top_window.navigate_terminal} for signal in signals: diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index abac61bf..00e84629 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -52,7 +52,7 @@ class Terminal(gtk.VBox): 'split-vert': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)), 'tab-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_BOOLEAN,)), + (gobject.TYPE_BOOLEAN, gobject.TYPE_OBJECT)), 'tab-top-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'focus-in': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'zoom': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), @@ -168,6 +168,10 @@ class Terminal(gtk.VBox): """Return our profile name""" return(self.config.profile) + def get_cwd(self): + """Return our cwd""" + return(self.terminator.pid_cwd(self.pid)) + def close(self): """Close ourselves""" dbg('Terminal::close: emitting close-term') diff --git a/terminatorlib/terminal_popup_menu.py b/terminatorlib/terminal_popup_menu.py index 9c75a6dd..ff0770b7 100755 --- a/terminatorlib/terminal_popup_menu.py +++ b/terminatorlib/terminal_popup_menu.py @@ -100,13 +100,14 @@ class TerminalPopupMenu(object): menu.append(item) item = gtk.MenuItem(_('Open _Tab')) - item.connect('activate', lambda x: terminal.emit('tab-new', False)) + item.connect('activate', lambda x: terminal.emit('tab-new', False, + terminal)) menu.append(item) - if self.terminator.debug_address or True: + if self.terminator.debug_address is not None: item = gtk.MenuItem(_('Open _Debug Tab')) item.connect('activate', lambda x: - terminal.emit('tab-new', True)) + terminal.emit('tab-new', True, terminal)) menu.append(item) menu.append(gtk.MenuItem()) diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 46909f3e..34ecda54 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -324,6 +324,13 @@ class Terminator(Borg): else: return([widget]) + def get_focussed_terminal(self): + """iterate over all the terminals to find which, if any, has focus""" + for terminal in self.terminals: + if terminal.has_focus(): + return(terminal) + return(None) + def focus_changed(self, widget): """We just moved focus to a new terminal""" for terminal in self.terminals: diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 5b683199..793071ee 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -149,7 +149,7 @@ class Window(Container, gtk.Window): self.on_destroy_event(window, gtk.gdk.Event(gtk.gdk.DESTROY)) elif mapping == 'new_tab': - self.tab_new() + self.tab_new(self.get_focussed_terminal()) else: return(False) return(True) @@ -159,12 +159,16 @@ class Window(Container, gtk.Window): maker = Factory() return(maker.isinstance(self.get_child(), 'Notebook')) - def tab_new(self, widget=None, debugtab=False): + def tab_new(self, widget=None, debugtab=False, _param1=None, _param2=None): """Make a new tab""" + cwd = None + + if widget: + cwd = widget.get_cwd() maker = Factory() if not self.is_child_notebook(): notebook = maker.make('Notebook', window=self) - self.get_child().newtab(debugtab) + self.get_child().newtab(debugtab, cwd=cwd) def on_delete_event(self, window, event, data=None): """Handle a window close request""" @@ -267,11 +271,16 @@ class Window(Container, gtk.Window): 'group-tab': self.group_tab, 'ungroup-tab': self.ungroup_tab, 'move-tab': self.move_tab, - 'tab-new': self.tab_new, + 'tab-new': [self.tab_new, widget], 'navigate': self.navigate_terminal} for signal in signals: - self.connect_child(widget, signal, signals[signal]) + args = [] + handler = signals[signal] + if isinstance(handler, list): + args = handler[1:] + handler = handler[0] + self.connect_child(widget, signal, handler, *args) widget.grab_focus() @@ -387,6 +396,14 @@ class Window(Container, gtk.Window): return(terminals) + def get_focussed_terminal(self): + """Find which terminal we want to have focus""" + terminals = self.get_visible_terminals() + for terminal in terminals: + if terminal.vte.is_focus(): + return(terminal) + return(None) + def set_rough_geometry_hints(self): """Walk all the terminals along the top and left edges to fake up how many columns/rows we sort of have"""