diff --git a/src/plus/workspaces/workspacesService.ts b/src/plus/workspaces/workspacesService.ts index d628315..4cad4ed 100644 --- a/src/plus/workspaces/workspacesService.ts +++ b/src/plus/workspaces/workspacesService.ts @@ -1,4 +1,4 @@ -import type { CancellationToken, Event } from 'vscode'; +import type { CancellationToken, Event, QuickPickItem } from 'vscode'; import { Disposable, EventEmitter, ProgressLocation, Uri, window, workspace } from 'vscode'; import { getSupportedWorkspacesPathMappingProvider } from '@env/providers'; import type { Container } from '../../container'; @@ -247,10 +247,16 @@ export class WorkspacesService implements Disposable { 'New repositories found in the cloud workspace matching this workspace. Would you like to add them?', { modal: true }, { title: 'Add' }, + { title: 'Change Auto-Add Setting' }, { title: 'Cancel', isCloseAffordance: true }, ); - if (addChoice?.title !== 'Add') { + if (addChoice == null || addChoice.title === 'Cancel') { + return; + } + + if (addChoice.title === 'Change Auto-Add Setting') { + void this.chooseCodeWorkspaceAutoAddSetting({ current: true }); return; } @@ -1010,20 +1016,14 @@ export class WorkspacesService implements Disposable { if (newWorkspaceUri == null) return; - const newWorkspaceAutoAddSetting = await window.showInformationMessage( - 'Would you like to enable auto-add for this workspace? This will automatically add new repositories from the cloud workspace to this workspace when it is opened.', - { modal: true }, - { title: 'Enable', option: WorkspaceAutoAddSetting.Enabled }, - { title: 'Disable', option: WorkspaceAutoAddSetting.Disabled }, - { title: 'Ask every time', option: WorkspaceAutoAddSetting.Prompt }, - ); + const newWorkspaceAutoAddSetting = await this.chooseCodeWorkspaceAutoAddSetting(); const created = await this._workspacesPathProvider.writeCodeWorkspaceFile( newWorkspaceUri, workspaceFolderPaths, { workspaceId: workspaceId, - workspaceAutoAddSetting: newWorkspaceAutoAddSetting?.option ?? WorkspaceAutoAddSetting.Disabled, + workspaceAutoAddSetting: newWorkspaceAutoAddSetting, }, ); @@ -1047,58 +1047,66 @@ export class WorkspacesService implements Disposable { void this.openCodeWorkspaceFile(workspaceId, { location: open.location }); } - async chooseCurrentCodeWorkspaceAutoAddSetting(): Promise { + async chooseCodeWorkspaceAutoAddSetting(options?: { current?: boolean }): Promise { if ( - workspace.workspaceFile == null || - this._currentWorkspaceId == null || - this._currentWorkspaceAutoAddSetting == null + options?.current && + (workspace.workspaceFile == null || + this._currentWorkspaceId == null || + this._currentWorkspaceAutoAddSetting == null) ) { - return; + return WorkspaceAutoAddSetting.Disabled; } - let autoAddOptions = [ + const defaultOption = options?.current + ? this._currentWorkspaceAutoAddSetting + : WorkspaceAutoAddSetting.Disabled; + + const autoAddOptions = [ { - title: 'Enable', + label: 'Enable', option: WorkspaceAutoAddSetting.Enabled, ...(this._currentWorkspaceAutoAddSetting === WorkspaceAutoAddSetting.Enabled - ? { description: 'current' } + ? { description: '(current)' } : {}), }, { - title: 'Disable', + label: 'Disable', option: WorkspaceAutoAddSetting.Disabled, ...(this._currentWorkspaceAutoAddSetting === WorkspaceAutoAddSetting.Disabled - ? { description: 'current' } + ? { description: '(current)' } : {}), }, { - title: 'Ask every time', + label: 'Ask every time', option: WorkspaceAutoAddSetting.Prompt, ...(this._currentWorkspaceAutoAddSetting === WorkspaceAutoAddSetting.Prompt - ? { description: 'current' } + ? { description: '(current)' } : {}), }, ]; - autoAddOptions = autoAddOptions.filter(s => s.option !== this._currentWorkspaceAutoAddSetting); - // Show a quickpick without the current auto-add setting as an option - const newWorkspaceAutoAddOption = await window.showQuickPick( - autoAddOptions.map(s => s.title), - { - placeHolder: 'Choose an option to automatically add missing repositories to this workspace', - title: 'Automatically add repositories', - }, - ); - if (newWorkspaceAutoAddOption == null) return; + const newWorkspaceAutoAddOption = await window.showQuickPick< + QuickPickItem & { option: WorkspaceAutoAddSetting } + >(autoAddOptions, { + placeHolder: 'Choose an option to automatically add missing repositories to this workspace', + title: 'Automatically add repositories', + }); + if (newWorkspaceAutoAddOption?.option == null) return defaultOption; - const newWorkspaceAtuoAddSetting = autoAddOptions.find(s => s.title === newWorkspaceAutoAddOption)?.option; - if (newWorkspaceAtuoAddSetting == null) return; + const newWorkspaceAutoAddSetting = newWorkspaceAutoAddOption.option; - const updated = await this._workspacesPathProvider.updateCodeWorkspaceFileSettings(workspace.workspaceFile, { - workspaceAutoAddSetting: newWorkspaceAtuoAddSetting, - }); - if (!updated) return; - this._currentWorkspaceAutoAddSetting = newWorkspaceAtuoAddSetting; + if (options?.current && workspace.workspaceFile != null) { + const updated = await this._workspacesPathProvider.updateCodeWorkspaceFileSettings( + workspace.workspaceFile, + { + workspaceAutoAddSetting: newWorkspaceAutoAddSetting, + }, + ); + if (!updated) return this._currentWorkspaceAutoAddSetting; + this._currentWorkspaceAutoAddSetting = newWorkspaceAutoAddSetting; + } + + return newWorkspaceAutoAddSetting; } async openCodeWorkspaceFile(workspaceId: string, options?: { location?: OpenWorkspaceLocation }): Promise { diff --git a/src/views/workspacesView.ts b/src/views/workspacesView.ts index 9d72bcc..1f4030a 100644 --- a/src/views/workspacesView.ts +++ b/src/views/workspacesView.ts @@ -131,7 +131,7 @@ export class WorkspacesView extends ViewBase<'workspaces', WorkspacesViewNode, R registerViewCommand( this.getQualifiedCommand('changeAutoAddSetting'), async () => { - await this.container.workspaces.chooseCurrentCodeWorkspaceAutoAddSetting(); + await this.container.workspaces.chooseCodeWorkspaceAutoAddSetting({ current: true }); }, this, ),