Skip to content

Commit

Permalink
electron: fix 'save as...' cwd
Browse files Browse the repository at this point in the history
The following commit fixes the `defaultPath` when performing a `save
as...` in `electron`. Previously, the `defaultPath` was incorrect
leading the dialog to always open where the application started. With
these changes, the dialog will open at the current location where the
`save as...` is performed.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Feb 26, 2021
1 parent 8d5e12a commit 41118c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@ export class DefaultFileDialogService implements FileDialogService {
resource: new URI(await this.environments.getHomeDirUri()),
isDirectory: true
};
if (folder) {
const folderUri = folder.resource;
const rootUri = folder.isDirectory ? folderUri : folderUri.parent;
try {
const rootStat = await this.fileService.resolve(rootUri);
return DirNode.createRoot(rootStat);
} catch { }
}
const folderUri = folder.resource;
const rootUri = folder.isDirectory ? folderUri : folderUri.parent;
try {
const rootStat = await this.fileService.resolve(rootUri);
return DirNode.createRoot(rootStat);
} catch { }
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
return undefined;
}

async showSaveDialog(props: SaveFileDialogProps, folder?: FileStat): Promise<URI | undefined> {
const rootNode = await this.getRootNode(folder);
if (rootNode) {
const { filePath } = await remote.dialog.showSaveDialog(this.toSaveDialogOptions(rootNode.uri, props));
async showSaveDialog(props: SaveFileDialogProps, fileOrFolder?: FileStat): Promise<URI | undefined> {
let resource = undefined;
if (fileOrFolder) {
resource = fileOrFolder.resource;
} else {
const node = await this.getRootNode(fileOrFolder);
resource = node?.uri;
}
if (resource) {
const { filePath } = await remote.dialog.showSaveDialog(this.toSaveDialogOptions(resource, props));
if (!filePath) {
return undefined;
}
Expand Down Expand Up @@ -108,8 +114,7 @@ export class ElectronFileDialogService extends DefaultFileDialogService {

protected toSaveDialogOptions(uri: URI, props: SaveFileDialogProps): SaveDialogOptions {
const buttonLabel = props.saveLabel;
const defaultPath = props.inputValue;
return { ...this.toDialogOptions(uri, props, 'Save'), buttonLabel, defaultPath };
return { ...this.toDialogOptions(uri, props, 'Save'), buttonLabel };
}

}
Expand Down

0 comments on commit 41118c0

Please sign in to comment.