Skip to content

Commit

Permalink
expose some of the open-options, #13807
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 22, 2017
1 parent beb033f commit 49784f8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
9 changes: 8 additions & 1 deletion src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

declare module 'vscode' {

export interface OpenDialogOptions {
uri: Uri;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
}

export namespace window {

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

// todo@joh discover files etc
Expand Down
38 changes: 32 additions & 6 deletions src/vs/workbench/api/electron-browser/mainThreadDialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { TPromise } from 'vs/base/common/winjs.base';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { MainThreadDiaglogsShape, MainContext, IExtHostContext } from '../node/extHost.protocol';
import { MainThreadDiaglogsShape, MainContext, IExtHostContext, MainThreadDialogOptions } from '../node/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { IWindowService } from 'vs/platform/windows/common/windows';

Expand All @@ -24,14 +24,40 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {
//
}

$showOpenDialog(): TPromise<string[]> {
$showOpenDialog(options: MainThreadDialogOptions): TPromise<string[]> {
// TODO@joh what about remote dev setup?
if (options.uri && options.uri.scheme !== 'file') {
return TPromise.wrapError(new Error('bad path'));
}
return new TPromise<string[]>(resolve => {
this._windowService.showOpenDialog({

}, filenames => {
// TODO@joh what about remote dev setup?
this._windowService.showOpenDialog(MainThreadDialogs._convertOptions(options), filenames => {
resolve(isFalsyOrEmpty(filenames) ? undefined : filenames);
});
});
}

private static _convertOptions(options: MainThreadDialogOptions): Electron.OpenDialogOptions {
const result: Electron.OpenDialogOptions = {
properties: ['createDirectory']
};
if (options.openLabel) {
result.buttonLabel = options.openLabel;
}
if (options.uri) {
result.defaultPath = options.uri.fsPath;
}
if (!options.openFiles && !options.openFolders) {
options.openFiles = true;
}
if (options.openFiles) {
result.properties.push('openFile');
}
if (options.openFolders) {
result.properties.push('openDirectory');
}
if (options.openMany) {
result.properties.push('multiSelections');
}
return result;
}
}
4 changes: 2 additions & 2 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ export function createApiFactory(
sampleFunction: proposedApiFunction(extension, () => {
return extHostMessageService.showMessage(extension, Severity.Info, 'Hello Proposed Api!', {}, []);
}),
showOpenDialog: proposedApiFunction(extension, () => {
return extHostDialogs.showOpenDialog();
showOpenDialog: proposedApiFunction(extension, options => {
return extHostDialogs.showOpenDialog(options);
})
};

Expand Down
10 changes: 9 additions & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ export interface MainThreadDiagnosticsShape extends IDisposable {
$clear(owner: string): TPromise<any>;
}

export interface MainThreadDialogOptions {
uri?: URI;
openLabel?: string;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
}

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

export interface MainThreadDocumentContentProvidersShape extends IDisposable {
Expand Down
12 changes: 5 additions & 7 deletions src/vs/workbench/api/node/extHostDialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { MainContext, MainThreadDiaglogsShape, IMainContext } from 'vs/workbench/api/node/extHost.protocol';
import * as vscode from 'vscode';
import URI from 'vs/base/common/uri';
import { MainContext, MainThreadDiaglogsShape, IMainContext } from 'vs/workbench/api/node/extHost.protocol';

export class ExtHostDialogs {

Expand All @@ -15,12 +16,9 @@ export class ExtHostDialogs {
this._proxy = mainContext.get(MainContext.MainThreadDialogs);
}

showOpenDialog(): Thenable<URI[]> {
return this._proxy.$showOpenDialog().then(filepaths => {
if (!filepaths) {
return undefined;
}
return filepaths.map(URI.file);
showOpenDialog(options: vscode.OpenDialogOptions): Thenable<URI[]> {
return this._proxy.$showOpenDialog(<any>options).then(filepaths => {
return filepaths && filepaths.map(URI.file);
});
}
}

0 comments on commit 49784f8

Please sign in to comment.