提交 af00f974 编写于 作者: B Benjamin Pasero

debt - temporary allow IElectronService in file dialog service

上级 d58aa5eb
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { IWindowService, INativeOpenDialogOptions, OpenDialogOptions, IURIToOpen, FileFilter } from 'vs/platform/windows/common/windows'; import { IWindowService, INativeOpenDialogOptions, OpenDialogOptions, IURIToOpen, FileFilter, SaveDialogOptions } from 'vs/platform/windows/common/windows';
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IHistoryService } from 'vs/workbench/services/history/common/history';
...@@ -12,7 +12,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/ ...@@ -12,7 +12,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
import * as resources from 'vs/base/common/resources'; import * as resources from 'vs/base/common/resources';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation';
import { RemoteFileDialog } from 'vs/workbench/services/dialogs/browser/remoteFileDialog'; import { RemoteFileDialog } from 'vs/workbench/services/dialogs/browser/remoteFileDialog';
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces'; import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts'; import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
...@@ -22,6 +22,10 @@ import { IFileService } from 'vs/platform/files/common/files'; ...@@ -22,6 +22,10 @@ import { IFileService } from 'vs/platform/files/common/files';
import { isWeb } from 'vs/base/common/platform'; import { isWeb } from 'vs/base/common/platform';
import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IOpenerService } from 'vs/platform/opener/common/opener';
// TODO@Alex layer breaker
// tslint:disable-next-line: layering import-patterns
import { IElectronService } from 'vs/platform/electron/node/electron';
export class FileDialogService implements IFileDialogService { export class FileDialogService implements IFileDialogService {
_serviceBrand: undefined; _serviceBrand: undefined;
...@@ -34,7 +38,8 @@ export class FileDialogService implements IFileDialogService { ...@@ -34,7 +38,8 @@ export class FileDialogService implements IFileDialogService {
@IInstantiationService private readonly instantiationService: IInstantiationService, @IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService, @IConfigurationService private readonly configurationService: IConfigurationService,
@IFileService private readonly fileService: IFileService, @IFileService private readonly fileService: IFileService,
@IOpenerService private readonly openerService: IOpenerService @IOpenerService private readonly openerService: IOpenerService,
@optional(IElectronService) private readonly electronService: IElectronService
) { } ) { }
defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined { defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
...@@ -217,15 +222,17 @@ export class FileDialogService implements IFileDialogService { ...@@ -217,15 +222,17 @@ export class FileDialogService implements IFileDialogService {
return this.saveRemoteResource(options); return this.saveRemoteResource(options);
} }
const result = await this.windowService.showSaveDialog(this.toNativeSaveDialogOptions(options)); if (this.electronService) {
if (result) { const result = await this.electronService.showSaveDialog(this.toNativeSaveDialogOptions(options));
return URI.file(result); if (result && result.filePath) {
return URI.file(result.filePath);
}
} }
return; return;
} }
private toNativeSaveDialogOptions(options: ISaveDialogOptions): Electron.SaveDialogOptions { private toNativeSaveDialogOptions(options: ISaveDialogOptions): SaveDialogOptions {
options.defaultUri = options.defaultUri ? URI.file(options.defaultUri.path) : undefined; options.defaultUri = options.defaultUri ? URI.file(options.defaultUri.path) : undefined;
return { return {
defaultPath: options.defaultUri && options.defaultUri.fsPath, defaultPath: options.defaultUri && options.defaultUri.fsPath,
...@@ -245,9 +252,11 @@ export class FileDialogService implements IFileDialogService { ...@@ -245,9 +252,11 @@ export class FileDialogService implements IFileDialogService {
return this.saveRemoteResource(options); return this.saveRemoteResource(options);
} }
const result = await this.windowService.showSaveDialog(this.toNativeSaveDialogOptions(options)); if (this.electronService) {
if (result) { const result = await this.electronService.showSaveDialog(this.toNativeSaveDialogOptions(options));
return URI.file(result); if (result && result.filePath) {
return URI.file(result.filePath);
}
} }
return; return;
...@@ -289,9 +298,13 @@ export class FileDialogService implements IFileDialogService { ...@@ -289,9 +298,13 @@ export class FileDialogService implements IFileDialogService {
newOptions.properties!.push('multiSelections'); newOptions.properties!.push('multiSelections');
} }
const result = await this.windowService.showOpenDialog(newOptions); if (this.electronService) {
const result = await this.electronService.showOpenDialog(newOptions);
return result ? result.map(URI.file) : undefined; return result && result.filePaths ? result.filePaths.map(URI.file) : undefined;
}
return;
} }
private pickRemoteResource(options: IOpenDialogOptions): Promise<URI | undefined> { private pickRemoteResource(options: IOpenDialogOptions): Promise<URI | undefined> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册