Make project workspace selectable if no workspace is open yet (#13508)

* allow new workspace location to be editable

* fix workspace inputbox not showing up after toggling open workspace radio buttons

* add a few tests

* cleanup

* fix errors

* addressing comments

* fix filter for windows

* add error message if existing workspace file is selected and change picker to be folder only

* address comments

* fix typos and update tests
This commit is contained in:
Kim Santiago
2020-12-14 13:24:36 -08:00
committed by GitHub
parent c2de462955
commit 1aaf80c3ab
8 changed files with 186 additions and 41 deletions

View File

@@ -39,13 +39,17 @@ export class OpenExistingDialog extends DialogBase {
if (this._targetTypeRadioCardGroup?.selectedCardId === constants.Project) {
const fileExists = await fileExist(this._projectFile);
if (!fileExists) {
this.showErrorMessage(constants.ProjectFileNotExistError(this._projectFile));
this.showErrorMessage(constants.FileNotExistError(constants.Project.toLowerCase(), this._projectFile));
return false;
}
if (this.workspaceInputBox!.enabled && !await this.validateNewWorkspace(false)) {
return false;
}
} else if (this._targetTypeRadioCardGroup?.selectedCardId === constants.Workspace) {
const fileExists = await fileExist(this._workspaceFile);
if (!fileExists) {
this.showErrorMessage(constants.WorkspaceFileNotExistError(this._workspaceFile));
this.showErrorMessage(constants.FileNotExistError(constants.Workspace.toLowerCase(), this._workspaceFile));
return false;
}
}
@@ -65,7 +69,7 @@ export class OpenExistingDialog extends DialogBase {
} else {
const validateWorkspace = await this.workspaceService.validateWorkspace();
if (validateWorkspace) {
await this.workspaceService.addProjectsToWorkspace([vscode.Uri.file(this._projectFile)]);
await this.workspaceService.addProjectsToWorkspace([vscode.Uri.file(this._projectFile)], vscode.Uri.file(this.workspaceInputBox!.value!));
}
}
}
@@ -130,16 +134,20 @@ export class OpenExistingDialog extends DialogBase {
this.register(this._targetTypeRadioCardGroup.onSelectionChanged(({ cardId }) => {
if (cardId === constants.Project) {
this._filePathTextBox!.placeHolder = constants.ProjectFilePlaceholder;
this.formBuilder?.addFormItem(this.workspaceFormComponent!);
this.formBuilder?.addFormItem(this.workspaceDescriptionFormComponent!);
this.formBuilder?.addFormItem(this.workspaceInputFormComponent!);
} else if (cardId === constants.Workspace) {
this._filePathTextBox!.placeHolder = constants.WorkspacePlaceholder;
this.formBuilder?.removeFormItem(this.workspaceFormComponent!);
this.formBuilder?.removeFormItem(this.workspaceDescriptionFormComponent!);
this.formBuilder?.removeFormItem(this.workspaceInputFormComponent!);
}
// clear selected file textbox
this._filePathTextBox!.value = '';
}));
this.createWorkspaceContainer(view);
this.formBuilder = view.modelBuilder.formContainer().withFormItems([
{
title: constants.TypeTitle,
@@ -150,14 +158,15 @@ export class OpenExistingDialog extends DialogBase {
required: true,
component: this.createHorizontalContainer(view, [this._filePathTextBox, browseFolderButton])
},
this.createWorkspaceContainer(view)
this.workspaceDescriptionFormComponent!,
this.workspaceInputFormComponent!
]);
await view.initializeModel(this.formBuilder?.component());
this.initDialogComplete?.resolve();
}
public async workspaceBrowse(): Promise<void> {
const filters: { [name: string]: string[] } = { [constants.Workspace]: [constants.WorkspaceFileExtension] };
const filters: { [name: string]: string[] } = { [constants.Workspace]: [constants.WorkspaceFileExtension.substring(1)] }; // filter already adds a period before the extension
const fileUris = await vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectFolders: false,