From 706180976e30244104e73230cc86051f2bf736d5 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 5 Mar 2010 22:44:38 +0000 Subject: [PATCH] Set cwd when spawning new shells to be that of the shell being split. Does not currently persist across tab creations --- terminatorlib/container.py | 10 +++++----- terminatorlib/notebook.py | 3 ++- terminatorlib/paned.py | 3 ++- terminatorlib/terminal.py | 15 +++++++++++---- terminatorlib/terminator.py | 4 ++++ terminatorlib/window.py | 3 ++- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/terminatorlib/container.py b/terminatorlib/container.py index 96f8890b..a009dee2 100755 --- a/terminatorlib/container.py +++ b/terminatorlib/container.py @@ -63,15 +63,15 @@ class Container(object): """Return a list of direct child widgets, if any""" return(self.children) - def split_horiz(self, widget): + def split_horiz(self, widget, cwd=None): """Split this container horizontally""" - return(self.split_axis(widget, True)) + return(self.split_axis(widget, True, cwd)) - def split_vert(self, widget): + def split_vert(self, widget, cwd=None): """Split this container vertically""" - return(self.split_axis(widget, False)) + return(self.split_axis(widget, False, cwd)) - def split_axis(self, widget, vertical=True, sibling=None, siblinglast=None): + def split_axis(self, widget, vertical=True, cwd=None, sibling=None, siblinglast=None): """Default axis splitter. This should be implemented by subclasses""" raise NotImplementedError('split_axis') diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index 8919e2e7..a4516651 100755 --- a/terminatorlib/notebook.py +++ b/terminatorlib/notebook.py @@ -86,7 +86,7 @@ class Notebook(Container, gtk.Notebook): page.create_layout(children[child_key]) num = num + 1 - def split_axis(self, widget, vertical=True, sibling=None, widgetfirst=True): + def split_axis(self, widget, vertical=True, cwd=None, sibling=None, widgetfirst=True): """Split the axis of a terminal inside us""" order = None page_num = self.page_num(widget) @@ -105,6 +105,7 @@ class Notebook(Container, gtk.Notebook): if not sibling: sibling = maker.make('terminal') + sibling.set_cwd(cwd) sibling.spawn_child() self.insert_page(container, None, page_num) diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index 541ce7d3..c71084a7 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -40,7 +40,7 @@ class Paned(Container): self.cnxids.remove_signal(self, 'expose-event') # pylint: disable-msg=W0613 - def split_axis(self, widget, vertical=True, sibling=None, + def split_axis(self, widget, vertical=True, cwd=None, sibling=None, widgetfirst=True): """Default axis splitter. This should be implemented by subclasses""" order = None @@ -55,6 +55,7 @@ class Paned(Container): if not sibling: sibling = maker.make('terminal') + sibling.set_cwd(cwd) sibling.spawn_child() self.add(container) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 6e1a4164..97add598 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -47,8 +47,10 @@ class Terminal(gtk.VBox): 'group-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'ungroup-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'ungroup-all': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), - 'split-horiz': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), - 'split-vert': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'split-horiz': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,)), + 'split-vert': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,)), 'tab-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'tab-top-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'focus-in': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), @@ -1037,6 +1039,11 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) """Restore normal layout""" self.emit('unzoom') + def set_cwd(self, cwd=None): + """Set our cwd""" + if cwd is not None: + self.cwd = cwd + def spawn_child(self, widget=None, respawn=False): update_records = self.config['update_records'] login = self.config['login_shell'] @@ -1275,10 +1282,10 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) self.emit('navigate', 'right') def key_split_horiz(self): - self.emit('split-horiz') + self.emit('split-horiz', self.terminator.pid_cwd(self.pid)) def key_split_vert(self): - self.emit('split-vert') + self.emit('split-vert', self.terminator.pid_cwd(self.pid)) def key_close_term(self): self.close() diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index eb3c67be..9a0df9cf 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -10,6 +10,7 @@ from config import Config from keybindings import Keybindings from util import dbg, err from factory import Factory +from cwd import get_pid_cwd class Terminator(Borg): """master object for the application""" @@ -22,6 +23,7 @@ class Terminator(Borg): keybindings = None origcwd = None + pid_cwd = None doing_layout = None @@ -52,6 +54,8 @@ class Terminator(Borg): self.keybindings.configure(self.config['keybindings']) if not self.doing_layout: self.doing_layout = False + if not self.pid_cwd: + self.pid_cwd = get_pid_cwd() def register_window(self, window): """Register a new window widget""" diff --git a/terminatorlib/window.py b/terminatorlib/window.py index f21e0381..8138f0e5 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -291,7 +291,7 @@ class Window(Container, gtk.Window): Container.closeterm(self, widget) self.hoover() - def split_axis(self, widget, vertical=True, sibling=None, widgetfirst=True): + def split_axis(self, widget, vertical=True, cwd=None, sibling=None, widgetfirst=True): """Split the window""" order = None maker = Factory() @@ -304,6 +304,7 @@ class Window(Container, gtk.Window): if not sibling: sibling = maker.make('Terminal') + sibling.set_cwd(cwd) sibling.spawn_child() self.add(container) container.show_all()