hook up the terminal enumeration menu items

This commit is contained in:
Chris Jones 2009-09-04 22:48:35 +01:00
parent 2a65918209
commit bb073887fc
2 changed files with 40 additions and 7 deletions

View File

@ -68,4 +68,29 @@ class Terminator(Borg):
for group in todestroy: for group in todestroy:
self.groups.remove(group) self.groups.remove(group)
def do_enumerate(self, widget, pad):
"""Insert the number of each terminal in a group, into that terminal"""
if pad:
numstr='%0'+str(len(str(len(self.terminals))))+'d'
else:
numstr='%d'
for term in self.get_target_terms(widget):
idx = self.terminals.index(term)
term.feed(numstr % (idx + 1))
def get_target_terms(self, widget):
"""Get the terminals we should currently be broadcasting to"""
if self.groupsend == self.groupsend_type['all']:
return(self.terminals)
elif self.groupsend == self.groupsend_type['group']:
set = []
for term in self.terminals:
if term == widget or (term.group != None and term.group ==
widget.group):
set.append(term)
return(set)
else:
return([widget])
# vim: set expandtab ts=4 sw=4: # vim: set expandtab ts=4 sw=4:

View File

@ -33,6 +33,8 @@ class Terminal(gtk.VBox):
'close-term': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'close-term': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
'title-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, 'title-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_STRING,)), (gobject.TYPE_STRING,)),
'enumerate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_INT,)),
} }
TARGET_TYPE_VTE = 8 TARGET_TYPE_VTE = 8
@ -60,6 +62,8 @@ class Terminal(gtk.VBox):
self.__gobject_init__() self.__gobject_init__()
self.terminator = Terminator() self.terminator = Terminator()
self.connect('enumerate', self.terminator.do_enumerate)
self.matches = {} self.matches = {}
self.config = Config() self.config = Config()
@ -318,11 +322,11 @@ class Terminal(gtk.VBox):
menu.append(gtk.MenuItem()) menu.append(gtk.MenuItem())
item = gtk.MenuItem(_('Insert terminal number')) item = gtk.MenuItem(_('Insert terminal number'))
item.connect('activate', lambda menu_item: self.do_enumerate()) item.connect('activate', lambda menu_item: self.emit('enumerate', False))
menu.append(item) menu.append(item)
item = gtk.MenuItem(_('Insert padded terminal number')) item = gtk.MenuItem(_('Insert padded terminal number'))
item.connect('activate', lambda menu_item: self.do_enumerate(pad=True)) item.connect('activate', lambda menu_item: self.emit('enumerate', True))
menu.append(item) menu.append(item)
return(menu) return(menu)
@ -581,12 +585,16 @@ class Terminal(gtk.VBox):
def paste_clipboard(self, primary=False): def paste_clipboard(self, primary=False):
"""Paste one of the two clipboards""" """Paste one of the two clipboards"""
# FIXME: Make this work across a group for term in self.terminator.get_target_terms():
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 feed(self, text):
"""Feed the supplied text to VTE"""
self.vte.feed_child(text)
gobject.type_register(Terminal) gobject.type_register(Terminal)
# vim: set expandtab ts=4 sw=4: # vim: set expandtab ts=4 sw=4: