Skip to content

Commit

Permalink
[New Plugin] Plugin that inserts the name
Browse files Browse the repository at this point in the history
This plugin inserts the name of the terminal, as determined by
Terminal.get_window_title() to all open terminals. Fixes gnome-terminator#540
  • Loading branch information
mattrose committed Dec 2, 2022
1 parent 8ffdd87 commit daf8a97
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions terminatorlib/plugins/insert_term_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from gi.repository import Gtk

import terminatorlib.plugin as plugin
from terminatorlib.terminator import Terminator

AVAILABLE = ['InsertTermName']

class InsertTermName(plugin.MenuItem):
capabilities = ['terminal_menu']
config = None

def __init__(self):
# self.connect_signals()
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)

2 changes: 2 additions & 0 deletions terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ()),
Expand Down Expand Up @@ -128,6 +129,7 @@ def __init__(self):

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

Expand Down
10 changes: 10 additions & 0 deletions terminatorlib/terminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,16 @@ def do_enumerate(self, widget, pad):
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:
Expand Down

0 comments on commit daf8a97

Please sign in to comment.