Skip to content

Commit

Permalink
Support multiselection in 'Add Folder to Workspace...' dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
  • Loading branch information
Colin Grant committed Jul 2, 2021
1 parent bc3b5e1 commit 80f6db0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## v1.16.0 - 7/29/2021

[1.16.0 Milestone](https://github.com/eclipse-theia/theia/milestone/22)

- [workspace] added support for multiple selections in 'Add folder to workspace' dialog. [#9684](https://github.com/eclipse-theia/theia/pull/9684)

<a name="breaking_changes_1.16.0">[Breaking Changes:](#breaking_changes_1.16.0)</a>

- [workspace] `WorkspaceCommandContribution.addFolderToWorkspace` no longer accepts `undefined`. [#9684](https://github.com/eclipse-theia/theia/pull/9684)

## v1.15.0 - 6/30/2021

[1.15.0 Milestone](https://github.com/eclipse-theia/theia/milestone/21)
Expand Down
24 changes: 15 additions & 9 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,18 @@ export class WorkspaceCommandContribution implements CommandContribution {
isEnabled: () => this.workspaceService.isMultiRootWorkspaceEnabled,
isVisible: () => this.workspaceService.isMultiRootWorkspaceEnabled,
execute: async () => {
const uri = await this.fileDialogService.showOpenDialog({
const selection = await this.fileDialogService.showOpenDialog({
title: WorkspaceCommands.ADD_FOLDER.label!,
canSelectFiles: false,
canSelectFolders: true
canSelectFolders: true,
canSelectMany: true,
});
if (!uri) {
if (!selection) {
return;
}
const uris = Array.isArray(selection) ? selection : [selection];
const workspaceSavedBeforeAdding = this.workspaceService.saved;
await this.addFolderToWorkspace(uri);
await this.addFolderToWorkspace(...uris);
if (!workspaceSavedBeforeAdding) {
const saveCommand = registry.getCommand(WorkspaceCommands.SAVE_WORKSPACE_AS.id);
if (saveCommand && await new ConfirmDialog({
Expand Down Expand Up @@ -426,13 +428,17 @@ export class WorkspaceCommandContribution implements CommandContribution {
}
}

protected async addFolderToWorkspace(uri: URI | undefined): Promise<void> {
if (uri) {
protected async addFolderToWorkspace(...uris: URI[]): Promise<void> {
if (uris.length) {
const foldersToAdd = [];
try {
const stat = await this.fileService.resolve(uri);
if (stat.isDirectory) {
await this.workspaceService.addRoot(uri);
for (const uri of uris) {
const stat = await this.fileService.resolve(uri);
if (stat.isDirectory) {
foldersToAdd.push(uri);
}
}
await this.workspaceService.addRoots(...foldersToAdd);
} catch { }
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/workspace/src/browser/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ export class WorkspaceService implements FrontendApplicationContribution {
await this.spliceRoots(this._roots.length, 0, uri);
}

async addRoots(...uris: URI[]): Promise<void> {
await this.spliceRoots(this._roots.length, 0, ...uris);
}

/**
* Removes root folder(s) from workspace.
*/
Expand All @@ -388,6 +392,7 @@ export class WorkspaceService implements FrontendApplicationContribution {
workspaceData
)
);
await this.updateWorkspace();
}
}

Expand Down Expand Up @@ -416,6 +421,7 @@ export class WorkspaceService implements FrontendApplicationContribution {
const currentData = await this.getWorkspaceDataFromFile();
const newData = WorkspaceData.buildWorkspaceData(roots, currentData);
await this.writeWorkspaceFile(this._workspace, newData);
await this.updateWorkspace();
return toRemove.map(root => new URI(root));
}

Expand Down

0 comments on commit 80f6db0

Please sign in to comment.