From 59101cfcb34505cb2a1e46e894a9f53221601a37 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 22 Aug 2021 20:59:50 +0200 Subject: [PATCH] added generic hotkeys for profile selectors by type --- tabby-core/src/configDefaults.yaml | 2 ++ tabby-core/src/hotkeys.ts | 4 +++ tabby-core/src/index.ts | 40 +++++++++++++++++++++++-- tabby-ssh/src/config.ts | 1 - tabby-ssh/src/hotkeys.ts | 4 --- tabby-ssh/src/index.ts | 48 ++---------------------------- tabby-telnet/src/config.ts | 1 - tabby-telnet/src/hotkeys.ts | 4 --- tabby-telnet/src/index.ts | 48 ++---------------------------- 9 files changed, 48 insertions(+), 104 deletions(-) diff --git a/tabby-core/src/configDefaults.yaml b/tabby-core/src/configDefaults.yaml index bc2ccdcf..3819b9dd 100644 --- a/tabby-core/src/configDefaults.yaml +++ b/tabby-core/src/configDefaults.yaml @@ -20,6 +20,8 @@ terminal: hotkeys: profile: __nonStructural: true + profile-selectors: + __nonStructural: true profiles: [] profileDefaults: __nonStructural: true diff --git a/tabby-core/src/hotkeys.ts b/tabby-core/src/hotkeys.ts index 42562936..28ce7b83 100644 --- a/tabby-core/src/hotkeys.ts +++ b/tabby-core/src/hotkeys.ts @@ -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`, + })), ] } diff --git a/tabby-core/src/index.ts b/tabby-core/src/index.ts index 296eb8f8..e2926acb 100644 --- a/tabby-core/src/index.ts +++ b/tabby-core/src/index.ts @@ -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): Promise { + let profiles = await this.profilesService.getProfiles() + + profiles = profiles.filter(x => !x.isTemplate && x.type === provider.id) + + const options: SelectorOption[] = 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 { return { ngModule: AppModule, diff --git a/tabby-ssh/src/config.ts b/tabby-ssh/src/config.ts index 468e5d34..eea5b1e9 100644 --- a/tabby-ssh/src/config.ts +++ b/tabby-ssh/src/config.ts @@ -10,7 +10,6 @@ export class SSHConfigProvider extends ConfigProvider { agentPath: null, }, hotkeys: { - 'ssh-profile-selector': [], 'restart-ssh-session': [], 'launch-winscp': [], }, diff --git a/tabby-ssh/src/hotkeys.ts b/tabby-ssh/src/hotkeys.ts index 96e538bc..658d06c3 100644 --- a/tabby-ssh/src/hotkeys.ts +++ b/tabby-ssh/src/hotkeys.ts @@ -5,10 +5,6 @@ import { HotkeyDescription, HotkeyProvider } from 'tabby-core' @Injectable() export class SSHHotkeyProvider extends HotkeyProvider { hotkeys: HotkeyDescription[] = [ - { - id: 'ssh-profile-selector', - name: 'Show SSH profile selector', - }, { id: 'restart-ssh-session', name: 'Restart current SSH session', diff --git a/tabby-ssh/src/index.ts b/tabby-ssh/src/index.ts index d57ebc7c..b945b7c0 100644 --- a/tabby-ssh/src/index.ts +++ b/tabby-ssh/src/index.ts @@ -62,52 +62,8 @@ import { CommonSFTPContextMenu } from './sftpContextMenu' SFTPPanelComponent, ], }) -export default class SSHModule { - constructor ( - hotkeys: HotkeysService, - private app: AppService, - private selector: SelectorService, - private profilesService: ProfilesService, - private sshProfiles: SSHProfilesService, - ) { - hotkeys.hotkey$.subscribe(hotkey => { - if (hotkey === 'ssh-profile-selector') { - this.showSelector() - } - }) - } - - async showSelector (): Promise { - let profiles = await this.profilesService.getProfiles() - - profiles = profiles.filter(x => !x.isTemplate && x.type === 'ssh') - - const options: SelectorOption[] = profiles.map(p => ({ - ...this.profilesService.selectorOptionForProfile(p), - callback: () => this.profilesService.openNewTabForProfile(p), - })) - - options.push({ - name: 'Manage profiles', - icon: 'fas fa-window-restore', - callback: () => this.app.openNewTabRaw({ - type: SettingsTabComponent, - inputs: { activeTab: 'profiles' }, - }), - }) - - options.push({ - name: 'Quick connect', - freeInputPattern: 'Connect to "%s"...', - icon: 'fas fa-arrow-right', - callback: query => this.profilesService.openNewTabForProfile( - this.sshProfiles.quickConnect(query) - ), - }) - - await this.selector.show('Select an SSH profile', options) - } -} +// eslint-disable-next-line @typescript-eslint/no-extraneous-class +export default class SSHModule { } export * from './api' export { SFTPFile, SFTPSession } from './session/sftp' diff --git a/tabby-telnet/src/config.ts b/tabby-telnet/src/config.ts index 26293834..6931a786 100644 --- a/tabby-telnet/src/config.ts +++ b/tabby-telnet/src/config.ts @@ -4,7 +4,6 @@ import { ConfigProvider } from 'tabby-core' export class TelnetConfigProvider extends ConfigProvider { defaults = { hotkeys: { - 'telnet-profile-selector': [], 'restart-telnet-session': [], }, } diff --git a/tabby-telnet/src/hotkeys.ts b/tabby-telnet/src/hotkeys.ts index 9898dc88..9e2bb6be 100644 --- a/tabby-telnet/src/hotkeys.ts +++ b/tabby-telnet/src/hotkeys.ts @@ -5,10 +5,6 @@ import { HotkeyDescription, HotkeyProvider } from 'tabby-core' @Injectable() export class TelnetHotkeyProvider extends HotkeyProvider { hotkeys: HotkeyDescription[] = [ - { - id: 'telnet-profile-selector', - name: 'Show Telnet profile selector', - }, { id: 'restart-telnet-session', name: 'Restart current Telnet session', diff --git a/tabby-telnet/src/index.ts b/tabby-telnet/src/index.ts index 1e970de1..a9c194eb 100644 --- a/tabby-telnet/src/index.ts +++ b/tabby-telnet/src/index.ts @@ -42,49 +42,5 @@ import { TelnetProfilesService } from './profiles' TelnetTabComponent, ], }) -export default class TelnetModule { - constructor ( - hotkeys: HotkeysService, - private app: AppService, - private selector: SelectorService, - private profilesService: ProfilesService, - private telnetProfiles: TelnetProfilesService, - ) { - hotkeys.hotkey$.subscribe(hotkey => { - if (hotkey === 'telnet-profile-selector') { - this.showSelector() - } - }) - } - - async showSelector (): Promise { - let profiles = await this.profilesService.getProfiles() - - profiles = profiles.filter(x => !x.isTemplate && x.type === 'telnet') - - const options: SelectorOption[] = profiles.map(p => ({ - ...this.profilesService.selectorOptionForProfile(p), - callback: () => this.profilesService.openNewTabForProfile(p), - })) - - options.push({ - name: 'Manage profiles', - icon: 'fas fa-window-restore', - callback: () => this.app.openNewTabRaw({ - type: SettingsTabComponent, - inputs: { activeTab: 'profiles' }, - }), - }) - - options.push({ - name: 'Quick connect', - freeInputPattern: 'Connect to "%s"...', - icon: 'fas fa-arrow-right', - callback: query => this.profilesService.openNewTabForProfile( - this.telnetProfiles.quickConnect(query) - ), - }) - - await this.selector.show('Select an Telnet profile', options) - } -} +// eslint-disable-next-line @typescript-eslint/no-extraneous-class +export default class TelnetModule { }