From f51823b51fc2c04632ac82571ca579ffb0518c1a Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 18 Apr 2019 12:08:44 -0500 Subject: [PATCH] Fix open dialog - Fixes #508 --- packages/vscode/src/dialog.ts | 24 ++++++++++++++-------- packages/vscode/src/fill/windowsService.ts | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/vscode/src/dialog.ts b/packages/vscode/src/dialog.ts index 1d480bd6..6eb63405 100644 --- a/packages/vscode/src/dialog.ts +++ b/packages/vscode/src/dialog.ts @@ -270,9 +270,12 @@ class Dialog { return; } + + // If it's a directory, we want to navigate to it. If it's a file, then we + // only want to open it if opening files is supported. if (element.isDirectory) { this.path = element.fullPath; - } else if (!(this.options as OpenDialogOptions).properties.openDirectory) { + } else if ((this.options as OpenDialogOptions).properties.openFile) { this.selectEmitter.emit(element.fullPath); } }); @@ -288,16 +291,18 @@ class Dialog { }); buttonsNode.appendChild(cancelBtn); const confirmBtn = document.createElement("button"); - const openFile = (this.options as OpenDialogOptions).properties.openFile; - confirmBtn.innerText = openFile ? "Open" : "Confirm"; + const openDirectory = (this.options as OpenDialogOptions).properties.openDirectory; + confirmBtn.innerText = this.options.buttonLabel || "Confirm"; confirmBtn.addEventListener("click", () => { - if (this._path && !openFile) { + if (this._path && openDirectory) { this.selectEmitter.emit(this._path); } }); - // Since a single click opens a file, the only time this button can be - // used is on a directory, which is invalid for opening files. - if (openFile) { + // Disable if we can't open directories, otherwise you can open a directory + // as a file which won't work. This is because our button currently just + // always opens whatever directory is opened and will not open selected + // files. (A single click on a file is used to open it instead.) + if (!openDirectory) { confirmBtn.disabled = true; } buttonsNode.appendChild(confirmBtn); @@ -407,8 +412,9 @@ class Dialog { isDirectory: stat.isDirectory(), lastModified: stat.mtime.toDateString(), size: stat.size, - // If we are opening a directory, show files as disabled. - isDisabled: !stat.isDirectory() && (this.options as OpenDialogOptions).properties.openDirectory, + // If we can't open files, show them as disabled. + isDisabled: !stat.isDirectory() + && !(this.options as OpenDialogOptions).properties.openFile, })); } } diff --git a/packages/vscode/src/fill/windowsService.ts b/packages/vscode/src/fill/windowsService.ts index aa56243b..d89c8420 100644 --- a/packages/vscode/src/fill/windowsService.ts +++ b/packages/vscode/src/fill/windowsService.ts @@ -142,8 +142,8 @@ export class WindowsService implements IWindowsService { return [await showOpenDialog({ ...(options || {}), properties: { - openDirectory: true, - openFile: true, + openDirectory: options && options.properties && options.properties.includes("openDirectory") || false, + openFile: options && options.properties && options.properties.includes("openFile") || false, }, })]; }