Add support for preserving cwd across tab creation events. Fixes a regression reported by jkaker

This commit is contained in:
Chris Jones 2010-04-02 16:45:32 +01:00
parent c8e654d0a8
commit 364a833324
6 changed files with 49 additions and 13 deletions

View File

@ -148,13 +148,15 @@ class Notebook(Container, gtk.Notebook):
children.append(self.get_nth_page(page)) children.append(self.get_nth_page(page))
return(children) 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""" """Add a new tab, optionally supplying a child widget"""
maker = Factory() maker = Factory()
top_window = get_top_window(self) top_window = get_top_window(self)
if not widget: if not widget:
widget = maker.make('Terminal') widget = maker.make('Terminal')
if cwd:
widget.set_cwd(cwd)
widget.spawn_child(debugserver=debugtab) widget.spawn_child(debugserver=debugtab)
signals = {'close-term': self.wrapcloseterm, signals = {'close-term': self.wrapcloseterm,
@ -168,12 +170,17 @@ class Notebook(Container, gtk.Notebook):
'group-tab': top_window.group_tab, 'group-tab': top_window.group_tab,
'ungroup-tab': top_window.ungroup_tab, 'ungroup-tab': top_window.ungroup_tab,
'move-tab': top_window.move_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} 'navigate': top_window.navigate_terminal}
if maker.isinstance(widget, 'Terminal'): if maker.isinstance(widget, 'Terminal'):
for signal in signals: 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) self.set_tab_reorderable(widget, True)
label = TabLabel(self.window.get_title(), self) label = TabLabel(self.window.get_title(), self)

View File

@ -100,7 +100,7 @@ class Paned(Container):
'ungroup-tab': top_window.ungroup_tab, 'ungroup-tab': top_window.ungroup_tab,
'move-tab': top_window.move_tab, 'move-tab': top_window.move_tab,
'maximise': [top_window.zoom, False], 'maximise': [top_window.zoom, False],
'tab-new': top_window.tab_new, 'tab-new': [top_window.tab_new, widget],
'navigate': top_window.navigate_terminal} 'navigate': top_window.navigate_terminal}
for signal in signals: for signal in signals:

View File

@ -52,7 +52,7 @@ class Terminal(gtk.VBox):
'split-vert': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, 'split-vert': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_STRING,)), (gobject.TYPE_STRING,)),
'tab-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, '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, ()), 'tab-top-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
'focus-in': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'focus-in': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
'zoom': (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 our profile name"""
return(self.config.profile) return(self.config.profile)
def get_cwd(self):
"""Return our cwd"""
return(self.terminator.pid_cwd(self.pid))
def close(self): def close(self):
"""Close ourselves""" """Close ourselves"""
dbg('Terminal::close: emitting close-term') dbg('Terminal::close: emitting close-term')

View File

@ -100,13 +100,14 @@ class TerminalPopupMenu(object):
menu.append(item) menu.append(item)
item = gtk.MenuItem(_('Open _Tab')) 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) 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 = gtk.MenuItem(_('Open _Debug Tab'))
item.connect('activate', lambda x: item.connect('activate', lambda x:
terminal.emit('tab-new', True)) terminal.emit('tab-new', True, terminal))
menu.append(item) menu.append(item)
menu.append(gtk.MenuItem()) menu.append(gtk.MenuItem())

View File

@ -324,6 +324,13 @@ class Terminator(Borg):
else: else:
return([widget]) 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): def focus_changed(self, widget):
"""We just moved focus to a new terminal""" """We just moved focus to a new terminal"""
for terminal in self.terminals: for terminal in self.terminals:

View File

@ -149,7 +149,7 @@ class Window(Container, gtk.Window):
self.on_destroy_event(window, self.on_destroy_event(window,
gtk.gdk.Event(gtk.gdk.DESTROY)) gtk.gdk.Event(gtk.gdk.DESTROY))
elif mapping == 'new_tab': elif mapping == 'new_tab':
self.tab_new() self.tab_new(self.get_focussed_terminal())
else: else:
return(False) return(False)
return(True) return(True)
@ -159,12 +159,16 @@ class Window(Container, gtk.Window):
maker = Factory() maker = Factory()
return(maker.isinstance(self.get_child(), 'Notebook')) 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""" """Make a new tab"""
cwd = None
if widget:
cwd = widget.get_cwd()
maker = Factory() maker = Factory()
if not self.is_child_notebook(): if not self.is_child_notebook():
notebook = maker.make('Notebook', window=self) 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): def on_delete_event(self, window, event, data=None):
"""Handle a window close request""" """Handle a window close request"""
@ -267,11 +271,16 @@ class Window(Container, gtk.Window):
'group-tab': self.group_tab, 'group-tab': self.group_tab,
'ungroup-tab': self.ungroup_tab, 'ungroup-tab': self.ungroup_tab,
'move-tab': self.move_tab, 'move-tab': self.move_tab,
'tab-new': self.tab_new, 'tab-new': [self.tab_new, widget],
'navigate': self.navigate_terminal} 'navigate': self.navigate_terminal}
for signal in signals: 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() widget.grab_focus()
@ -387,6 +396,14 @@ class Window(Container, gtk.Window):
return(terminals) 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): def set_rough_geometry_hints(self):
"""Walk all the terminals along the top and left edges to fake up how """Walk all the terminals along the top and left edges to fake up how
many columns/rows we sort of have""" many columns/rows we sort of have"""