Merge pull request #683 from mattrose/insert-term-name-plugin
Plugin and Group menu item that inserts the name of the terminal.
This commit is contained in:
commit
13ff8cdcf5
|
@ -0,0 +1,18 @@
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
import terminatorlib.plugin as plugin
|
||||||
|
|
||||||
|
AVAILABLE = ['InsertTermName']
|
||||||
|
|
||||||
|
class InsertTermName(plugin.MenuItem):
|
||||||
|
capabilities = ['terminal_menu']
|
||||||
|
config = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
plugin.MenuItem.__init__(self)
|
||||||
|
|
||||||
|
def callback(self, menuitems, menu, terminal):
|
||||||
|
item = Gtk.MenuItem.new_with_label('Insert terminal name')
|
||||||
|
item.connect('activate', lambda x: terminal.emit('insert-term-name'))
|
||||||
|
menuitems.append(item)
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Terminal(Gtk.VBox):
|
||||||
'close-term': (GObject.SignalFlags.RUN_LAST, None, ()),
|
'close-term': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||||
'title-change': (GObject.SignalFlags.RUN_LAST, None,
|
'title-change': (GObject.SignalFlags.RUN_LAST, None,
|
||||||
(GObject.TYPE_STRING,)),
|
(GObject.TYPE_STRING,)),
|
||||||
|
'insert-term-name': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||||
'enumerate': (GObject.SignalFlags.RUN_LAST, None,
|
'enumerate': (GObject.SignalFlags.RUN_LAST, None,
|
||||||
(GObject.TYPE_INT,)),
|
(GObject.TYPE_INT,)),
|
||||||
'group-tab': (GObject.SignalFlags.RUN_LAST, None, ()),
|
'group-tab': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||||
|
@ -128,6 +129,7 @@ class Terminal(Gtk.VBox):
|
||||||
|
|
||||||
# FIXME: Surely these should happen in Terminator::register_terminal()?
|
# FIXME: Surely these should happen in Terminator::register_terminal()?
|
||||||
self.connect('enumerate', self.terminator.do_enumerate)
|
self.connect('enumerate', self.terminator.do_enumerate)
|
||||||
|
self.connect('insert-term-name', self.terminator.do_insert_term_name)
|
||||||
self.connect('focus-in', self.terminator.focus_changed)
|
self.connect('focus-in', self.terminator.focus_changed)
|
||||||
self.connect('focus-out', self.terminator.focus_left)
|
self.connect('focus-out', self.terminator.focus_left)
|
||||||
|
|
||||||
|
@ -587,6 +589,10 @@ class Terminal(Gtk.VBox):
|
||||||
item.connect('activate', lambda x: self.emit('enumerate', True))
|
item.connect('activate', lambda x: self.emit('enumerate', True))
|
||||||
menu.append(item)
|
menu.append(item)
|
||||||
|
|
||||||
|
item = Gtk.MenuItem.new_with_mnemonic(_('Insert terminal _name'))
|
||||||
|
item.connect('activate', lambda x: self.emit('insert-term-name'))
|
||||||
|
menu.append(item)
|
||||||
|
|
||||||
return(menu)
|
return(menu)
|
||||||
|
|
||||||
def set_group(self, _item, name):
|
def set_group(self, _item, name):
|
||||||
|
|
|
@ -584,6 +584,16 @@ class Terminator(Borg):
|
||||||
idx = terminals.index(term)
|
idx = terminals.index(term)
|
||||||
term.feed(numstr.encode() % (idx + 1))
|
term.feed(numstr.encode() % (idx + 1))
|
||||||
|
|
||||||
|
def do_insert_term_name(self, widget):
|
||||||
|
terminals = []
|
||||||
|
for window in self.windows:
|
||||||
|
containers, win_terminals = enumerate_descendants(window)
|
||||||
|
terminals.extend(win_terminals)
|
||||||
|
|
||||||
|
for term in self.get_target_terms(widget):
|
||||||
|
name = term.titlebar.get_custom_string() or term.get_window_title()
|
||||||
|
term.feed(name)
|
||||||
|
|
||||||
def get_sibling_terms(self, widget):
|
def get_sibling_terms(self, widget):
|
||||||
termset = []
|
termset = []
|
||||||
for term in self.terminals:
|
for term in self.terminals:
|
||||||
|
|
Loading…
Reference in New Issue