Merge pull request #691 from nicbn/patch-1

Ctrl+Click on group button automatically creates groups whenever needed
This commit is contained in:
Matt Rose 2023-03-01 16:23:33 -05:00 committed by GitHub
commit 45a8b4c75c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View File

@ -887,7 +887,13 @@ class Terminal(Gtk.VBox):
focused=self.get_toplevel().get_focussed_terminal()
if focused in targets: targets.remove(focused)
if self != focused:
if self.group == focused.group:
if focused.group is None and self.group is None:
# Create a new group and assign currently focused
# terminal to this group
new_group = self.terminator.new_random_group()
focused.set_group(None, new_group)
focused.titlebar.update()
elif self.group == focused.group:
new_group = None
else:
new_group = focused.group

View File

@ -8,6 +8,8 @@ import gi
gi.require_version('Vte', '2.91')
from gi.repository import Gtk, Gdk, Vte
from gi.repository.GLib import GError
import itertools
import random
from . import borg
from .borg import Borg
@ -16,6 +18,7 @@ from .keybindings import Keybindings
from .util import dbg, err, enumerate_descendants
from .factory import Factory
from .version import APP_NAME, APP_VERSION
from .translation import _
try:
from gi.repository import GdkX11
@ -647,4 +650,18 @@ class Terminator(Borg):
def zoom_orig_all(self):
for term in self.terminals:
term.zoom_orig()
def new_random_group(self):
defaultmembers=[_('Alpha'),_('Beta'),_('Gamma'),_('Delta'),_('Epsilon'),_('Zeta'),_('Eta'),
_('Theta'),_('Iota'),_('Kappa'),_('Lambda'),_('Mu'),_('Nu'),_('Xi'),
_('Omicron'),_('Pi'),_('Rho'),_('Sigma'),_('Tau'),_('Upsilon'),_('Phi'),
_('Chi'),_('Psi'),_('Omega')]
currentgroups=set(self.groups)
for i in range(1,4):
defaultgroups=set(map(''.join, list(itertools.product(defaultmembers,repeat=i))))
freegroups = list(defaultgroups-currentgroups)
if freegroups:
return random.choice(freegroups)
return ''
# vim: set expandtab ts=4 sw=4:

View File

@ -5,8 +5,6 @@
from gi.repository import Gtk, Gdk
from gi.repository import GObject
from gi.repository import Pango
import random
import itertools
from .version import APP_NAME
from .util import dbg
@ -255,19 +253,7 @@ class Titlebar(Gtk.EventBox):
if self.terminal.group:
self.groupentry.set_text(self.terminal.group)
else:
defaultmembers=[_('Alpha'),_('Beta'),_('Gamma'),_('Delta'),_('Epsilon'),_('Zeta'),_('Eta'),
_('Theta'),_('Iota'),_('Kappa'),_('Lambda'),_('Mu'),_('Nu'),_('Xi'),
_('Omicron'),_('Pi'),_('Rho'),_('Sigma'),_('Tau'),_('Upsilon'),_('Phi'),
_('Chi'),_('Psi'),_('Omega')]
currentgroups=set(self.terminator.groups)
for i in range(1,4):
defaultgroups=set(map(''.join, list(itertools.product(defaultmembers,repeat=i))))
freegroups = list(defaultgroups-currentgroups)
if freegroups:
self.groupentry.set_text(random.choice(freegroups))
break
else:
self.groupentry.set_text('')
self.groupentry.set_text(self.terminator.new_random_group())
self.groupentry.show()
self.grouplabel.hide()
self.groupentry.grab_focus()