Skip to content

Commit

Permalink
Add default properties to electron OpenDialog
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Moran <rob.moran@arm.com>
  • Loading branch information
thegecko committed Feb 25, 2020
1 parent c1bd96f commit 68e8e24
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 };
}
Expand Down Expand Up @@ -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<DialogProperties> {
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<DialogProperties> = [];
if (!isOSX) {
if (props.canSelectFiles !== false && props.canSelectFolders !== true) {
properties.push('openFile');
Expand All @@ -167,6 +172,7 @@ export namespace electron {
}
if (props.canSelectFolders === true) {
properties.push('openDirectory');
properties.push('createDirectory');
}
}
if (props.canSelectMany === true) {
Expand Down

0 comments on commit 68e8e24

Please sign in to comment.