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 committed Apr 15, 2019
1 parent cc7b214 commit a002a95
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, label] = await Promise.all([
this.fileSystem.getFileStat(rootUri.toString()),
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 a002a95

Please sign in to comment.