Skip to content

Commit

Permalink
first cut of option-less open, #13807
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 21, 2017
1 parent d51605b commit 891e684
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

declare module 'vscode' {

export namespace window {

export function showOpenDialog(): Thenable<Uri[]>;
}

// todo@joh discover files etc
export interface FileSystemProvider {
// todo@joh -> added, deleted, renamed, changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './mainThreadConfiguration';
import './mainThreadCredentials';
import './mainThreadDebugService';
import './mainThreadDiagnostics';
import './mainThreadDialogs';
import './mainThreadDocumentContentProviders';
import './mainThreadDocuments';
import './mainThreadDocumentsAndEditors';
Expand Down
37 changes: 37 additions & 0 deletions src/vs/workbench/api/electron-browser/mainThreadDialogs.ts
Original file line number Diff line number Diff line change
@@ -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<string[]> {
return new TPromise<string[]>(resolve => {
this._windowService.showOpenDialog({

}, filenames => {
// TODO@joh what about remote dev setup?
resolve(isFalsyOrEmpty(filenames) ? undefined : filenames);
});
});
}
}
5 changes: 5 additions & 0 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export interface MainThreadDiagnosticsShape extends IDisposable {
$clear(owner: string): TPromise<any>;
}

export interface MainThreadDiaglogsShape extends IDisposable {
$showOpenDialog(): TPromise<string[]>;
}

export interface MainThreadDocumentContentProvidersShape extends IDisposable {
$registerTextContentProvider(handle: number, scheme: string): void;
$unregisterTextContentProvider(handle: number): void;
Expand Down Expand Up @@ -532,6 +536,7 @@ export const MainContext = {
MainThreadConfiguration: createMainId<MainThreadConfigurationShape>('MainThreadConfiguration'),
MainThreadDebugService: createMainId<MainThreadDebugServiceShape>('MainThreadDebugService'),
MainThreadDiagnostics: createMainId<MainThreadDiagnosticsShape>('MainThreadDiagnostics'),
MainThreadDialogs: createMainId<MainThreadDiaglogsShape>('MainThreadDiaglogs'),
MainThreadDocuments: createMainId<MainThreadDocumentsShape>('MainThreadDocuments'),
MainThreadDocumentContentProviders: createMainId<MainThreadDocumentContentProvidersShape>('MainThreadDocumentContentProviders'),
MainThreadEditors: createMainId<MainThreadEditorsShape>('MainThreadEditors'),
Expand Down
26 changes: 26 additions & 0 deletions src/vs/workbench/api/node/extHostDialogs.ts
Original file line number Diff line number Diff line change
@@ -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<URI[]> {
return this._proxy.$showOpenDialog().then(filepaths => {
if (!filepaths) {
return undefined;
}
return filepaths.map(URI.file);
});
}
}

0 comments on commit 891e684

Please sign in to comment.