Significant grouping improvements. Nearly everything there and works great. Still require 2 GUI related things before done.

This commit is contained in:
Stephen Boddy 2009-01-10 17:13:49 +01:00
parent 895226aaa9
commit b69a54b53f
2 changed files with 128 additions and 47 deletions

View File

@ -133,6 +133,9 @@ class Terminator:
self.start_cwd = os.getcwd() self.start_cwd = os.getcwd()
self.term_list = [] self.term_list = []
self.gnome_client = None self.gnome_client = None
self.groupsend = 1 # 0 off, 1 group (d), 2 all
self.splittogroup = 1 # 0 no group, 1 new takes orginators group (d)
self.autocleangroups = 1 # 0 off, 1 on (d)
stores = [] stores = []
store = config.TerminatorConfValuestoreRC () store = config.TerminatorConfValuestoreRC ()
@ -709,6 +712,8 @@ class Terminator:
# create a new terminal and parent pane. # create a new terminal and parent pane.
dbg ('SEGBUG: Creating TerminatorTerm') dbg ('SEGBUG: Creating TerminatorTerm')
terminal = TerminatorTerm (self, self.profile, command, widget.get_cwd()) terminal = TerminatorTerm (self, self.profile, command, widget.get_cwd())
if self.splittogroup:
terminal.set_group (None, widget._group)
dbg ('SEGBUG: Created TerminatorTerm') dbg ('SEGBUG: Created TerminatorTerm')
pos = vertical and "right" or "bottom" pos = vertical and "right" or "bottom"
dbg ('SEGBUG: Position is: %s'%pos) dbg ('SEGBUG: Position is: %s'%pos)
@ -828,6 +833,19 @@ class Terminator:
return True return True
return False return False
def closegroupedterms (self, widget):
if self._zoomed:
# We are zoomed, pop back out to normal layout before closing
dbg ("closeterm function called while in zoomed mode. Restoring previous layout before closing.")
self.toggle_zoom(widget, not self._maximised)
widget_group = widget._group
for term in self.term_list:
if term._group == widget_group and not self.remove(term):
return False
self.group_hoover()
return True
def go_to (self, term, selector): def go_to (self, term, selector):
current = self.term_list.index (term) current = self.term_list.index (term)
target = selector (term) target = selector (term)
@ -1285,16 +1303,22 @@ class Terminator:
if term != terminatorterm and term._group == group: if term != terminatorterm and term._group == group:
term._vte.emit (type, event) term._vte.emit (type, event)
def all_emit (self, terminatorterm, type, event):
for term in self.term_list:
if term != terminatorterm:
term._vte.emit (type, event)
def group_hoover (self): def group_hoover (self):
destroy = [] if self.autocleangroups:
for group in self.groupings: destroy = []
save = False for group in self.groupings:
for term in self.term_list: save = False
if term._group == group: for term in self.term_list:
save = True if term._group == group:
save = True
if not save: if not save:
destroy.append (group) destroy.append (group)
for group in destroy: for group in destroy:
self.groupings.remove (group) self.groupings.remove (group)

View File

@ -311,6 +311,19 @@ text/plain
parent = widget.get_parent() parent = widget.get_parent()
dbg ('Drag drop on %s'%parent) dbg ('Drag drop on %s'%parent)
def get_target_terms(self):
if self.terminator.groupsend == 0:
return [self]
if self.terminator.groupsend == 2:
return self.terminator.term_list
if self.terminator.groupsend == 1:
term_subset = []
for term in self.terminator.term_list:
if term == self or (term._group != None and term._group == self._group):
term_subset.append(term)
return term_subset
return None
def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, time, data): def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, time, data):
dbg ("Drag Data Received") dbg ("Drag Data Received")
if selection_data.type == 'text/plain': if selection_data.type == 'text/plain':
@ -319,8 +332,7 @@ text/plain
txt = selection_data.data.strip() txt = selection_data.data.strip()
if txt[0:7] == "file://": if txt[0:7] == "file://":
txt = "'%s'" % txt[7:] txt = "'%s'" % txt[7:]
for term in self.terminator.term_list: for term in self.get_target_terms():
if term == self or term._group != None and term._group == self._group:
term._vte.feed_child(txt) term._vte.feed_child(txt)
return return
@ -679,9 +691,15 @@ text/plain
term.grab_focus () term.grab_focus ()
return False return False
def do_autocleangroups_toggle (self):
self.terminator.autocleangroups = not self.terminator.autocleangroups
def do_scrollbar_toggle (self): def do_scrollbar_toggle (self):
self.toggle_widget_visibility (self._scrollbar) self.toggle_widget_visibility (self._scrollbar)
def do_splittogroup_toggle (self):
self.terminator.splittogroup = not self.terminator.splittogroup
def do_title_toggle (self): def do_title_toggle (self):
self._want_titlebar = not self._titlebox.get_property ('visible') self._want_titlebar = not self._titlebox.get_property ('visible')
self.toggle_widget_visibility (self._titlebox) self.toggle_widget_visibility (self._titlebox)
@ -696,29 +714,21 @@ text/plain
widget.show () widget.show ()
def paste_clipboard(self, primary = False): def paste_clipboard(self, primary = False):
if self._group: for term in self.get_target_terms():
for term in self.terminator.term_list:
if term._group == self._group:
if primary:
term._vte.paste_primary ()
else:
term._vte.paste_clipboard ()
else:
if primary: if primary:
self._vte.paste_primary () term._vte.paste_primary ()
else: else:
self._vte.paste_clipboard () term._vte.paste_clipboard ()
self._vte.grab_focus() self._vte.grab_focus()
def do_enumerate(self, pad=False): def do_enumerate(self, pad=False):
for idx in range(len(self.terminator.term_list)): if pad:
term = self.terminator.term_list[idx] numstr='%0'+str(len(str(len(self.terminator.term_list))))+'d'
if term == self or term._group != None and term._group == self._group: else:
if pad == True: numstr='%d'
numstr = '%0'+str(len(str(len(self.terminator.term_list))))+'d' for term in self.get_target_terms():
else: idx=self.terminator.term_list.index(term)
numstr = '%d' term._vte.feed_child(numstr % (idx+1))
term._vte.feed_child(numstr % (idx+1))
#keybindings for the individual splited terminals (affects only the #keybindings for the individual splited terminals (affects only the
#the selected terminal) #the selected terminal)
@ -734,8 +744,11 @@ text/plain
getattr(self, "key_" + mapping)() getattr(self, "key_" + mapping)()
return True return True
if self._group and self._vte.is_focus (): if self.terminator.groupsend != 0 and self._vte.is_focus ():
self.terminator.group_emit (self, self._group, 'key-press-event', event) if self._group and self.terminator.groupsend == 1:
self.terminator.group_emit (self, self._group, 'key-press-event', event)
if self.terminator.groupsend == 2:
self.terminator.all_emit (self, 'key-press-event', event)
return False return False
# Key events # Key events
@ -1113,6 +1126,10 @@ text/plain
def populate_grouping_menu (self, widget): def populate_grouping_menu (self, widget):
groupitem = None groupitem = None
item = gtk.MenuItem (_("Assign to..."))
item.connect ("activate", self.create_group)
widget.append (item)
if len (self.terminator.groupings) > 0: if len (self.terminator.groupings) > 0:
groupitem = gtk.RadioMenuItem (groupitem, _("None")) groupitem = gtk.RadioMenuItem (groupitem, _("None"))
groupitem.set_active (self._group == None) groupitem.set_active (self._group == None)
@ -1126,24 +1143,63 @@ text/plain
widget.append (item) widget.append (item)
groupitem = item groupitem = item
if self._group != None or len (self.terminator.groupings) > 0:
item = gtk.MenuItem () item = gtk.MenuItem ()
widget.append (item) widget.append (item)
item = gtk.MenuItem (_("_New group"))
item.connect ("activate", self.create_group)
widget.append (item)
item = gtk.MenuItem () if self._group != None:
widget.append (item) item = gtk.MenuItem (_("Ungroup ") + self._group)
item.connect ("activate", self.ungroup, self._group)
item = gtk.MenuItem (_("_Group all")) widget.append (item)
item.connect ("activate", self.group_all)
widget.append (item)
if len (self.terminator.groupings) > 0: if len (self.terminator.groupings) > 0:
item = gtk.MenuItem (_("_Ungroup all")) item = gtk.MenuItem (_("_Ungroup all"))
item.connect ("activate", self.ungroup_all) item.connect ("activate", self.ungroup_all)
widget.append (item) widget.append (item)
if self._group != None:
item = gtk.MenuItem ()
widget.append (item)
item = gtk.ImageMenuItem (_("Close Group"))
grp_close_img = gtk.Image()
grp_close_img.set_from_stock(gtk.STOCK_CLOSE, 1)
item.set_image (grp_close_img)
item.connect ("activate", lambda menu_item: self.terminator.closegroupedterms (self))
widget.append (item)
item = gtk.MenuItem ()
widget.append (item)
groupitem = None
groupitem = gtk.RadioMenuItem (groupitem, _("Broadcast off"))
groupitem.set_active (self.terminator.groupsend == 0)
groupitem.connect ("activate", self.set_groupsend, 0)
widget.append (groupitem)
groupitem = gtk.RadioMenuItem (groupitem, _("Broadcast to group"))
groupitem.set_active (self.terminator.groupsend == 1)
groupitem.connect ("activate", self.set_groupsend, 1)
widget.append (groupitem)
groupitem = gtk.RadioMenuItem (groupitem, _("Broadcast to all"))
groupitem.set_active (self.terminator.groupsend == 2)
groupitem.connect ("activate", self.set_groupsend, 2)
widget.append (groupitem)
item = gtk.MenuItem ()
widget.append (item)
item = gtk.CheckMenuItem (_("Split to this group"))
item.set_active (self.terminator.splittogroup)
item.connect ("toggled", lambda menu_item: self.do_splittogroup_toggle ())
widget.append (item)
item = gtk.CheckMenuItem (_("Autoclean groups"))
item.set_active (self.terminator.autocleangroups)
item.connect ("toggled", lambda menu_item: self.do_autocleangroups_toggle ())
widget.append (item)
def create_group (self, item): def create_group (self, item):
win = gtk.Window () win = gtk.Window ()
@ -1203,12 +1259,13 @@ text/plain
self._titlebox.hide () self._titlebox.hide ()
self.terminator.group_hoover () self.terminator.group_hoover ()
def group_all (self, widget): def set_groupsend (self, item, data):
allname = _("All") self.terminator.groupsend = data
if not allname in self.terminator.groupings:
self.terminator.groupings.append (allname) def ungroup (self, widget, data):
for term in self.terminator.term_list: for term in self.terminator.term_list:
term.set_group (None, allname) if term._group == data:
term.set_group (None, None)
self.terminator.group_hoover () self.terminator.group_hoover ()
def ungroup_all (self, widget): def ungroup_all (self, widget):