mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-24 17:23:05 -05:00
* Initial 1.19 xcopy * Fix yarn build * Fix numerous build breaks * Next batch of build break fixes * More build break fixes * Runtime breaks * Additional post merge fixes * Fix windows setup file * Fix test failures. * Update license header blocks to refer to source eula
101 lines
3.4 KiB
TypeScript
101 lines
3.4 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. 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, 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 {
|
|
|
|
constructor(
|
|
context: IExtHostContext,
|
|
@IWindowService private readonly _windowService: IWindowService
|
|
) {
|
|
//
|
|
}
|
|
|
|
dispose(): void {
|
|
//
|
|
}
|
|
|
|
$showOpenDialog(options: MainThreadDialogOpenOptions): TPromise<string[]> {
|
|
// TODO@joh what about remote dev setup?
|
|
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 => {
|
|
const filenames = this._windowService.showOpenDialog(
|
|
MainThreadDialogs._convertOpenOptions(options)
|
|
);
|
|
|
|
resolve(isFalsyOrEmpty(filenames) ? undefined : filenames);
|
|
});
|
|
}
|
|
|
|
$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 => {
|
|
const filename = this._windowService.showSaveDialog(
|
|
MainThreadDialogs._convertSaveOptions(options)
|
|
);
|
|
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.defaultUri) {
|
|
result.defaultPath = options.defaultUri.fsPath;
|
|
}
|
|
if (!options.canSelectFiles && !options.canSelectFolders) {
|
|
options.canSelectFiles = true;
|
|
}
|
|
if (options.canSelectFiles) {
|
|
result.properties.push('openFile');
|
|
}
|
|
if (options.canSelectFolders) {
|
|
result.properties.push('openDirectory');
|
|
}
|
|
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;
|
|
}
|
|
}
|