diff --git a/terminatorlib/config.py b/terminatorlib/config.py index f122287a..801dc9c0 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -163,8 +163,10 @@ DEFAULTS = { 'reset_clear' : 'g', 'hide_window' : 'a', 'group_all' : 'g', + 'group_all_toggle' : '', 'ungroup_all' : 'g', 'group_tab' : 't', + 'group_tab_toggle' : '', 'ungroup_tab' : 't', 'new_window' : 'i', 'new_terminator' : 'i', diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index 931bf83a..62b4f613 100755 --- a/terminatorlib/notebook.py +++ b/terminatorlib/notebook.py @@ -249,8 +249,10 @@ class Notebook(Container, gtk.Notebook): 'unzoom': self.unzoom, 'tab-change': top_window.tab_change, 'group-all': top_window.group_all, + 'group-all-toggle': top_window.group_all_toggle, 'ungroup-all': top_window.ungroup_all, 'group-tab': top_window.group_tab, + 'group-tab-toggle': top_window.group_tab_toggle, 'ungroup-tab': top_window.ungroup_tab, 'move-tab': top_window.move_tab, 'tab-new': [top_window.tab_new, widget], diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index 119b437d..dada8768 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -98,8 +98,10 @@ class Paned(Container): 'zoom': top_window.zoom, 'tab-change': top_window.tab_change, 'group-all': top_window.group_all, + 'group-all-toggle': top_window.group_all_toggle, 'ungroup-all': top_window.ungroup_all, 'group-tab': top_window.group_tab, + 'group-tab-toggle': top_window.group_tab_toggle, 'ungroup-tab': top_window.ungroup_tab, 'move-tab': top_window.move_tab, 'maximise': [top_window.zoom, False], diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index de2cdcbe..9e3c684d 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -134,8 +134,10 @@ class PrefsEditor: 'reset_clear' : 'Reset and clear the terminal', 'hide_window' : 'Toggle window visibility', 'group_all' : 'Group all terminals', + 'group_all_toggle' : 'Group/Ungroup all terminals', 'ungroup_all' : 'Ungroup all terminals', 'group_tab' : 'Group terminals in tab', + 'group_tab_toggle' : 'Group/Ungroup terminals in tab', 'ungroup_tab' : 'Ungroup terminals in tab', 'new_window' : 'Create a new window', 'new_terminator' : 'Spawn a new Terminator process', diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index aa9c86f8..adf18adc 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -46,6 +46,7 @@ class Terminal(gtk.VBox): 'enumerate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)), 'group-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'group-tab-toggle': (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, @@ -69,6 +70,7 @@ class Terminal(gtk.VBox): 'tab-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)), 'group-all': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'group-all-toggle': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'move-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)), } @@ -1679,12 +1681,18 @@ class Terminal(gtk.VBox): def key_group_all(self): self.emit('group-all') + def key_group_all_toggle(self): + self.emit('group-all-toggle') + def key_ungroup_all(self): self.emit('ungroup-all') def key_group_tab(self): self.emit('group-tab') - + + def key_group_tab_toggle(self): + self.emit('group-tab-toggle') + def key_ungroup_tab(self): self.emit('ungroup-tab') diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index c0c6af6c..418cb738 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -160,7 +160,6 @@ class Terminator(Borg): dbg('Terminator::register_terminal: registering %s:%s' % (id(terminal), type(terminal))) self.terminals.append(terminal) - terminal.connect('ungroup-all', self.ungroup_all) def deregister_terminal(self, terminal): """De-register a terminal widget""" @@ -377,12 +376,6 @@ class Terminator(Borg): dbg('Terminator::create_group: registering group %s' % name) self.groups.append(name) - def ungroup_all(self, widget): - """Remove all groups""" - for terminal in self.terminals: - terminal.set_group(None, None) - self.groups = [] - def closegroupedterms(self, group): """Close all terminals in a group""" for terminal in self.terminals[:]: diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 2a20a3bd..09a8987c 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -411,8 +411,10 @@ class Window(Container, gtk.Window): 'unzoom': self.unzoom, 'tab-change': self.tab_change, 'group-all': self.group_all, + 'group-all-toggle': self.group_all_toggle, 'ungroup-all': self.ungroup_all, 'group-tab': self.group_tab, + 'group-tab-toggle': self.group_tab_toggle, 'ungroup-tab': self.ungroup_tab, 'move-tab': self.move_tab, 'tab-new': [self.tab_new, widget], @@ -687,21 +689,29 @@ class Window(Container, gtk.Window): # change child.set_current_page(child.get_current_page()) - # FIXME: All of these (un)group_(all|tab) methods need refactoring work + def set_groups(self, new_group, term_list): + """Set terminals in term_list to new_group""" + for terminal in term_list: + terminal.set_group(None, new_group) + self.terminator.focus_changed(self.terminator.last_focused_term) + def group_all(self, widget): """Group all terminals""" # FIXME: Why isn't this being done by Terminator() ? group = _('All') self.terminator.create_group(group) - for terminal in self.terminator.terminals: - terminal.set_group(None, group) - self.terminator.focus_changed(self.terminator.last_focused_term) + self.set_groups(group, self.terminator.terminals) + + def group_all_toggle(self, widget): + """Toggle grouping to all""" + if widget.group == 'All': + self.ungroup_all(widget) + else: + self.group_all(widget) def ungroup_all(self, widget): """Ungroup all terminals""" - for terminal in self.terminator.terminals: - terminal.set_group(None, None) - self.terminator.focus_changed(self.terminator.last_focused_term) + self.set_groups(None, self.terminator.terminals) def group_tab(self, widget): """Group all terminals in the current tab""" @@ -718,9 +728,14 @@ class Window(Container, gtk.Window): if group not in self.terminator.groups: break pagenum += 1 - for terminal in self.get_visible_terminals(): - terminal.set_group(None, group) - self.terminator.focus_changed(self.terminator.last_focused_term) + self.set_groups(group, self.get_visible_terminals()) + + def group_tab_toggle(self, widget): + """Blah""" + if widget.group and widget.group[:4] == 'Tab ': + self.ungroup_tab(widget) + else: + self.group_tab(widget) def ungroup_tab(self, widget): """Ungroup all terminals in the current tab""" @@ -731,9 +746,7 @@ class Window(Container, gtk.Window): dbg('note in a notebook, refusing to ungroup tab') return - for terminal in self.get_visible_terminals(): - terminal.set_group(None, None) - self.terminator.focus_changed(self.terminator.last_focused_term) + self.set_groups(None, self.get_visible_terminals()) def move_tab(self, widget, direction): """Handle a keyboard shortcut for moving tab positions"""