added generic hotkeys for profile selectors by type

This commit is contained in:
Eugene Pankov
2021-08-22 20:59:50 +02:00
parent 7120e32c91
commit 59101cfcb3
9 changed files with 48 additions and 104 deletions

View File

@@ -20,6 +20,8 @@ terminal:
hotkeys:
profile:
__nonStructural: true
profile-selectors:
__nonStructural: true
profiles: []
profileDefaults:
__nonStructural: true

View File

@@ -197,6 +197,10 @@ export class AppHotkeyProvider extends HotkeyProvider {
id: `profile.${AppHotkeyProvider.getProfileHotkeyName(profile)}`,
name: `New tab: ${profile.name}`,
})),
...this.profilesService.getProviders().map(provider => ({
id: `profile-selectors.${provider.id}`,
name: `Show ${provider.name} profile selector`,
})),
]
}

View File

@@ -34,7 +34,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, ToolbarButtonProvider, ProfilesService, ProfileProvider } from './api'
import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider, ToolbarButtonProvider, ProfilesService, ProfileProvider, SelectorOption, Profile, SelectorService } from './api'
import { AppService } from './services/app.service'
import { ConfigService } from './services/config.service'
@@ -135,7 +135,8 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
config: ConfigService,
platform: PlatformService,
hotkeys: HotkeysService,
profilesService: ProfilesService,
private profilesService: ProfilesService,
private selector: SelectorService,
) {
app.ready$.subscribe(() => {
config.ready$.toPromise().then(() => {
@@ -158,9 +159,44 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
profilesService.openNewTabForProfile(profile)
}
}
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)
}
})
}
async showSelector (provider: ProfileProvider<Profile>): Promise<void> {
let profiles = await this.profilesService.getProfiles()
profiles = profiles.filter(x => !x.isTemplate && x.type === provider.id)
const options: SelectorOption<void>[] = profiles.map(p => ({
...this.profilesService.selectorOptionForProfile(p),
callback: () => this.profilesService.openNewTabForProfile(p),
}))
if (provider.supportsQuickConnect) {
options.push({
name: 'Quick connect',
freeInputPattern: 'Connect to "%s"...',
icon: 'fas fa-arrow-right',
callback: query => {
const p = provider.quickConnect(query)
if (p) {
this.profilesService.openNewTabForProfile(p)
}
},
})
}
await this.selector.show('Select profile', options)
}
static forRoot (): ModuleWithProviders<AppModule> {
return {
ngModule: AppModule,