From 136ec1035b6636e6d5907d51fa1cea5966ee2d6f Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 9 Feb 2022 21:56:44 +0100 Subject: [PATCH] fixed #5702 - added hotkeys to jump to settings tabs --- tabby-settings/src/config.ts | 5 +++++ tabby-settings/src/hotkeys.ts | 16 +++++++++++++--- tabby-settings/src/index.ts | 18 ++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tabby-settings/src/config.ts b/tabby-settings/src/config.ts index 31727f5b..f76c7dde 100644 --- a/tabby-settings/src/config.ts +++ b/tabby-settings/src/config.ts @@ -14,6 +14,11 @@ export class SettingsConfigProvider extends ConfigProvider { vault: true, }, }, + hotkeys: { + 'settings-tab': { + __nonStructural: true, + }, + }, } platformDefaults = { [Platform.macOS]: { diff --git a/tabby-settings/src/hotkeys.ts b/tabby-settings/src/hotkeys.ts index 8e8c6080..725a5c57 100644 --- a/tabby-settings/src/hotkeys.ts +++ b/tabby-settings/src/hotkeys.ts @@ -1,5 +1,6 @@ -import { Injectable } from '@angular/core' +import { Inject, Injectable } from '@angular/core' import { HotkeyDescription, HotkeyProvider, TranslateService } from 'tabby-core' +import { SettingsTabProvider } from './api' /** @hidden */ @Injectable() @@ -11,9 +12,18 @@ export class SettingsHotkeyProvider extends HotkeyProvider { }, ] - constructor (private translate: TranslateService) { super() } + constructor ( + private translate: TranslateService, + @Inject(SettingsTabProvider) private settingsProviders: SettingsTabProvider[], + ) { super() } async provide (): Promise { - return this.hotkeys + return [ + ...this.hotkeys, + ...this.settingsProviders.map(provider => ({ + id: `settings-tab.${provider.id}`, + name: this.translate.instant('Open settings tab: {tab}', { tab: provider.title }), + })), + ] } } diff --git a/tabby-settings/src/index.ts b/tabby-settings/src/index.ts index b34090c1..13fa5a73 100644 --- a/tabby-settings/src/index.ts +++ b/tabby-settings/src/index.ts @@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { InfiniteScrollModule } from 'ngx-infinite-scroll' -import TabbyCorePlugin, { ToolbarButtonProvider, HotkeyProvider, ConfigProvider } from 'tabby-core' +import TabbyCorePlugin, { ToolbarButtonProvider, HotkeyProvider, ConfigProvider, HotkeysService, AppService } from 'tabby-core' import { EditProfileModalComponent } from './components/editProfileModal.component' import { HotkeyInputModalComponent } from './components/hotkeyInputModal.component' @@ -74,7 +74,21 @@ import { HotkeySettingsTabProvider, WindowSettingsTabProvider, VaultSettingsTabP ], }) export default class SettingsModule { - constructor (public configSync: ConfigSyncService) { } + constructor ( + public configSync: ConfigSyncService, + app: AppService, + hotkeys: HotkeysService, + ) { + hotkeys.hotkey$.subscribe(async hotkey => { + if (hotkey.startsWith('settings-tab.')) { + const id = hotkey.substring(hotkey.indexOf('.') + 1) + app.openNewTabRaw({ + type: SettingsTabComponent, + inputs: { activeTab: id }, + }) + } + }) + } } export * from './api'