Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[electron] Add ability to create folder in OpenDialog on MacOS #7208

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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