deprecated matchedHotkey

上级 da599567
......@@ -7,10 +7,10 @@ import { HostAppService, Platform } from './api/hostApp'
import { Profile } from './api/profileProvider'
import { ConfigService } from './services/config.service'
import { SelectorOption } from './api/selector'
import { HotkeysService } from './services/hotkeys.service'
import { ProfilesService } from './services/profiles.service'
import { AppService } from './services/app.service'
import { NotificationsService } from './services/notifications.service'
import { HotkeysService } from 'api'
/** @hidden */
@Injectable()
......@@ -35,12 +35,14 @@ export class ButtonProvider extends ToolbarButtonProvider {
async activate () {
const recentProfiles: Profile[] = this.config.store.recentProfiles
const getProfileOptions = (profile): SelectorOption<void> => ({
icon: recentProfiles.includes(profile) ? 'fas fa-history' : profile.icon,
name: profile.group ? `${profile.group} / ${profile.name}` : profile.name,
description: this.profilesServices.providerForProfile(profile)?.getDescription(profile),
callback: () => this.launchProfile(profile),
})
const getProfileOptions = (profile): SelectorOption<void> => {
const result: SelectorOption<void> = this.profilesServices.selectorOptionForProfile(profile)
if (recentProfiles.includes(profile)) {
result.icon = 'fas fa-history'
}
result.callback = () => this.launchProfile(profile)
return result
}
let options = recentProfiles.map(getProfileOptions)
if (recentProfiles.length) {
......
......@@ -80,7 +80,7 @@ export class AppRootComponent {
this.logger = log.create('main')
this.logger.info('v', platform.getAppVersion())
this.hotkeys.matchedHotkey.subscribe((hotkey: string) => {
this.hotkeys.hotkey$.subscribe((hotkey: string) => {
if (hotkey.startsWith('tab-')) {
const index = parseInt(hotkey.split('-')[1])
if (index <= this.app.tabs.length) {
......
......@@ -209,7 +209,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
})
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) {
return
}
......
......@@ -43,7 +43,7 @@ export class TabHeaderComponent extends BaseComponent {
@Optional() @Inject(TabContextMenuItemProvider) protected contextMenuProviders: TabContextMenuItemProvider[],
) {
super()
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, (hotkey) => {
this.subscribeUntilDestroyed(this.hotkeys.hotkey$, (hotkey) => {
if (this.app.activeTab === this.tab) {
if (hotkey === 'rename-tab') {
this.showRenameTabModal()
......
......@@ -135,7 +135,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
console.error('Unhandled exception:', err)
})
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
hotkeys.hotkey$.subscribe(async (hotkey) => {
if (hotkey.startsWith('profile.')) {
const id = hotkey.split('.')[1]
const profile = (await profilesService.getProfiles()).find(x => x.id === id)
......
......@@ -3,6 +3,7 @@ import { Observable, Subject } from 'rxjs'
import { HotkeyDescription, HotkeyProvider } from '../api/hotkeyProvider'
import { stringifyKeySequence, EventData } from './hotkeys.util'
import { ConfigService } from './config.service'
import { deprecate } from 'util'
export interface PartialHotkeyMatch {
id: string
......@@ -53,6 +54,7 @@ export class HotkeysService {
// deprecated
this.hotkey$.subscribe(h => this.matchedHotkey.emit(h))
this.matchedHotkey.subscribe = deprecate(this.matchedHotkey.subscribe, 'matchedHotkey is deprecated, use hotkey$')
}
/**
......
......@@ -2,6 +2,7 @@ import { Injectable, Inject } from '@angular/core'
import { NewTabParameters } from './tabs.service'
import { BaseTabComponent } from '../components/baseTab.component'
import { Profile, ProfileProvider } from '../api/profileProvider'
import { SelectorOption } from '../api/selector'
import { AppService } from './app.service'
import { ConfigService } from './config.service'
......@@ -51,4 +52,12 @@ export class ProfilesService {
providerForProfile (profile: Profile): ProfileProvider|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),
}
}
}
......@@ -30,7 +30,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
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) {
return
}
......
......@@ -116,7 +116,7 @@ export default class LocalTerminalModule { // eslint-disable-line @typescript-es
dockMenu: DockMenuService,
config: ConfigService,
) {
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
hotkeys.hotkey$.subscribe(async (hotkey) => {
if (hotkey === 'new-tab') {
terminal.openTab()
}
......
......@@ -29,7 +29,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
ngOnInit () {
this.logger = this.log.create('terminalTab')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => {
this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (!this.hasFocus) {
return
}
......
......@@ -14,7 +14,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
super()
hostApp.settingsUIRequest$.subscribe(() => this.open())
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
hotkeys.hotkey$.subscribe(async (hotkey) => {
if (hotkey === 'settings') {
this.open()
}
......
......@@ -41,7 +41,7 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
this.logger = this.log.create('terminalTab')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => {
this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
if (!this.hasFocus) {
return
}
......
......@@ -10,6 +10,7 @@ export class SSHConfigProvider extends ConfigProvider {
agentPath: null,
},
hotkeys: {
'ssh-profile-selector': [],
'restart-ssh-session': [],
'launch-winscp': [],
},
......
......@@ -5,6 +5,10 @@ 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',
......
......@@ -4,8 +4,8 @@ import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr'
import { NgxFilesizeModule } from 'ngx-filesize'
import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, TabContextMenuItemProvider, ProfileProvider } from 'tabby-core'
import { SettingsTabProvider } from 'tabby-settings'
import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, TabContextMenuItemProvider, ProfileProvider, HotkeysService, ProfilesService, AppService, SelectorService, SelectorOption } from 'tabby-core'
import { SettingsTabComponent, SettingsTabProvider } from 'tabby-settings'
import TabbyTerminalModule from 'tabby-terminal'
import { SSHProfileSettingsComponent } from './components/sshProfileSettings.component'
......@@ -40,7 +40,7 @@ import { SSHProfilesService } from './profiles'
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
{ provide: HotkeyProvider, useClass: SSHHotkeyProvider, multi: true },
{ provide: TabContextMenuItemProvider, useClass: SFTPContextMenu, multi: true },
{ provide: ProfileProvider, useClass: SSHProfilesService, multi: true },
{ provide: ProfileProvider, useExisting: SSHProfilesService, multi: true },
],
entryComponents: [
SSHProfileSettingsComponent,
......@@ -59,4 +59,49 @@ import { SSHProfilesService } from './profiles'
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)
}
}
......@@ -33,7 +33,7 @@ export class TelnetTabComponent extends BaseTerminalTabComponent {
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') {
this.reconnect()
}
......
......@@ -4,6 +4,7 @@ import { ConfigProvider } from 'tabby-core'
export class TelnetConfigProvider extends ConfigProvider {
defaults = {
hotkeys: {
'telnet-profile-selector': [],
'restart-telnet-session': [],
},
}
......
......@@ -5,6 +5,10 @@ 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',
......
......@@ -4,8 +4,9 @@ import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr'
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 { SettingsTabComponent } from 'tabby-settings'
import { TelnetProfileSettingsComponent } from './components/telnetProfileSettings.component'
import { TelnetTabComponent } from './components/telnetTab.component'
......@@ -30,7 +31,7 @@ import { TelnetProfilesService } from './profiles'
{ provide: ConfigProvider, useClass: TelnetConfigProvider, multi: true },
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
{ provide: HotkeyProvider, useClass: TelnetHotkeyProvider, multi: true },
{ provide: ProfileProvider, useClass: TelnetProfilesService, multi: true },
{ provide: ProfileProvider, useExisting: TelnetProfilesService, multi: true },
],
entryComponents: [
TelnetProfileSettingsComponent,
......@@ -41,4 +42,49 @@ import { TelnetProfilesService } from './profiles'
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)
}
}
......@@ -8,7 +8,7 @@ import { TelnetProfile } from './session'
export class TelnetProfilesService extends ProfileProvider {
id = 'telnet'
name = 'Telnet'
supportsQuickConnect = true
supportsQuickConnect = false
settingsComponent = TelnetProfileSettingsComponent
async getBuiltinProfiles (): Promise<TelnetProfile[]> {
......@@ -41,12 +41,7 @@ export class TelnetProfilesService extends ProfileProvider {
return profile.options.host ? `${profile.options.host}:${profile.options.port}` : ''
}
quickConnect (query: string): TelnetProfile|null {
if (!query.startsWith('telnet:')) {
return null
}
query = query.substring('telnet:'.length)
quickConnect (query: string): TelnetProfile {
let host = query
let port = 23
if (host.includes('[')) {
......
......@@ -174,7 +174,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.logger = this.log.create('baseTerminalTab')
this.setTitle('Terminal')
this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, async hotkey => {
this.subscribeUntilDestroyed(this.hotkeys.hotkey$, async hotkey => {
if (!this.hasFocus) {
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册