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:
parent
aab7e285a9
commit
2ecccad2db
@ -31,6 +31,8 @@ hotkeys:
|
|||||||
__nonStructural: true
|
__nonStructural: true
|
||||||
profile-selectors:
|
profile-selectors:
|
||||||
__nonStructural: true
|
__nonStructural: true
|
||||||
|
group-selectors:
|
||||||
|
__nonStructural: true
|
||||||
profiles: []
|
profiles: []
|
||||||
groups: []
|
groups: []
|
||||||
profileDefaults:
|
profileDefaults:
|
||||||
|
@ -264,6 +264,7 @@ export class AppHotkeyProvider extends HotkeyProvider {
|
|||||||
|
|
||||||
async provide (): Promise<HotkeyDescription[]> {
|
async provide (): Promise<HotkeyDescription[]> {
|
||||||
const profiles = await this.profilesService.getProfiles()
|
const profiles = await this.profilesService.getProfiles()
|
||||||
|
const groups = await this.profilesService.getProfileGroups()
|
||||||
return [
|
return [
|
||||||
...this.hotkeys,
|
...this.hotkeys,
|
||||||
...profiles.map(profile => ({
|
...profiles.map(profile => ({
|
||||||
@ -274,6 +275,10 @@ export class AppHotkeyProvider extends HotkeyProvider {
|
|||||||
id: `profile-selectors.${provider.id}`,
|
id: `profile-selectors.${provider.id}`,
|
||||||
name: this.translate.instant('Show {type} profile selector', { type: provider.name }),
|
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 }),
|
||||||
|
})),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ import { FastHtmlBindDirective } from './directives/fastHtmlBind.directive'
|
|||||||
import { DropZoneDirective } from './directives/dropZone.directive'
|
import { DropZoneDirective } from './directives/dropZone.directive'
|
||||||
import { CdkAutoDropGroup } from './directives/cdkAutoDropGroup.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 { AppService } from './services/app.service'
|
||||||
import { ConfigService } from './services/config.service'
|
import { ConfigService } from './services/config.service'
|
||||||
@ -181,20 +181,24 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
|
|||||||
if (profile) {
|
if (profile) {
|
||||||
profilesService.openNewTabForProfile(profile)
|
profilesService.openNewTabForProfile(profile)
|
||||||
}
|
}
|
||||||
}
|
} else if (hotkey.startsWith('profile-selectors.')) {
|
||||||
if (hotkey.startsWith('profile-selectors.')) {
|
|
||||||
const id = hotkey.substring(hotkey.indexOf('.') + 1)
|
const id = hotkey.substring(hotkey.indexOf('.') + 1)
|
||||||
const provider = profilesService.getProviders().find(x => x.id === id)
|
const provider = profilesService.getProviders().find(x => x.id === id)
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.showSelector(provider).catch(() => null)
|
this.showSelector(provider).catch(() => null)
|
||||||
}
|
} else if (hotkey.startsWith('group-selectors.')) {
|
||||||
if (hotkey === 'command-selector') {
|
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)
|
commands.showSelector().catch(() => null)
|
||||||
}
|
} else if (hotkey === 'profile-selector') {
|
||||||
|
|
||||||
if (hotkey === 'profile-selector') {
|
|
||||||
commands.run('core: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)
|
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> {
|
static forRoot (): ModuleWithProviders<AppModule> {
|
||||||
return {
|
return {
|
||||||
ngModule: AppModule,
|
ngModule: AppModule,
|
||||||
|
@ -487,6 +487,12 @@ export class ProfilesService {
|
|||||||
delete profile.group
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user