Skip to content

Commit

Permalink
dialogs - Allow multiple selection on Open...
Browse files Browse the repository at this point in the history
fixes #12905

- allow multiple selection in doOpen dialog
- handle an array or a single URI or undefined when closing dialog

Contributed on behalf of ST Microelectronics

Signed-off-by: Remi Schnekenburger <[email protected]>
  • Loading branch information
rschnekenbu committed Sep 19, 2023
1 parent c4eeb2c commit 7e8f500
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)

## v1.42.0 - 09/28/2023

- [dialogs] allow multiple selection on Open... [#12923](https://github.com/eclipse-theia/theia/pull/12923) - Contributed on behalf of STMicroelectronics.

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

## v1.41.0 - 08/31/2023

- [application-package] added handling to quit the electron app when the backend fails to start [#12778](https://github.com/eclipse-theia/theia/pull/12778) - Contributed on behalf of STMicroelectronics.
Expand Down
67 changes: 51 additions & 16 deletions packages/workspace/src/browser/workspace-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,60 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
* This is the generic `Open` method. Opens files and directories too. Resolves to the opened URI.
* Except when you are on either Windows or Linux `AND` running in electron. If so, it opens a file.
*/
protected async doOpen(): Promise<URI | undefined> {
protected async doOpen(): Promise<MaybeArray<URI> | undefined> {
if (!isOSX && this.isElectron()) {
return this.doOpenFile();
}
const [rootStat] = await this.workspaceService.roots;
const destinationUri = await this.fileDialogService.showOpenDialog({
title: WorkspaceCommands.OPEN.dialogLabel,
canSelectFolders: true,
canSelectFiles: true
canSelectFiles: true,
canSelectMany: true
}, rootStat);
if (destinationUri && this.getCurrentWorkspaceUri()?.toString() !== destinationUri.toString()) {
const destination = await this.fileService.resolve(destinationUri);
if (destination.isDirectory) {
this.workspaceService.open(destinationUri);
if (destinationUri) {
if (Array.isArray(destinationUri)) {
// only open files then open all folders in a new workspace, as done with Electron see doOpenFolder
const folders: MaybeArray<URI> = [];
for (const uri of destinationUri) {
if (this.getCurrentWorkspaceUri()?.toString() !== uri.toString()) {
const destination = await this.fileService.resolve(uri);
if (destination.isDirectory) {
folders.push(uri);
} else {
await open(this.openerService, uri);
}
}
}
if (folders.length > 0) {
const openableURI = await this.getOpenableWorkspaceUri(folders);
if (openableURI && (!this.workspaceService.workspace || !openableURI.isEqual(this.workspaceService.workspace.resource))) {
this.workspaceService.open(openableURI);
}
}

return destinationUri;
} else {
await open(this.openerService, destinationUri);
return this.doOpenFileOrFolder(destinationUri, true);
}
return destinationUri;
}
return undefined;
}

protected async doOpenFileOrFolder(uri: URI, openFolders: boolean): Promise<URI> {
if (this.getCurrentWorkspaceUri()?.toString() !== uri.toString()) {
const destination = await this.fileService.resolve(uri);
if (destination.isDirectory) {
if (openFolders) {
this.workspaceService.open(uri);
}
} else {
await open(this.openerService, uri);
}
}
return uri;
}

/**
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
* - the workspace root is not set,
Expand All @@ -292,20 +324,23 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
*
* Otherwise, resolves to the URI of the file.
*/
protected async doOpenFile(): Promise<URI | undefined> {
protected async doOpenFile(): Promise<MaybeArray<URI> | undefined> {
const props: OpenFileDialogProps = {
title: WorkspaceCommands.OPEN_FILE.dialogLabel,
canSelectFolders: false,
canSelectFiles: true
canSelectFiles: true,
canSelectMany: true
};
const [rootStat] = await this.workspaceService.roots;
const destinationFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
if (destinationFileUri) {
const destinationFile = await this.fileService.resolve(destinationFileUri);
if (!destinationFile.isDirectory) {
await open(this.openerService, destinationFileUri);
return destinationFileUri;
const destinationFileUri: MaybeArray<URI> | undefined = await this.fileDialogService.showOpenDialog(props, rootStat);
if (Array.isArray(destinationFileUri)) {
const result = [];
for (const uri of destinationFileUri) {
result.push(await this.doOpenFileOrFolder(uri, false));
}
return result;
} else if (destinationFileUri) {
return this.doOpenFileOrFolder(destinationFileUri, false);
}
return undefined;
}
Expand Down

0 comments on commit 7e8f500

Please sign in to comment.