From 891e6843e8ceabf5178c50935fb1daf587003eee Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 21 Aug 2017 10:35:11 +0200 Subject: [PATCH] first cut of option-less open, #13807 --- src/vs/vscode.proposed.d.ts | 5 +++ .../extensionHost.contribution.ts | 1 + .../api/electron-browser/mainThreadDialogs.ts | 37 +++++++++++++++++++ src/vs/workbench/api/node/extHost.api.impl.ts | 5 +++ src/vs/workbench/api/node/extHost.protocol.ts | 5 +++ src/vs/workbench/api/node/extHostDialogs.ts | 26 +++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 src/vs/workbench/api/electron-browser/mainThreadDialogs.ts create mode 100644 src/vs/workbench/api/node/extHostDialogs.ts diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index ab976f0f57bd6..8b4a96fc1453d 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -7,6 +7,11 @@ declare module 'vscode' { + export namespace window { + + export function showOpenDialog(): Thenable; + } + // todo@joh discover files etc export interface FileSystemProvider { // todo@joh -> added, deleted, renamed, changed diff --git a/src/vs/workbench/api/electron-browser/extensionHost.contribution.ts b/src/vs/workbench/api/electron-browser/extensionHost.contribution.ts index 338de5a1b0468..703c996da2e5d 100644 --- a/src/vs/workbench/api/electron-browser/extensionHost.contribution.ts +++ b/src/vs/workbench/api/electron-browser/extensionHost.contribution.ts @@ -20,6 +20,7 @@ import './mainThreadConfiguration'; import './mainThreadCredentials'; import './mainThreadDebugService'; import './mainThreadDiagnostics'; +import './mainThreadDialogs'; import './mainThreadDocumentContentProviders'; import './mainThreadDocuments'; import './mainThreadDocumentsAndEditors'; diff --git a/src/vs/workbench/api/electron-browser/mainThreadDialogs.ts b/src/vs/workbench/api/electron-browser/mainThreadDialogs.ts new file mode 100644 index 0000000000000..11a3bf5a2039e --- /dev/null +++ b/src/vs/workbench/api/electron-browser/mainThreadDialogs.ts @@ -0,0 +1,37 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { TPromise } from 'vs/base/common/winjs.base'; +import { isFalsyOrEmpty } from 'vs/base/common/arrays'; +import { MainThreadDiaglogsShape, MainContext, IExtHostContext } from '../node/extHost.protocol'; +import { extHostNamedCustomer } from "vs/workbench/api/electron-browser/extHostCustomers"; +import { IWindowService } from "vs/platform/windows/common/windows"; + +@extHostNamedCustomer(MainContext.MainThreadDialogs) +export class MainThreadDialogs implements MainThreadDiaglogsShape { + + constructor( + context: IExtHostContext, + @IWindowService private readonly _windowService: IWindowService + ) { + // + } + + dispose(): void { + // + } + + $showOpenDialog(): TPromise { + return new TPromise(resolve => { + this._windowService.showOpenDialog({ + + }, filenames => { + // TODO@joh what about remote dev setup? + resolve(isFalsyOrEmpty(filenames) ? undefined : filenames); + }); + }); + } +} diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index c410c99b2020f..040952f58f7a8 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -52,6 +52,7 @@ import * as languageConfiguration from 'vs/editor/common/modes/languageConfigura import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions'; import { ExtHostThreadService } from "vs/workbench/services/thread/node/extHostThreadService"; import { ProxyIdentifier } from "vs/workbench/services/thread/common/threadService"; +import { ExtHostDialogs } from "vs/workbench/api/node/extHostDialogs"; export interface IExtensionApiFactory { (extension: IExtensionDescription): typeof vscode; @@ -105,6 +106,7 @@ export function createApiFactory( // Other instances const extHostMessageService = new ExtHostMessageService(threadService); + const extHostDialogs = new ExtHostDialogs(threadService); const extHostStatusBar = new ExtHostStatusBar(threadService); const extHostProgress = new ExtHostProgress(threadService.get(MainContext.MainThreadProgress)); const extHostOutputService = new ExtHostOutputService(threadService); @@ -368,6 +370,9 @@ export function createApiFactory( sampleFunction: proposedApiFunction(extension, () => { return extHostMessageService.showMessage(extension.id, Severity.Info, 'Hello Proposed Api!', {}, []); }), + showOpenDialog: proposedApiFunction(extension, () => { + return extHostDialogs.showOpenDialog(); + }) }; // namespace: workspace diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index a653f9d00b2aa..beb06f12cf549 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -113,6 +113,10 @@ export interface MainThreadDiagnosticsShape extends IDisposable { $clear(owner: string): TPromise; } +export interface MainThreadDiaglogsShape extends IDisposable { + $showOpenDialog(): TPromise; +} + export interface MainThreadDocumentContentProvidersShape extends IDisposable { $registerTextContentProvider(handle: number, scheme: string): void; $unregisterTextContentProvider(handle: number): void; @@ -532,6 +536,7 @@ export const MainContext = { MainThreadConfiguration: createMainId('MainThreadConfiguration'), MainThreadDebugService: createMainId('MainThreadDebugService'), MainThreadDiagnostics: createMainId('MainThreadDiagnostics'), + MainThreadDialogs: createMainId('MainThreadDiaglogs'), MainThreadDocuments: createMainId('MainThreadDocuments'), MainThreadDocumentContentProviders: createMainId('MainThreadDocumentContentProviders'), MainThreadEditors: createMainId('MainThreadEditors'), diff --git a/src/vs/workbench/api/node/extHostDialogs.ts b/src/vs/workbench/api/node/extHostDialogs.ts new file mode 100644 index 0000000000000..727bf8b3495f8 --- /dev/null +++ b/src/vs/workbench/api/node/extHostDialogs.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { MainContext, MainThreadDiaglogsShape, IMainContext } from 'vs/workbench/api/node/extHost.protocol'; +import URI from "vs/base/common/uri"; + +export class ExtHostDialogs { + + private readonly _proxy: MainThreadDiaglogsShape; + + constructor(mainContext: IMainContext) { + this._proxy = mainContext.get(MainContext.MainThreadDialogs); + } + + showOpenDialog(): Thenable { + return this._proxy.$showOpenDialog().then(filepaths => { + if (!filepaths) { + return undefined; + } + return filepaths.map(URI.file); + }); + } +}