提交 73028765 编写于 作者: M Martin Aeschlimann

add availableFileSystems

上级 973849f2
......@@ -43,7 +43,6 @@ export interface IPickAndOpenOptions {
forceNewWindow?: boolean;
defaultUri?: URI;
telemetryExtraData?: ITelemetryData;
allowLocalPaths?: boolean;
}
export interface ISaveDialogOptions {
......@@ -67,6 +66,12 @@ export interface ISaveDialogOptions {
* A human-readable string for the ok button
*/
saveLabel?: string;
/**
* Specifies a list of schemas for the file systems the user can save to. If not specified, uses the schema of the defaultURI or, if also not specified,
* the schema of the current window.
*/
availableFileSystems?: string[];
}
export interface IOpenDialogOptions {
......@@ -107,9 +112,10 @@ export interface IOpenDialogOptions {
filters?: FileFilter[];
/**
* Wheter the user can pick local files or folders as well (only applies to remote dialogs)
* Specifies a list of schemas for the file systems the user can load from. If not specified, uses the schema of the defaultURI or, if also not available,
* the schema of the current window.
*/
allowLocalPaths?: boolean;
availableFileSystems?: string[];
}
......
......@@ -32,7 +32,7 @@ export class OpenFileAction extends Action {
}
run(event?: any, data?: ITelemetryData): Promise<any> {
return this.dialogService.pickFileAndOpen({ forceNewWindow: false, telemetryExtraData: data, allowLocalPaths: true });
return this.dialogService.pickFileAndOpen({ forceNewWindow: false, telemetryExtraData: data });
}
}
......@@ -50,7 +50,7 @@ export class OpenFolderAction extends Action {
}
run(event?: any, data?: ITelemetryData): Promise<any> {
return this.dialogService.pickFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data, allowLocalPaths: true });
return this.dialogService.pickFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data });
}
}
......@@ -68,7 +68,7 @@ export class OpenFileFolderAction extends Action {
}
run(event?: any, data?: ITelemetryData): Promise<any> {
return this.dialogService.pickFileFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data, allowLocalPaths: true });
return this.dialogService.pickFileFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data });
}
}
......@@ -179,7 +179,7 @@ export class OpenWorkspaceAction extends Action {
}
run(event?: any, data?: ITelemetryData): Promise<any> {
return this.dialogService.pickWorkspaceAndOpen({ telemetryExtraData: data, allowLocalPaths: true });
return this.dialogService.pickWorkspaceAndOpen({ telemetryExtraData: data });
}
}
......
......@@ -29,7 +29,7 @@ export const PICK_WORKSPACE_FOLDER_COMMAND_ID = '_workbench.pickWorkspaceFolder'
CommandsRegistry.registerCommand({
id: 'workbench.action.files.openFileFolderInNewWindow',
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickFileFolderAndOpen({ forceNewWindow: true, allowLocalPaths: true })
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickFileFolderAndOpen({ forceNewWindow: true })
});
CommandsRegistry.registerCommand({
......@@ -39,17 +39,17 @@ CommandsRegistry.registerCommand({
CommandsRegistry.registerCommand({
id: 'workbench.action.files.openFolderInNewWindow',
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickFolderAndOpen({ forceNewWindow: true, allowLocalPaths: true })
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickFolderAndOpen({ forceNewWindow: true })
});
CommandsRegistry.registerCommand({
id: 'workbench.action.files.openFileInNewWindow',
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickFileAndOpen({ forceNewWindow: true, allowLocalPaths: true })
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickFileAndOpen({ forceNewWindow: true })
});
CommandsRegistry.registerCommand({
id: 'workbench.action.openWorkspaceInNewWindow',
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickWorkspaceAndOpen({ forceNewWindow: true, allowLocalPaths: true })
handler: (accessor: ServicesAccessor) => accessor.get(IFileDialogService).pickWorkspaceAndOpen({ forceNewWindow: true })
});
CommandsRegistry.registerCommand({
......
......@@ -17,7 +17,6 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import * as resources from 'vs/base/common/resources';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { RemoteFileDialog } from 'vs/workbench/services/dialogs/electron-browser/remoteFileDialog';
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
......@@ -165,8 +164,7 @@ export class FileDialogService implements IFileDialogService {
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@IHistoryService private readonly historyService: IHistoryService,
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IFileService private readonly fileService: IFileService
@IInstantiationService private readonly instantiationService: IInstantiationService
) { }
defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
......@@ -209,10 +207,6 @@ export class FileDialogService implements IFileDialogService {
return this.defaultFolderPath(schemeFilter);
}
private getSchemeFilterForWindow() {
return !this.windowService.getConfiguration().remoteAuthority ? Schemas.file : REMOTE_HOST_SCHEME;
}
private toNativeOpenDialogOptions(options: IPickAndOpenOptions): INativeOpenDialogOptions {
return {
forceNewWindow: options.forceNewWindow,
......@@ -224,57 +218,66 @@ export class FileDialogService implements IFileDialogService {
}
pickFileFolderAndOpen(options: IPickAndOpenOptions): Promise<any> {
let defaultUri = options.defaultUri;
if (!defaultUri) {
defaultUri = options.defaultUri = this.defaultFilePath();
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFilePath(schema);
}
if (this.useRemoteDialogs(defaultUri)) {
if (schema !== Schemas.file) {
const title = nls.localize('openFileOrFolder.title', 'Open File Or Folder');
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: true, canSelectMany: false, defaultUri, title, allowLocalPaths: options.allowLocalPaths }, options.forceNewWindow, true);
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems }, options.forceNewWindow, true);
}
return this.windowService.pickFileFolderAndOpen(this.toNativeOpenDialogOptions(options));
}
pickFileAndOpen(options: IPickAndOpenOptions): Promise<any> {
let defaultUri = options.defaultUri;
if (!defaultUri) {
defaultUri = options.defaultUri = this.defaultFilePath();
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFilePath(schema);
}
if (this.useRemoteDialogs(defaultUri)) {
if (schema !== Schemas.file) {
const title = nls.localize('openFile.title', 'Open File');
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri, title, allowLocalPaths: options.allowLocalPaths }, options.forceNewWindow, true);
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems }, options.forceNewWindow, true);
}
return this.windowService.pickFileAndOpen(this.toNativeOpenDialogOptions(options));
}
pickFolderAndOpen(options: IPickAndOpenOptions): Promise<any> {
let defaultUri = options.defaultUri;
if (!defaultUri) {
defaultUri = options.defaultUri = this.defaultFolderPath();
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFolderPath(schema);
}
if (this.useRemoteDialogs(defaultUri)) {
if (schema !== Schemas.file) {
const title = nls.localize('openFolder.title', 'Open Folder');
return this.pickRemoteResourceAndOpen({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri, title, allowLocalPaths: options.allowLocalPaths }, options.forceNewWindow, false);
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
return this.pickRemoteResourceAndOpen({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems }, options.forceNewWindow, false);
}
return this.windowService.pickFolderAndOpen(this.toNativeOpenDialogOptions(options));
}
pickWorkspaceAndOpen(options: IPickAndOpenOptions): Promise<void> {
let defaultUri = options.defaultUri;
if (!defaultUri) {
defaultUri = options.defaultUri = this.defaultWorkspacePath();
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultWorkspacePath(schema);
}
if (this.useRemoteDialogs(defaultUri)) {
if (schema !== Schemas.file) {
const title = nls.localize('openWorkspace.title', 'Open Workspace');
const filters: FileFilter[] = [{ name: nls.localize('filterName.workspace', 'Workspace'), extensions: [WORKSPACE_EXTENSION] }];
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri, title, filters, allowLocalPaths: options.allowLocalPaths }, options.forceNewWindow, false);
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, filters, availableFileSystems }, options.forceNewWindow, false);
}
return this.windowService.pickWorkspaceAndOpen(this.toNativeOpenDialogOptions(options));
......@@ -290,8 +293,8 @@ export class FileDialogService implements IFileDialogService {
}
showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
const defaultUri = options.defaultUri;
if (this.useRemoteDialogs(defaultUri)) {
const schema = this.getFileSystemSchema(options);
if (schema !== Schemas.file) {
return this.saveRemoteResource(options);
}
......@@ -305,13 +308,15 @@ export class FileDialogService implements IFileDialogService {
}
showOpenDialog(options: IOpenDialogOptions): Promise<URI[] | undefined> {
const defaultUri = options.defaultUri;
if (this.useRemoteDialogs(defaultUri)) {
const schema = this.getFileSystemSchema(options);
if (schema !== Schemas.file) {
return this.pickRemoteResource(options).then(urisToOpen => {
return urisToOpen && urisToOpen.map(uto => uto.uri);
});
}
const defaultUri = options.defaultUri;
const newOptions: OpenDialogOptions = {
title: options.title,
defaultPath: defaultUri && defaultUri.fsPath,
......@@ -356,12 +361,12 @@ export class FileDialogService implements IFileDialogService {
return remoteFileDialog.showSaveDialog(options);
}
private useRemoteDialogs(defaultUri: URI) {
if (defaultUri) {
return defaultUri.scheme !== Schemas.file && this.fileService.canHandleResource(defaultUri);
} else {
return !!this.windowService.getConfiguration().remoteAuthority;
}
private getSchemeFilterForWindow() {
return !this.windowService.getConfiguration().remoteAuthority ? Schemas.file : REMOTE_HOST_SCHEME;
}
private getFileSystemSchema(options: { availableFileSystems?: string[], defaultUri?: URI }): string {
return options.availableFileSystems && options.availableFileSystems[0] || options.defaultUri && options.defaultUri.scheme || this.getSchemeFilterForWindow();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册