提交 a731263d 编写于 作者: J Johannes Rieken

also add showSaveDialog-api, #13807

上级 550e32ea
......@@ -8,15 +8,21 @@
declare module 'vscode' {
export interface OpenDialogOptions {
uri?: Uri;
defaultResource?: Uri;
openLabel?: string;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
}
export namespace window {
export interface SaveDialogOptions {
defaultResource?: Uri;
saveLabel?: string;
}
export namespace window {
export function showOpenDialog(options: OpenDialogOptions): Thenable<Uri[]>;
export function showSaveDialog(options: OpenDialogOptions): Thenable<Uri>;
}
// todo@joh discover files etc
......
......@@ -6,7 +6,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { MainThreadDiaglogsShape, MainContext, IExtHostContext, MainThreadDialogOptions } from '../node/extHost.protocol';
import { MainThreadDiaglogsShape, MainContext, IExtHostContext, MainThreadDialogOpenOptions, MainThreadDialogSaveOptions } from '../node/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { IWindowService } from 'vs/platform/windows/common/windows';
......@@ -24,27 +24,41 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {
//
}
$showOpenDialog(options: MainThreadDialogOptions): TPromise<string[]> {
$showOpenDialog(options: MainThreadDialogOpenOptions): TPromise<string[]> {
// TODO@joh what about remote dev setup?
if (options.uri && options.uri.scheme !== 'file') {
if (options.defaultResource && options.defaultResource.scheme !== 'file') {
return TPromise.wrapError(new Error('bad path'));
}
return new TPromise<string[]>(resolve => {
this._windowService.showOpenDialog(MainThreadDialogs._convertOptions(options), filenames => {
resolve(isFalsyOrEmpty(filenames) ? undefined : filenames);
});
this._windowService.showOpenDialog(
MainThreadDialogs._convertOpenOptions(options),
filenames => resolve(isFalsyOrEmpty(filenames) ? undefined : filenames)
);
});
}
private static _convertOptions(options: MainThreadDialogOptions): Electron.OpenDialogOptions {
$showSaveDialog(options: MainThreadDialogSaveOptions): TPromise<string> {
// TODO@joh what about remote dev setup?
if (options.defaultResource && options.defaultResource.scheme !== 'file') {
return TPromise.wrapError(new Error('bad path'));
}
return new TPromise<string>(resolve => {
this._windowService.showSaveDialog(
MainThreadDialogs._convertSaveOptions(options),
filename => resolve(!filename ? undefined : filename)
);
});
}
private static _convertOpenOptions(options: MainThreadDialogOpenOptions): 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.defaultResource) {
result.defaultPath = options.defaultResource.fsPath;
}
if (!options.openFiles && !options.openFolders) {
options.openFiles = true;
......@@ -60,4 +74,17 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {
}
return result;
}
private static _convertSaveOptions(options: MainThreadDialogSaveOptions): Electron.SaveDialogOptions {
const result: Electron.SaveDialogOptions = {
};
if (options.defaultResource) {
result.defaultPath = options.defaultResource.fsPath;
}
if (options.saveLabel) {
result.buttonLabel = options.saveLabel;
}
return result;
}
}
......@@ -382,6 +382,9 @@ export function createApiFactory(
}),
showOpenDialog: proposedApiFunction(extension, options => {
return extHostDialogs.showOpenDialog(options);
}),
showSaveDialog: proposedApiFunction(extension, options => {
return extHostDialogs.showSaveDialog(options);
})
};
......
......@@ -114,16 +114,22 @@ export interface MainThreadDiagnosticsShape extends IDisposable {
$clear(owner: string): TPromise<any>;
}
export interface MainThreadDialogOptions {
uri?: URI;
export interface MainThreadDialogOpenOptions {
defaultResource?: URI;
openLabel?: string;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
}
export interface MainThreadDialogSaveOptions {
defaultResource?: URI;
saveLabel?: string;
}
export interface MainThreadDiaglogsShape extends IDisposable {
$showOpenDialog(options: MainThreadDialogOptions): TPromise<string[]>;
$showOpenDialog(options: MainThreadDialogOpenOptions): TPromise<string[]>;
$showSaveDialog(options: MainThreadDialogSaveOptions): TPromise<string>;
}
export interface MainThreadDocumentContentProvidersShape extends IDisposable {
......
......@@ -21,4 +21,10 @@ export class ExtHostDialogs {
return filepaths && filepaths.map(URI.file);
});
}
showSaveDialog(options: vscode.SaveDialogOptions): Thenable<URI> {
return this._proxy.$showSaveDialog(<any>options).then(filepath => {
return filepath && URI.file(filepath);
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册