Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -6,9 +6,10 @@
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';
import { forEach } from 'vs/base/common/collections';
@extHostNamedCustomer(MainContext.MainThreadDialogs)
export class MainThreadDialogs implements MainThreadDiaglogsShape {
@@ -24,40 +25,75 @@ 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') {
return TPromise.wrapError(new Error('bad path'));
if (options.defaultUri && options.defaultUri.scheme !== 'file') {
return TPromise.wrapError(new Error('Not supported - Open-dialogs can only be opened on `file`-uris.'));
}
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.defaultUri && options.defaultUri.scheme !== 'file') {
return TPromise.wrapError(new Error('Not supported - Save-dialogs can only be opened on `file`-uris.'));
}
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.defaultUri) {
result.defaultPath = options.defaultUri.fsPath;
}
if (!options.openFiles && !options.openFolders) {
options.openFiles = true;
if (!options.canSelectFiles && !options.canSelectFolders) {
options.canSelectFiles = true;
}
if (options.openFiles) {
if (options.canSelectFiles) {
result.properties.push('openFile');
}
if (options.openFolders) {
if (options.canSelectFolders) {
result.properties.push('openDirectory');
}
if (options.openMany) {
if (options.canSelectMany) {
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.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;
}
}