diff --git a/tabby-core/src/configDefaults.yaml b/tabby-core/src/configDefaults.yaml index 096fa942..20a654ee 100644 --- a/tabby-core/src/configDefaults.yaml +++ b/tabby-core/src/configDefaults.yaml @@ -31,6 +31,8 @@ hotkeys: __nonStructural: true profile-selectors: __nonStructural: true + group-selectors: + __nonStructural: true profiles: [] groups: [] profileDefaults: diff --git a/tabby-core/src/hotkeys.ts b/tabby-core/src/hotkeys.ts index d4465a36..d9b71015 100644 --- a/tabby-core/src/hotkeys.ts +++ b/tabby-core/src/hotkeys.ts @@ -264,6 +264,7 @@ export class AppHotkeyProvider extends HotkeyProvider { async provide (): Promise { const profiles = await this.profilesService.getProfiles() + const groups = await this.profilesService.getProfileGroups() return [ ...this.hotkeys, ...profiles.map(profile => ({ @@ -274,6 +275,10 @@ export class AppHotkeyProvider extends HotkeyProvider { id: `profile-selectors.${provider.id}`, name: this.translate.instant('Show {type} profile selector', { type: provider.name }), })), + ...groups.map(group => ({ + id: `group-selectors.${group.id}`, + name: this.translate.instant('Show profile selector for group {name}', { name: group.name }), + })), ] } diff --git a/tabby-core/src/index.ts b/tabby-core/src/index.ts index 33b41d54..25955e67 100644 --- a/tabby-core/src/index.ts +++ b/tabby-core/src/index.ts @@ -37,7 +37,7 @@ import { FastHtmlBindDirective } from './directives/fastHtmlBind.directive' import { DropZoneDirective } from './directives/dropZone.directive' import { CdkAutoDropGroup } from './directives/cdkAutoDropGroup.directive' -import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider, ProfilesService, ProfileProvider, QuickConnectProfileProvider, SelectorOption, Profile, SelectorService, CommandProvider } from './api' +import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider, ProfilesService, ProfileProvider, QuickConnectProfileProvider, SelectorOption, Profile, SelectorService, CommandProvider, PartialProfileGroup, ProfileGroup } from './api' import { AppService } from './services/app.service' import { ConfigService } from './services/config.service' @@ -181,20 +181,24 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex if (profile) { profilesService.openNewTabForProfile(profile) } - } - if (hotkey.startsWith('profile-selectors.')) { + } else if (hotkey.startsWith('profile-selectors.')) { const id = hotkey.substring(hotkey.indexOf('.') + 1) const provider = profilesService.getProviders().find(x => x.id === id) if (!provider) { return } this.showSelector(provider).catch(() => null) - } - if (hotkey === 'command-selector') { + } else if (hotkey.startsWith('group-selectors.')) { + const id = hotkey.substring(hotkey.indexOf('.') + 1) + const groups = await this.profilesService.getProfileGroups({ includeProfiles: true }) + const group = groups.find(x => x.id === id) + if (!group) { + return + } + this.showGroupSelector(group).catch(() => null) + } else if (hotkey === 'command-selector') { commands.showSelector().catch(() => null) - } - - if (hotkey === 'profile-selector') { + } else if (hotkey === 'profile-selector') { commands.run('core:profile-selector', {}) } }) @@ -232,6 +236,21 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex await this.selector.show(this.translate.instant('Select profile'), options) } + async showGroupSelector (group: PartialProfileGroup): Promise { + if (this.selector.active) { + return + } + + const profiles = group.profiles ?? [] + + const options: SelectorOption[] = profiles.map(p => ({ + ...this.profilesService.selectorOptionForProfile(p), + callback: () => this.profilesService.openNewTabForProfile(p), + })) + + await this.selector.show(this.translate.instant('Select profile'), options) + } + static forRoot (): ModuleWithProviders { return { ngModule: AppModule, diff --git a/tabby-core/src/services/profiles.service.ts b/tabby-core/src/services/profiles.service.ts index 7106ca67..18522ee5 100644 --- a/tabby-core/src/services/profiles.service.ts +++ b/tabby-core/src/services/profiles.service.ts @@ -487,6 +487,12 @@ export class ProfilesService { delete profile.group } } + if (this.config.store.hotkeys['group-selectors'].hasOwnProperty(group.id)) { + const groupSelectorsHotkeys = { ...this.config.store.hotkeys['group-selectors'] } + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete + delete groupSelectorsHotkeys[group.id] + this.config.store.hotkeys['group-selectors'] = groupSelectorsHotkeys + } } /**