Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix#9323: Can't modify profiles created via "Save as profile" #10010

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tabby-core/src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class ConfigProxy {
}
}
}

this.__getReal = () => { // eslint-disable-line @typescript-eslint/unbound-method
return real
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-empty-function
Expand All @@ -112,6 +116,8 @@ export class ConfigProxy {
__getDefault (_key: string): any { }
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-empty-function
__cleanup () { }
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-empty-function
__getReal (): any { }
}

@Injectable({ providedIn: 'root' })
Expand Down
4 changes: 2 additions & 2 deletions tabby-core/src/services/profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class ProfilesService {
* arg: skipUserDefaults -> do not merge global provider defaults in ConfigProxy
* arg: skipGroupDefaults -> do not merge parent group provider defaults in ConfigProxy
*/
getConfigProxyForProfile <T extends Profile> (profile: PartialProfile<T>, options?: { skipGlobalDefaults?: boolean, skipGroupDefaults?: boolean }): T {
getConfigProxyForProfile <T extends Profile> (profile: PartialProfile<T>, options?: { skipGlobalDefaults?: boolean, skipGroupDefaults?: boolean }): T & ConfigProxy {
const defaults = this.getProfileDefaults(profile, options).reduce(configMerge, {})
return new ConfigProxy(profile, defaults) as unknown as T
return new ConfigProxy(profile, defaults) as unknown as T & ConfigProxy
}

/**
Expand Down
20 changes: 9 additions & 11 deletions tabby-terminal/src/tabContextMenu.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Injectable, Optional, Inject } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile } from 'tabby-core'
import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile, ProfilesService, ConfigProxy } 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()
Expand Down Expand Up @@ -162,6 +160,7 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
private ngbModal: NgbModal,
private notifications: NotificationsService,
private translate: TranslateService,
private profilesService: ProfilesService,
) {
super()
}
Expand All @@ -180,9 +179,8 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
return
}

const options = {
...tab.profile.options,
}
const tab_options = tab.profile.options instanceof ConfigProxy ? (tab.profile.options as ConfigProxy).__getReal() : tab.profile.options
const options = { ...tab_options }

const cwd = await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd
if (cwd) {
Expand All @@ -195,18 +193,18 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
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.profilesService.getConfigProxyForProfile(profile).__cleanup()
profile.type = tab.profile.type

this.profilesService.newProfile(profile)
this.config.save()

this.notifications.info(this.translate.instant('Saved'))
},
},
Expand Down
Loading