1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-22 11:52:03 +03:00

Feat#10008: add hotkeys to open profile selectors for a specific group (#10015)

This commit is contained in:
Clem 2024-10-20 21:31:09 +02:00 committed by GitHub
parent aab7e285a9
commit 2ecccad2db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 8 deletions

View File

@ -31,6 +31,8 @@ hotkeys:
__nonStructural: true
profile-selectors:
__nonStructural: true
group-selectors:
__nonStructural: true
profiles: []
groups: []
profileDefaults:

View File

@ -264,6 +264,7 @@ export class AppHotkeyProvider extends HotkeyProvider {
async provide (): Promise<HotkeyDescription[]> {
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 }),
})),
]
}

View File

@ -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<ProfileGroup>): Promise<void> {
if (this.selector.active) {
return
}
const profiles = group.profiles ?? []
const options: SelectorOption<void>[] = 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<AppModule> {
return {
ngModule: AppModule,

View File

@ -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
}
}
/**