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:
Matt Rose 2022-11-20 16:11:25 -05:00 committed by GitHub
commit 13ff8cdcf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -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)

View File

@ -40,6 +40,7 @@ class Terminal(Gtk.VBox):
'close-term': (GObject.SignalFlags.RUN_LAST, None, ()),
'title-change': (GObject.SignalFlags.RUN_LAST, None,
(GObject.TYPE_STRING,)),
'insert-term-name': (GObject.SignalFlags.RUN_LAST, None, ()),
'enumerate': (GObject.SignalFlags.RUN_LAST, None,
(GObject.TYPE_INT,)),
'group-tab': (GObject.SignalFlags.RUN_LAST, None, ()),
@ -128,6 +129,7 @@ class Terminal(Gtk.VBox):
# FIXME: Surely these should happen in Terminator::register_terminal()?
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-out', self.terminator.focus_left)
@ -587,6 +589,10 @@ class Terminal(Gtk.VBox):
item.connect('activate', lambda x: self.emit('enumerate', True))
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)
def set_group(self, _item, name):

View File

@ -584,6 +584,16 @@ class Terminator(Borg):
idx = terminals.index(term)
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):
termset = []
for term in self.terminals: