Skip to content

Commit

Permalink
Handled case where the folder parameter is a file.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Bozzini <federico.bozzini@gmail.com>
  • Loading branch information
federicobozzini authored and akosyakov committed Jul 3, 2019
1 parent fa52ca2 commit 8b3cdca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class DefaultFileDialogService {
async showOpenDialog(props: OpenFileDialogProps, folder?: FileStat): Promise<URI | undefined>;
async showOpenDialog(props: OpenFileDialogProps, folder?: FileStat): Promise<MaybeArray<URI> | undefined> {
const title = props.title || 'Open';
const rootNode = await this.getDirNode(folder);
const rootNode = await this.getRootNode(folder);
if (rootNode) {
const dialog = this.openFileDialogFactory(Object.assign(props, { title }));
await dialog.model.navigateTo(rootNode);
Expand All @@ -62,7 +62,7 @@ export class DefaultFileDialogService {

async showSaveDialog(props: SaveFileDialogProps, folder?: FileStat): Promise<URI | undefined> {
const title = props.title || 'Save';
const rootNode = await this.getDirNode(folder);
const rootNode = await this.getRootNode(folder);
if (rootNode) {
const dialog = this.saveFileDialogFactory(Object.assign(props, { title }));
await dialog.model.navigateTo(rootNode);
Expand All @@ -71,10 +71,11 @@ export class DefaultFileDialogService {
return undefined;
}

protected async getDirNode(folderToOpen?: FileStat): Promise<DirNode | undefined> {
protected async getRootNode(folderToOpen?: FileStat): Promise<DirNode | undefined> {
const folder = folderToOpen || await this.fileSystem.getCurrentUserHome();
if (folder) {
const rootUri = new URI(folder.uri);
const folderUri = new URI(folder.uri);
const rootUri = folder.isDirectory ? folderUri : folderUri.parent;
const name = this.labelProvider.getName(rootUri);
const rootStat = await this.fileSystem.getFileStat(rootUri.toString());
if (rootStat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
async showOpenDialog(props: OpenFileDialogProps & { canSelectMany: true }, folder?: FileStat): Promise<MaybeArray<URI> | undefined>;
async showOpenDialog(props: OpenFileDialogProps, folder?: FileStat): Promise<URI | undefined>;
async showOpenDialog(props: OpenFileDialogProps, folder?: FileStat): Promise<MaybeArray<URI> | undefined> {
const rootNode = await this.getDirNode(folder);
const rootNode = await this.getRootNode(folder);
if (rootNode) {
return new Promise<MaybeArray<URI> | undefined>(resolve => {
remote.dialog.showOpenDialog(this.toOpenDialogOptions(rootNode.uri, props), (filePaths: string[] | undefined) => {
Expand All @@ -61,7 +61,7 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
}

async showSaveDialog(props: SaveFileDialogProps, folder?: FileStat): Promise<URI | undefined> {
const rootNode = await this.getDirNode(folder);
const rootNode = await this.getRootNode(folder);
if (rootNode) {
return new Promise<URI | undefined>(resolve => {
remote.dialog.showSaveDialog(this.toSaveDialogOptions(rootNode.uri, props), (filename: string | undefined) => {
Expand Down

0 comments on commit 8b3cdca

Please sign in to comment.