deprecated matchedHotkey

This commit is contained in:
Eugene Pankov
2021-07-05 22:52:32 +02:00
parent da599567f8
commit 461cd2bec7
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 { 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) {

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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)

View File

@@ -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$')
}
/**

View File

@@ -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),
}
}
}