Skip to content

Commit

Permalink
add filters, #13807
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 21, 2017
1 parent ad4b098 commit c7630e1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
declare module 'vscode' {

export interface OpenDialogOptions {
defaultResource?: Uri;
defaultUri?: Uri;
openLabel?: string;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
filters: { [name: string]: string[] };
}

export interface SaveDialogOptions {
defaultResource?: Uri;
defaultUri?: Uri;
saveLabel?: string;
filters: { [name: string]: string[] };
}

export namespace window {
Expand Down Expand Up @@ -228,4 +230,4 @@ declare module 'vscode' {
export namespace languages {
export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable;
}
}
}
21 changes: 15 additions & 6 deletions src/vs/workbench/api/electron-browser/mainThreadDialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isFalsyOrEmpty } from 'vs/base/common/arrays';
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';
import { forEach } from 'vs/base/common/collections';

@extHostNamedCustomer(MainContext.MainThreadDialogs)
export class MainThreadDialogs implements MainThreadDiaglogsShape {
Expand All @@ -26,7 +27,7 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {

$showOpenDialog(options: MainThreadDialogOpenOptions): TPromise<string[]> {
// TODO@joh what about remote dev setup?
if (options.defaultResource && options.defaultResource.scheme !== 'file') {
if (options.defaultUri && options.defaultUri.scheme !== 'file') {
return TPromise.wrapError(new Error('bad path'));
}
return new TPromise<string[]>(resolve => {
Expand All @@ -39,7 +40,7 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {

$showSaveDialog(options: MainThreadDialogSaveOptions): TPromise<string> {
// TODO@joh what about remote dev setup?
if (options.defaultResource && options.defaultResource.scheme !== 'file') {
if (options.defaultUri && options.defaultUri.scheme !== 'file') {
return TPromise.wrapError(new Error('bad path'));
}
return new TPromise<string>(resolve => {
Expand All @@ -57,8 +58,8 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {
if (options.openLabel) {
result.buttonLabel = options.openLabel;
}
if (options.defaultResource) {
result.defaultPath = options.defaultResource.fsPath;
if (options.defaultUri) {
result.defaultPath = options.defaultUri.fsPath;
}
if (!options.openFiles && !options.openFolders) {
options.openFiles = true;
Expand All @@ -72,19 +73,27 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {
if (options.openMany) {
result.properties.push('multiSelections');
}
if (options.filters) {
result.filters = [];
forEach(options.filters, entry => result.filters.push({ name: entry.key, extensions: entry.value }));
}
return result;
}

private static _convertSaveOptions(options: MainThreadDialogSaveOptions): Electron.SaveDialogOptions {
const result: Electron.SaveDialogOptions = {

};
if (options.defaultResource) {
result.defaultPath = options.defaultResource.fsPath;
if (options.defaultUri) {
result.defaultPath = options.defaultUri.fsPath;
}
if (options.saveLabel) {
result.buttonLabel = options.saveLabel;
}
if (options.filters) {
result.filters = [];
forEach(options.filters, entry => result.filters.push({ name: entry.key, extensions: entry.value }));
}
return result;
}
}
6 changes: 4 additions & 2 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,18 @@ export interface MainThreadDiagnosticsShape extends IDisposable {
}

export interface MainThreadDialogOpenOptions {
defaultResource?: URI;
defaultUri?: URI;
openLabel?: string;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
filters: { [name: string]: string[] };
}

export interface MainThreadDialogSaveOptions {
defaultResource?: URI;
defaultUri?: URI;
saveLabel?: string;
filters: { [name: string]: string[] };
}

export interface MainThreadDiaglogsShape extends IDisposable {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/node/extHostDialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export class ExtHostDialogs {
}

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

showSaveDialog(options: vscode.SaveDialogOptions): Thenable<URI> {
return this._proxy.$showSaveDialog(<any>options).then(filepath => {
return this._proxy.$showSaveDialog(options).then(filepath => {
return filepath && URI.file(filepath);
});
}
Expand Down

0 comments on commit c7630e1

Please sign in to comment.