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

Refactor file dialog service to fix layer breaker #81171

Merged
merged 6 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remot
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { RemoteConnectionState, Deprecated_RemoteAuthorityContext, RemoteFileDialogContext } from 'vs/workbench/browser/contextkeys';
import { IDownloadService } from 'vs/platform/download/common/download';
import { OpenLocalFileFolderCommand, OpenLocalFileCommand, OpenLocalFolderCommand, SaveLocalFileCommand } from 'vs/workbench/services/dialogs/browser/remoteFileDialog';
import { OpenLocalFileFolderCommand, OpenLocalFileCommand, OpenLocalFolderCommand, SaveLocalFileCommand } from 'vs/workbench/services/dialogs/browser/simpleFileDialog';

const WINDOW_ACTIONS_COMMAND_ID = 'remote.showActions';
const CLOSE_REMOTE_COMMAND_ID = 'remote.closeRemote';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { IWindowService, INativeOpenDialogOptions, IURIToOpen, FileFilter } from 'vs/platform/windows/common/windows';
import { IWindowService, IURIToOpen, FileFilter } from 'vs/platform/windows/common/windows';
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
Expand All @@ -13,7 +13,7 @@ import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import * as resources from 'vs/base/common/resources';
import { IInstantiationService, } from 'vs/platform/instantiation/common/instantiation';
import { RemoteFileDialog } from 'vs/workbench/services/dialogs/browser/remoteFileDialog';
import { SimpleFileDialog as SimpleFileDialog } from 'vs/workbench/services/dialogs/browser/simpleFileDialog';
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -78,20 +78,6 @@ export class AbstractFileDialogService {
return this.defaultFilePath(schemeFilter);
}

protected toNativeOpenDialogOptions(options: IPickAndOpenOptions): INativeOpenDialogOptions {
return {
forceNewWindow: options.forceNewWindow,
telemetryExtraData: options.telemetryExtraData,
defaultPath: options.defaultUri && options.defaultUri.fsPath
};
}

protected shouldUseSimplified(schema: string): { useSimplified: boolean, isSetting: boolean } {
const setting = (this.configurationService.getValue('files.simpleDialog.enable') === true);

return { useSimplified: (schema !== Schemas.file) || setting, isSetting: (schema === Schemas.file) && setting };
}

protected addFileSchemaIfNeeded(schema: string): string[] {
// Include File schema unless the schema is web
// Don't allow untitled schema through.
Expand All @@ -102,31 +88,31 @@ export class AbstractFileDialogService {
}
}

protected async pickFileFolderAndOpenSimplified(schema: string, options: IPickAndOpenOptions, shouldUseSimplifiedSetting: boolean): Promise<any> {
protected async pickFileFolderAndOpenSimplified(schema: string, options: IPickAndOpenOptions, preferCurrentWindow: boolean): Promise<any> {
const title = nls.localize('openFileOrFolder.title', 'Open File Or Folder');
const availableFileSystems = this.addFileSchemaIfNeeded(schema);

const uri = await this.pickRemoteResource({ canSelectFiles: true, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });

if (uri) {
const stat = await this.fileService.resolve(uri);

const toOpen: IURIToOpen = stat.isDirectory ? { folderUri: uri } : { fileUri: uri };
if (stat.isDirectory || options.forceNewWindow || shouldUseSimplifiedSetting) {
if (stat.isDirectory || options.forceNewWindow || preferCurrentWindow) {
return this.windowService.openWindow([toOpen], { forceNewWindow: options.forceNewWindow });
} else {
return this.openerService.open(uri);
}
}
}

protected async pickFileAndOpenSimplified(schema: string, options: IPickAndOpenOptions, shouldUseSimplifiedSetting: boolean): Promise<any> {
protected async pickFileAndOpenSimplified(schema: string, options: IPickAndOpenOptions, preferCurrentWindow: boolean): Promise<any> {
const title = nls.localize('openFile.title', 'Open File');
const availableFileSystems = this.addFileSchemaIfNeeded(schema);

const uri = await this.pickRemoteResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
if (uri) {
if (options.forceNewWindow || shouldUseSimplifiedSetting) {
if (options.forceNewWindow || preferCurrentWindow) {
return this.windowService.openWindow([{ fileUri: uri }], { forceNewWindow: options.forceNewWindow });
} else {
return this.openerService.open(uri);
Expand All @@ -138,7 +124,7 @@ export class AbstractFileDialogService {
const title = nls.localize('openFolder.title', 'Open Folder');
const availableFileSystems = this.addFileSchemaIfNeeded(schema);

const uri = await this.pickRemoteResource({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
const uri = await this.pickResource({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
if (uri) {
return this.windowService.openWindow([{ folderUri: uri }], { forceNewWindow: options.forceNewWindow });
}
Expand All @@ -149,7 +135,7 @@ export class AbstractFileDialogService {
const filters: FileFilter[] = [{ name: nls.localize('filterName.workspace', 'Workspace'), extensions: [WORKSPACE_EXTENSION] }];
const availableFileSystems = this.addFileSchemaIfNeeded(schema);

const uri = await this.pickRemoteResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, filters, availableFileSystems });
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, filters, availableFileSystems });
if (uri) {
return this.windowService.openWindow([{ workspaceUri: uri }], { forceNewWindow: options.forceNewWindow });
}
Expand Down Expand Up @@ -177,19 +163,19 @@ export class AbstractFileDialogService {
options.availableFileSystems = this.addFileSchemaIfNeeded(schema);
}

const uri = await this.pickRemoteResource(options);
const uri = await this.pickResource(options);

return uri ? [uri] : undefined;
}

private pickRemoteResource(options: IOpenDialogOptions): Promise<URI | undefined> {
const remoteFileDialog = this.instantiationService.createInstance(RemoteFileDialog);
private pickResource(options: IOpenDialogOptions): Promise<URI | undefined> {
const simpleFileDialog = this.instantiationService.createInstance(SimpleFileDialog);

return remoteFileDialog.showOpenDialog(options);
return simpleFileDialog.showOpenDialog(options);
}

private saveRemoteResource(options: ISaveDialogOptions): Promise<URI | undefined> {
const remoteFileDialog = this.instantiationService.createInstance(RemoteFileDialog);
const remoteFileDialog = this.instantiationService.createInstance(SimpleFileDialog);

return remoteFileDialog.showSaveDialog(options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
options.defaultUri = this.defaultFilePath(schema);
}

return this.pickFileFolderAndOpenSimplified(schema, options, this.shouldUseSimplified(schema).isSetting);
return this.pickFileFolderAndOpenSimplified(schema, options, false);
}

async pickFileAndOpen(options: IPickAndOpenOptions): Promise<any> {
Expand All @@ -27,7 +27,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
options.defaultUri = this.defaultFilePath(schema);
}

return this.pickFileAndOpenSimplified(schema, options, this.shouldUseSimplified(schema).isSetting);
return this.pickFileAndOpenSimplified(schema, options, false);
}

async pickFolderAndOpen(options: IPickAndOpenOptions): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ enum UpdateResult {
InvalidPath
}

export class RemoteFileDialog {
export class SimpleFileDialog {
private options!: IOpenDialogOptions;
private currentFolder!: URI;
private filePickBox!: IQuickPick<FileQuickPickItem>;
Expand Down Expand Up @@ -303,7 +303,7 @@ export class RemoteFileDialog {
this.filePickBox.valueSelection = [this.filePickBox.value.length, this.filePickBox.value.length];
this.filePickBox.items = [];

function doResolve(dialog: RemoteFileDialog, uri: URI | undefined) {
function doResolve(dialog: SimpleFileDialog, uri: URI | undefined) {
if (uri) {
uri = resources.removeTrailingPathSeparator(uri);
}
Expand Down Expand Up @@ -335,7 +335,7 @@ export class RemoteFileDialog {
}
});

function handleAccept(dialog: RemoteFileDialog) {
function handleAccept(dialog: SimpleFileDialog) {
if (dialog.busy) {
// Save the accept until the file picker is not busy.
dialog.onBusyChangeEmitter.event((busy: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IWindowService, OpenDialogOptions, SaveDialogOptions } from 'vs/platform/windows/common/windows';
import { IWindowService, OpenDialogOptions, SaveDialogOptions, INativeOpenDialogOptions } from 'vs/platform/windows/common/windows';
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
Expand All @@ -16,6 +16,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IElectronService } from 'vs/platform/electron/node/electron';
import { AbstractFileDialogService } from 'vs/workbench/services/dialogs/browser/abstractFileDialogService';
import { Schemas } from 'vs/base/common/network';

export class FileDialogService extends AbstractFileDialogService implements IFileDialogService {

Expand All @@ -33,6 +34,20 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
@IElectronService private readonly electronService: IElectronService
) { super(windowService, contextService, historyService, environmentService, instantiationService, configurationService, fileService, openerService); }

private toNativeOpenDialogOptions(options: IPickAndOpenOptions): INativeOpenDialogOptions {
return {
forceNewWindow: options.forceNewWindow,
telemetryExtraData: options.telemetryExtraData,
defaultPath: options.defaultUri && options.defaultUri.fsPath
};
}

private shouldUseSimplified(schema: string): { useSimplified: boolean, isSetting: boolean } {
const setting = (this.configurationService.getValue('files.simpleDialog.enable') === true);

return { useSimplified: (schema !== Schemas.file) || setting, isSetting: (schema === Schemas.file) && setting };
}

async pickFileFolderAndOpen(options: IPickAndOpenOptions): Promise<any> {
const schema = this.getFileSystemSchema(options);

Expand Down