1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-23 02:22:02 +03:00

deprecated matchedHotkey

This commit is contained in:
Eugene Pankov 2021-07-05 22:52:32 +02:00
parent da599567f8
commit 461cd2bec7
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
21 changed files with 141 additions and 32 deletions

View File

@ -7,10 +7,10 @@ import { HostAppService, Platform } from './api/hostApp'
import { Profile } from './api/profileProvider' import { Profile } from './api/profileProvider'
import { ConfigService } from './services/config.service' import { ConfigService } from './services/config.service'
import { SelectorOption } from './api/selector' import { SelectorOption } from './api/selector'
import { HotkeysService } from './services/hotkeys.service'
import { ProfilesService } from './services/profiles.service' import { ProfilesService } from './services/profiles.service'
import { AppService } from './services/app.service' import { AppService } from './services/app.service'
import { NotificationsService } from './services/notifications.service' import { NotificationsService } from './services/notifications.service'
import { HotkeysService } from 'api'
/** @hidden */ /** @hidden */
@Injectable() @Injectable()
@ -35,12 +35,14 @@ export class ButtonProvider extends ToolbarButtonProvider {
async activate () { async activate () {
const recentProfiles: Profile[] = this.config.store.recentProfiles const recentProfiles: Profile[] = this.config.store.recentProfiles
const getProfileOptions = (profile): SelectorOption<void> => ({ const getProfileOptions = (profile): SelectorOption<void> => {
icon: recentProfiles.includes(profile) ? 'fas fa-history' : profile.icon, const result: SelectorOption<void> = this.profilesServices.selectorOptionForProfile(profile)
name: profile.group ? `${profile.group} / ${profile.name}` : profile.name, if (recentProfiles.includes(profile)) {
description: this.profilesServices.providerForProfile(profile)?.getDescription(profile), result.icon = 'fas fa-history'
callback: () => this.launchProfile(profile), }
}) result.callback = () => this.launchProfile(profile)
return result
}
let options = recentProfiles.map(getProfileOptions) let options = recentProfiles.map(getProfileOptions)
if (recentProfiles.length) { if (recentProfiles.length) {

View File

@ -80,7 +80,7 @@ export class AppRootComponent {
this.logger = log.create('main') this.logger = log.create('main')
this.logger.info('v', platform.getAppVersion()) this.logger.info('v', platform.getAppVersion())
this.hotkeys.matchedHotkey.subscribe((hotkey: string) => { this.hotkeys.hotkey$.subscribe((hotkey: string) => {
if (hotkey.startsWith('tab-')) { if (hotkey.startsWith('tab-')) {
const index = parseInt(hotkey.split('-')[1]) const index = parseInt(hotkey.split('-')[1])
if (index <= this.app.tabs.length) { if (index <= this.app.tabs.length) {

View File

@ -209,7 +209,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
}) })
this.blurred$.subscribe(() => this.getAllTabs().forEach(x => x.emitBlurred())) this.blurred$.subscribe(() => this.getAllTabs().forEach(x => x.emitBlurred()))
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (!this.hasFocus || !this.focusedTab) { if (!this.hasFocus || !this.focusedTab) {
return return
} }

View File

@ -43,7 +43,7 @@ export class TabHeaderComponent extends BaseComponent {
@Optional() @Inject(TabContextMenuItemProvider) protected contextMenuProviders: TabContextMenuItemProvider[], @Optional() @Inject(TabContextMenuItemProvider) protected contextMenuProviders: TabContextMenuItemProvider[],
) { ) {
super() super()
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, (hotkey) => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, (hotkey) => {
if (this.app.activeTab === this.tab) { if (this.app.activeTab === this.tab) {
if (hotkey === 'rename-tab') { if (hotkey === 'rename-tab') {
this.showRenameTabModal() this.showRenameTabModal()

View File

@ -135,7 +135,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
console.error('Unhandled exception:', err) console.error('Unhandled exception:', err)
}) })
hotkeys.matchedHotkey.subscribe(async (hotkey) => { hotkeys.hotkey$.subscribe(async (hotkey) => {
if (hotkey.startsWith('profile.')) { if (hotkey.startsWith('profile.')) {
const id = hotkey.split('.')[1] const id = hotkey.split('.')[1]
const profile = (await profilesService.getProfiles()).find(x => x.id === id) const profile = (await profilesService.getProfiles()).find(x => x.id === id)

View File

@ -3,6 +3,7 @@ import { Observable, Subject } from 'rxjs'
import { HotkeyDescription, HotkeyProvider } from '../api/hotkeyProvider' import { HotkeyDescription, HotkeyProvider } from '../api/hotkeyProvider'
import { stringifyKeySequence, EventData } from './hotkeys.util' import { stringifyKeySequence, EventData } from './hotkeys.util'
import { ConfigService } from './config.service' import { ConfigService } from './config.service'
import { deprecate } from 'util'
export interface PartialHotkeyMatch { export interface PartialHotkeyMatch {
id: string id: string
@ -53,6 +54,7 @@ export class HotkeysService {
// deprecated // deprecated
this.hotkey$.subscribe(h => this.matchedHotkey.emit(h)) this.hotkey$.subscribe(h => this.matchedHotkey.emit(h))
this.matchedHotkey.subscribe = deprecate(this.matchedHotkey.subscribe, 'matchedHotkey is deprecated, use hotkey$')
} }
/** /**

View File

@ -2,6 +2,7 @@ import { Injectable, Inject } from '@angular/core'
import { NewTabParameters } from './tabs.service' import { NewTabParameters } from './tabs.service'
import { BaseTabComponent } from '../components/baseTab.component' import { BaseTabComponent } from '../components/baseTab.component'
import { Profile, ProfileProvider } from '../api/profileProvider' import { Profile, ProfileProvider } from '../api/profileProvider'
import { SelectorOption } from '../api/selector'
import { AppService } from './app.service' import { AppService } from './app.service'
import { ConfigService } from './config.service' import { ConfigService } from './config.service'
@ -51,4 +52,12 @@ export class ProfilesService {
providerForProfile (profile: Profile): ProfileProvider|null { providerForProfile (profile: Profile): ProfileProvider|null {
return this.profileProviders.find(x => x.id === profile.type) ?? null return this.profileProviders.find(x => x.id === profile.type) ?? null
} }
selectorOptionForProfile <T> (profile: Profile): SelectorOption<T> {
return {
icon: profile.icon,
name: profile.group ? `${profile.group} / ${profile.name}` : profile.name,
description: this.providerForProfile(profile)?.getDescription(profile),
}
}
} }

View File

@ -30,7 +30,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
const isConPTY = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) && this.config.store.terminal.useConPTY const isConPTY = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) && this.config.store.terminal.useConPTY
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (!this.hasFocus) { if (!this.hasFocus) {
return return
} }

View File

@ -116,7 +116,7 @@ export default class LocalTerminalModule { // eslint-disable-line @typescript-es
dockMenu: DockMenuService, dockMenu: DockMenuService,
config: ConfigService, config: ConfigService,
) { ) {
hotkeys.matchedHotkey.subscribe(async (hotkey) => { hotkeys.hotkey$.subscribe(async (hotkey) => {
if (hotkey === 'new-tab') { if (hotkey === 'new-tab') {
terminal.openTab() terminal.openTab()
} }

View File

@ -29,7 +29,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
ngOnInit () { ngOnInit () {
this.logger = this.log.create('terminalTab') this.logger = this.log.create('terminalTab')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (!this.hasFocus) { if (!this.hasFocus) {
return return
} }

View File

@ -14,7 +14,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
super() super()
hostApp.settingsUIRequest$.subscribe(() => this.open()) hostApp.settingsUIRequest$.subscribe(() => this.open())
hotkeys.matchedHotkey.subscribe(async (hotkey) => { hotkeys.hotkey$.subscribe(async (hotkey) => {
if (hotkey === 'settings') { if (hotkey === 'settings') {
this.open() this.open()
} }

View File

@ -41,7 +41,7 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
this.logger = this.log.create('terminalTab') this.logger = this.log.create('terminalTab')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (!this.hasFocus) { if (!this.hasFocus) {
return return
} }

View File

@ -10,6 +10,7 @@ export class SSHConfigProvider extends ConfigProvider {
agentPath: null, agentPath: null,
}, },
hotkeys: { hotkeys: {
'ssh-profile-selector': [],
'restart-ssh-session': [], 'restart-ssh-session': [],
'launch-winscp': [], 'launch-winscp': [],
}, },

View File

@ -5,6 +5,10 @@ import { HotkeyDescription, HotkeyProvider } from 'tabby-core'
@Injectable() @Injectable()
export class SSHHotkeyProvider extends HotkeyProvider { export class SSHHotkeyProvider extends HotkeyProvider {
hotkeys: HotkeyDescription[] = [ hotkeys: HotkeyDescription[] = [
{
id: 'ssh-profile-selector',
name: 'Show SSH profile selector',
},
{ {
id: 'restart-ssh-session', id: 'restart-ssh-session',
name: 'Restart current SSH session', name: 'Restart current SSH session',

View File

@ -4,8 +4,8 @@ import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr' import { ToastrModule } from 'ngx-toastr'
import { NgxFilesizeModule } from 'ngx-filesize' import { NgxFilesizeModule } from 'ngx-filesize'
import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, TabContextMenuItemProvider, ProfileProvider } from 'tabby-core' import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, TabContextMenuItemProvider, ProfileProvider, HotkeysService, ProfilesService, AppService, SelectorService, SelectorOption } from 'tabby-core'
import { SettingsTabProvider } from 'tabby-settings' import { SettingsTabComponent, SettingsTabProvider } from 'tabby-settings'
import TabbyTerminalModule from 'tabby-terminal' import TabbyTerminalModule from 'tabby-terminal'
import { SSHProfileSettingsComponent } from './components/sshProfileSettings.component' import { SSHProfileSettingsComponent } from './components/sshProfileSettings.component'
@ -40,7 +40,7 @@ import { SSHProfilesService } from './profiles'
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true }, { provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
{ provide: HotkeyProvider, useClass: SSHHotkeyProvider, multi: true }, { provide: HotkeyProvider, useClass: SSHHotkeyProvider, multi: true },
{ provide: TabContextMenuItemProvider, useClass: SFTPContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: SFTPContextMenu, multi: true },
{ provide: ProfileProvider, useClass: SSHProfilesService, multi: true }, { provide: ProfileProvider, useExisting: SSHProfilesService, multi: true },
], ],
entryComponents: [ entryComponents: [
SSHProfileSettingsComponent, SSHProfileSettingsComponent,
@ -59,4 +59,49 @@ import { SSHProfilesService } from './profiles'
SFTPPanelComponent, SFTPPanelComponent,
], ],
}) })
export default class SSHModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class 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<void> {
let profiles = await this.profilesService.getProfiles()
profiles = profiles.filter(x => !x.isTemplate && x.type === 'ssh')
const options: SelectorOption<void>[] = 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)
}
}

View File

@ -33,7 +33,7 @@ export class TelnetTabComponent extends BaseTerminalTabComponent {
this.logger = this.log.create('telnetTab') this.logger = this.log.create('telnetTab')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (this.hasFocus && hotkey === 'restart-telnet-session') { if (this.hasFocus && hotkey === 'restart-telnet-session') {
this.reconnect() this.reconnect()
} }

View File

@ -4,6 +4,7 @@ import { ConfigProvider } from 'tabby-core'
export class TelnetConfigProvider extends ConfigProvider { export class TelnetConfigProvider extends ConfigProvider {
defaults = { defaults = {
hotkeys: { hotkeys: {
'telnet-profile-selector': [],
'restart-telnet-session': [], 'restart-telnet-session': [],
}, },
} }

View File

@ -5,6 +5,10 @@ import { HotkeyDescription, HotkeyProvider } from 'tabby-core'
@Injectable() @Injectable()
export class TelnetHotkeyProvider extends HotkeyProvider { export class TelnetHotkeyProvider extends HotkeyProvider {
hotkeys: HotkeyDescription[] = [ hotkeys: HotkeyDescription[] = [
{
id: 'telnet-profile-selector',
name: 'Show Telnet profile selector',
},
{ {
id: 'restart-telnet-session', id: 'restart-telnet-session',
name: 'Restart current Telnet session', name: 'Restart current Telnet session',

View File

@ -4,8 +4,9 @@ import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr' import { ToastrModule } from 'ngx-toastr'
import { NgxFilesizeModule } from 'ngx-filesize' import { NgxFilesizeModule } from 'ngx-filesize'
import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, ProfileProvider } from 'tabby-core' import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, ProfileProvider, HotkeysService, AppService, SelectorService, ProfilesService, SelectorOption } from 'tabby-core'
import TabbyTerminalModule from 'tabby-terminal' import TabbyTerminalModule from 'tabby-terminal'
import { SettingsTabComponent } from 'tabby-settings'
import { TelnetProfileSettingsComponent } from './components/telnetProfileSettings.component' import { TelnetProfileSettingsComponent } from './components/telnetProfileSettings.component'
import { TelnetTabComponent } from './components/telnetTab.component' import { TelnetTabComponent } from './components/telnetTab.component'
@ -30,7 +31,7 @@ import { TelnetProfilesService } from './profiles'
{ provide: ConfigProvider, useClass: TelnetConfigProvider, multi: true }, { provide: ConfigProvider, useClass: TelnetConfigProvider, multi: true },
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true }, { provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
{ provide: HotkeyProvider, useClass: TelnetHotkeyProvider, multi: true }, { provide: HotkeyProvider, useClass: TelnetHotkeyProvider, multi: true },
{ provide: ProfileProvider, useClass: TelnetProfilesService, multi: true }, { provide: ProfileProvider, useExisting: TelnetProfilesService, multi: true },
], ],
entryComponents: [ entryComponents: [
TelnetProfileSettingsComponent, TelnetProfileSettingsComponent,
@ -41,4 +42,49 @@ import { TelnetProfilesService } from './profiles'
TelnetTabComponent, TelnetTabComponent,
], ],
}) })
export default class TelnetModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class 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<void> {
let profiles = await this.profilesService.getProfiles()
profiles = profiles.filter(x => !x.isTemplate && x.type === 'telnet')
const options: SelectorOption<void>[] = 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)
}
}

View File

@ -8,7 +8,7 @@ import { TelnetProfile } from './session'
export class TelnetProfilesService extends ProfileProvider { export class TelnetProfilesService extends ProfileProvider {
id = 'telnet' id = 'telnet'
name = 'Telnet' name = 'Telnet'
supportsQuickConnect = true supportsQuickConnect = false
settingsComponent = TelnetProfileSettingsComponent settingsComponent = TelnetProfileSettingsComponent
async getBuiltinProfiles (): Promise<TelnetProfile[]> { async getBuiltinProfiles (): Promise<TelnetProfile[]> {
@ -41,12 +41,7 @@ export class TelnetProfilesService extends ProfileProvider {
return profile.options.host ? `${profile.options.host}:${profile.options.port}` : '' return profile.options.host ? `${profile.options.host}:${profile.options.port}` : ''
} }
quickConnect (query: string): TelnetProfile|null { quickConnect (query: string): TelnetProfile {
if (!query.startsWith('telnet:')) {
return null
}
query = query.substring('telnet:'.length)
let host = query let host = query
let port = 23 let port = 23
if (host.includes('[')) { if (host.includes('[')) {

View File

@ -174,7 +174,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.logger = this.log.create('baseTerminalTab') this.logger = this.log.create('baseTerminalTab')
this.setTitle('Terminal') this.setTitle('Terminal')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, async hotkey => { this.subscribeUntilDestroyed(this.hotkeys.hotkey$, async hotkey => {
if (!this.hasFocus) { if (!this.hasFocus) {
return return
} }