From 68e8e2411c1a424d1b71a4b01779a1f5b1b0c4cd Mon Sep 17 00:00:00 2001 From: Rob Moran Date: Mon, 24 Feb 2020 22:19:13 +0000 Subject: [PATCH] Add default properties to electron OpenDialog Signed-off-by: Rob Moran --- .../file-dialog/electron-file-dialog-service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts b/packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts index 6aa3985eda367..99203100b79a7 100644 --- a/packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts +++ b/packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts @@ -24,6 +24,11 @@ import { FileStat } from '../../common'; import { FileAccess } from '../../common/filesystem'; import { DefaultFileDialogService, OpenFileDialogProps, SaveFileDialogProps } from '../../browser/file-dialog'; +// See https://github.com/electron/electron/blob/v4.2.12/docs/api/dialog.md +// These properties get extended with newer versions of Electron +type DialogProperties = 'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | + 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory'; + // // We are OK to use this here because the electron backend and frontend are on the same host. // If required, we can move this single service (and its module) to a dedicated Theia extension, @@ -102,7 +107,7 @@ export class ElectronFileDialogService extends DefaultFileDialogService { } protected toOpenDialogOptions(uri: URI, props: OpenFileDialogProps): OpenDialogOptions { - const properties: Array<'openFile' | 'openDirectory' | 'multiSelections'> = electron.dialog.toDialogProperties(props); + const properties = electron.dialog.toDialogProperties(props); const buttonLabel = props.openLabel; return { ...this.toDialogOptions(uri, props, 'Open'), properties, buttonLabel }; } @@ -149,11 +154,11 @@ export namespace electron { * * See: https://github.com/electron/electron/issues/10252#issuecomment-322012159 */ - export function toDialogProperties(props: OpenFileDialogProps): Array<'openFile' | 'openDirectory' | 'multiSelections'> { + export function toDialogProperties(props: OpenFileDialogProps): Array { if (!isOSX && props.canSelectFiles !== false && props.canSelectFolders === true) { throw new Error(`Illegal props. Cannot have 'canSelectFiles' and 'canSelectFolders' at the same times. Props was: ${JSON.stringify(props)}.`); } - const properties: Array<'openFile' | 'openDirectory' | 'multiSelections'> = []; + const properties: Array = []; if (!isOSX) { if (props.canSelectFiles !== false && props.canSelectFolders !== true) { properties.push('openFile'); @@ -167,6 +172,7 @@ export namespace electron { } if (props.canSelectFolders === true) { properties.push('openDirectory'); + properties.push('createDirectory'); } } if (props.canSelectMany === true) {