From d98fbe8b44ec063237632658fc071d1ea584b003 Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 10:37:28 +0200 Subject: [PATCH] feat(tabby-terminal): Eugeny/tabby#5688 add global Save As Profile context menu --- tabby-terminal/src/index.ts | 3 +- tabby-terminal/src/tabContextMenu.ts | 60 +++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/tabby-terminal/src/index.ts b/tabby-terminal/src/index.ts index 35b0ac70d0..77cd82ed50 100644 --- a/tabby-terminal/src/index.ts +++ b/tabby-terminal/src/index.ts @@ -28,7 +28,7 @@ import { PathDropDecorator } from './features/pathDrop' import { ZModemDecorator } from './features/zmodem' import { TerminalConfigProvider } from './config' import { TerminalHotkeyProvider } from './hotkeys' -import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu, ReconnectContextMenu } from './tabContextMenu' +import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu, ReconnectContextMenu, SaveAsProfileContextMenu } from './tabContextMenu' import { Frontend } from './frontends/frontend' import { XTermFrontend, XTermWebGLFrontend } from './frontends/xtermFrontend' @@ -60,6 +60,7 @@ import { DefaultColorSchemes } from './colorSchemes' { provide: TabContextMenuItemProvider, useClass: MiscContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: LegacyContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: ReconnectContextMenu, multi: true }, + { provide: TabContextMenuItemProvider, useClass: SaveAsProfileContextMenu, multi: true }, { provide: CLIHandler, useClass: TerminalCLIHandler, multi: true }, { provide: TerminalColorSchemeProvider, useClass: DefaultColorSchemes, multi: true }, diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index 9be7947618..e566d13558 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,5 +1,6 @@ import { Injectable, Optional, Inject } from '@angular/core' -import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent } from 'tabby-core' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -150,3 +151,60 @@ export class LegacyContextMenu extends TabContextMenuItemProvider { } } + +/** @hidden */ +@Injectable() +export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { + constructor ( + private config: ConfigService, + private ngbModal: NgbModal, + private notifications: NotificationsService, + private translate: TranslateService, + ) { + super() + } + + async getItems (tab: BaseTabComponent): Promise { + if (tab instanceof BaseTerminalTabComponent) { + return [ + { + label: this.translate.instant('Save as profile'), + click: async () => { + const modal = this.ngbModal.open(PromptModalComponent) + modal.componentInstance.prompt = this.translate.instant('New profile name') + const name = (await modal.result)?.value + if (!name) { + return + } + + let options = {...tab.profile.options} + const cwd = await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd + if (cwd) { + options = { + ...options, + cwd + } + } + + const profile = { + options, + name, + type: tab.profile.type, + } + + console.log(profile) + + this.config.store.profiles = [ + ...this.config.store.profiles, + profile, + ] + this.config.save() + this.notifications.info(this.translate.instant('Saved')) + }, + }, + ] + } + + return [] + } +} \ No newline at end of file