|
|
@@ -1,9 +1,12 @@
|
|
|
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, PartialProfile, Profile } from 'tabby-core'
|
|
|
import { BaseTerminalTabComponent } from './api/baseTerminalTab.component'
|
|
|
import { TerminalContextMenuItemProvider } from './api/contextMenuProvider'
|
|
|
import { MultifocusService } from './services/multifocus.service'
|
|
|
import { ConnectableTerminalTabComponent } from './api/connectableTerminalTab.component'
|
|
|
+import { v4 as uuidv4 } from 'uuid'
|
|
|
+import slugify from 'slugify'
|
|
|
|
|
|
/** @hidden */
|
|
|
@Injectable()
|
|
|
@@ -150,3 +153,66 @@ 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')
|
|
|
+ modal.componentInstance.value = tab.profile.name
|
|
|
+ const name = (await modal.result)?.value
|
|
|
+ if (!name) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const options = {
|
|
|
+ ...tab.profile.options,
|
|
|
+ }
|
|
|
+
|
|
|
+ const cwd = await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd
|
|
|
+ if (cwd) {
|
|
|
+ options.cwd = cwd
|
|
|
+ }
|
|
|
+
|
|
|
+ const profile: PartialProfile<Profile> = {
|
|
|
+ type: tab.profile.type,
|
|
|
+ name,
|
|
|
+ options,
|
|
|
+ }
|
|
|
+
|
|
|
+ profile.id = `${profile.type}:custom:${slugify(name)}:${uuidv4()}`
|
|
|
+ profile.group = tab.profile.group
|
|
|
+ profile.icon = tab.profile.icon
|
|
|
+ profile.color = tab.profile.color
|
|
|
+ profile.disableDynamicTitle = tab.profile.disableDynamicTitle
|
|
|
+ profile.behaviorOnSessionEnd = tab.profile.behaviorOnSessionEnd
|
|
|
+
|
|
|
+ this.config.store.profiles = [
|
|
|
+ ...this.config.store.profiles,
|
|
|
+ profile,
|
|
|
+ ]
|
|
|
+ this.config.save()
|
|
|
+ this.notifications.info(this.translate.instant('Saved'))
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ return []
|
|
|
+ }
|
|
|
+}
|