Skip to content

Commit

Permalink
feat(tabby-terminal): #5688 add global Save As Profile context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Clem-Fern committed Jul 7, 2023
1 parent 3d9b15a commit d98fbe8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tabby-terminal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 },
Expand Down
60 changes: 59 additions & 1 deletion tabby-terminal/src/tabContextMenu.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<MenuItemOptions[]> {
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 []
}
}

0 comments on commit d98fbe8

Please sign in to comment.