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

Make behaviour of "Open Workspace/Folder" consistent with VS Code #12537

Merged
merged 2 commits into from
May 24, 2023
Merged
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: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
## v1.38.0 - 05/25/2023

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

- [core] moved `ToolbarAwareTabBar.Styles` to `ScrollableTabBar.Styles` [12411](https://github.com/eclipse-theia/theia/pull/12411/)
- [debug] Change the return type of (method) `DebugConfigurationManager.provideDynamicDebugConfigurations()` to <br>
- [workspace] Removed `WorkspaceFrontentContribution.createOpenWorkspaceOpenFileDialogProps(...)` and `WorkspaceFrontendContribution.preferences`
- [core] Moved `ToolbarAwareTabBar.Styles` to `ScrollableTabBar.Styles` [12411](https://github.com/eclipse-theia/theia/pull/12411/)
- [debug] Changed the return type of (method) `DebugConfigurationManager.provideDynamicDebugConfigurations()` to <br>
`Promise<Record<string, DynamicDebugConfigurationSessionOptions[]>>` [#12482](https://github.com/eclipse-theia/theia/pull/12482)

## v1.37.0 - 04/27/2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { inject, injectable } from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri';
import { isOSX } from '@theia/core/lib/common/os';
import { MaybeArray } from '@theia/core/lib/common/types';
import { MessageService } from '@theia/core/lib/common/message-service';
import { FileStat } from '../../common/files';
Expand Down Expand Up @@ -101,14 +100,6 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
}

protected toOpenDialogOptions(uri: URI, props: OpenFileDialogProps): OpenDialogOptions {
if (!isOSX && props.canSelectFiles !== false && props.canSelectFolders === true) {
console.warn(`Cannot have 'canSelectFiles' and 'canSelectFolders' at the same time. Fallback to 'folder' dialog. \nProps was: ${JSON.stringify(props)}.`);

// Given that both props are set, fallback to using a `folder` dialog.
props.canSelectFiles = false;
props.canSelectFolders = true;
}

const result: OpenDialogOptions = {
path: FileUri.fsPath(uri)
};
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export namespace WorkspaceCommands {
...Command.toDefaultLocalizedCommand({
id: 'workspace:openWorkspace',
category: CommonCommands.FILE_CATEGORY,
label: 'Open Workspace...',
label: 'Open Workspace from File...',
}),
dialogLabel: nls.localizeByDefault('Open Workspace')
dialogLabel: nls.localizeByDefault('Open Workspace from File')
};
export const OPEN_RECENT_WORKSPACE = Command.toLocalizedCommand({
id: 'workspace:openRecent',
Expand Down

This file was deleted.

89 changes: 13 additions & 76 deletions packages/workspace/src/browser/workspace-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { injectable, inject } from '@theia/core/shared/inversify';
import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, MessageService, isWindows, MaybeArray } from '@theia/core/lib/common';
import { isOSX, environment, OS } from '@theia/core';
import { isOSX, environment } from '@theia/core';
import {
open, OpenerService, CommonMenus, KeybindingRegistry, KeybindingContribution,
FrontendApplicationContribution, SHELL_TABBAR_CONTEXT_COPY, OnWillStopAction, Navigatable, SaveableSource, Widget
Expand All @@ -27,7 +27,6 @@ import { WorkspaceService } from './workspace-service';
import { THEIA_EXT, VSCODE_EXT } from '../common';
import { WorkspaceCommands } from './workspace-commands';
import { QuickOpenWorkspace } from './quick-open-workspace';
import { WorkspacePreferences } from './workspace-preferences';
import URI from '@theia/core/lib/common/uri';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { EncodingRegistry } from '@theia/core/lib/browser/encoding-registry';
Expand Down Expand Up @@ -70,7 +69,6 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
@inject(QuickOpenWorkspace) protected readonly quickOpenWorkspace: QuickOpenWorkspace;
@inject(FileDialogService) protected readonly fileDialogService: FileDialogService;
@inject(WorkspacePreferences) protected preferences: WorkspacePreferences;
@inject(ContextKeyService) protected readonly contextKeyService: ContextKeyService;
@inject(EncodingRegistry) protected readonly encodingRegistry: EncodingRegistry;
@inject(PreferenceConfigurations) protected readonly preferenceConfigurations: PreferenceConfigurations;
Expand Down Expand Up @@ -362,51 +360,26 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
/**
* Opens a workspace after raising the `Open Workspace` dialog. Resolves to the URI of the recently opened workspace,
* if it was successful. Otherwise, resolves to `undefined`.
*
* **Caveat**: this behaves differently on different platforms
* and `electron`/`browser` version has impact too. See [here](https://github.com/eclipse-theia/theia/pull/3202#issuecomment-430884195) for more details.
*
* Legend:
* - Folders only: => `F`
* - Workspace files only: => `W`
* - Folders and workspace files: => `FW`
*
* -----
*
* |---------|-----------|-----------|------------|------------|
* | | browser Y | browser N | electron Y | electron N |
* |---------|-----------|-----------|------------|------------|
* | Linux | FW | F | W | F |
* | Windows | FW | F | W | F |
* | OS X | FW | F | FW | FW |
* |---------|-----------|-----------|------------|------------|
*
*/
protected async doOpenWorkspace(): Promise<URI | undefined> {
const props = await this.openWorkspaceOpenFileDialogProps();
const props = {
title: WorkspaceCommands.OPEN_WORKSPACE.dialogLabel,
canSelectFiles: true,
canSelectFolders: false,
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
};
const [rootStat] = await this.workspaceService.roots;
const workspaceFolderOrWorkspaceFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
if (workspaceFolderOrWorkspaceFileUri &&
this.getCurrentWorkspaceUri()?.toString() !== workspaceFolderOrWorkspaceFileUri.toString()) {
const destinationFolder = await this.fileService.exists(workspaceFolderOrWorkspaceFileUri);
if (destinationFolder) {
this.workspaceService.open(workspaceFolderOrWorkspaceFileUri);
return workspaceFolderOrWorkspaceFileUri;
const workspaceFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
if (workspaceFileUri &&
this.getCurrentWorkspaceUri()?.toString() !== workspaceFileUri.toString()) {
if (await this.fileService.exists(workspaceFileUri)) {
this.workspaceService.open(workspaceFileUri);
return workspaceFileUri;
}
}
return undefined;
}

protected async openWorkspaceOpenFileDialogProps(): Promise<OpenFileDialogProps> {
await this.preferences.ready;
tsmaeder marked this conversation as resolved.
Show resolved Hide resolved
const type = OS.type();
const electron = this.isElectron();
return WorkspaceFrontendContribution.createOpenWorkspaceOpenFileDialogProps({
type,
electron,
});
}

protected async closeWorkspace(): Promise<void> {
await this.workspaceService.close();
}
Expand Down Expand Up @@ -519,40 +492,4 @@ export namespace WorkspaceFrontendContribution {
'Theia Workspace (*.theia-workspace)': [THEIA_EXT],
'VS Code Workspace (*.code-workspace)': [VSCODE_EXT]
};

/**
* Returns with an `OpenFileDialogProps` for opening the `Open Workspace` dialog.
*/
export function createOpenWorkspaceOpenFileDialogProps(options: Readonly<{ type: OS.Type, electron: boolean }>): OpenFileDialogProps {
const { electron, type } = options;
const title = WorkspaceCommands.OPEN_WORKSPACE.dialogLabel;
// If browser
if (!electron) {
return {
title,
canSelectFiles: true,
canSelectFolders: true,
filters: DEFAULT_FILE_FILTER
};
}

// If electron
if (OS.Type.OSX === type) {
// `Finder` can select folders and files at the same time. We allow folders and workspace files.
return {
title,
canSelectFiles: true,
canSelectFolders: true,
filters: DEFAULT_FILE_FILTER
};
}

return {
title,
canSelectFiles: true,
canSelectFolders: false,
filters: DEFAULT_FILE_FILTER
};
}

}