Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl+Click on group button automatically creates groups whenever needed #691

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,13 @@ def on_group_button_press(self, widget, event):
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
Expand Down
17 changes: 17 additions & 0 deletions terminatorlib/terminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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
Expand All @@ -16,6 +18,7 @@
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
Expand Down Expand Up @@ -638,4 +641,18 @@ def zoom_out_all(self):
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:
16 changes: 1 addition & 15 deletions terminatorlib/titlebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -255,19 +253,7 @@ def create_group(self):
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()
Expand Down