Skip to content

Commit f51823b

Browse files
committed
Fix open dialog
- Fixes coder#508
1 parent 55bfeab commit f51823b

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

packages/vscode/src/dialog.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,12 @@ class Dialog {
270270

271271
return;
272272
}
273+
274+
// If it's a directory, we want to navigate to it. If it's a file, then we
275+
// only want to open it if opening files is supported.
273276
if (element.isDirectory) {
274277
this.path = element.fullPath;
275-
} else if (!(this.options as OpenDialogOptions).properties.openDirectory) {
278+
} else if ((this.options as OpenDialogOptions).properties.openFile) {
276279
this.selectEmitter.emit(element.fullPath);
277280
}
278281
});
@@ -288,16 +291,18 @@ class Dialog {
288291
});
289292
buttonsNode.appendChild(cancelBtn);
290293
const confirmBtn = document.createElement("button");
291-
const openFile = (this.options as OpenDialogOptions).properties.openFile;
292-
confirmBtn.innerText = openFile ? "Open" : "Confirm";
294+
const openDirectory = (this.options as OpenDialogOptions).properties.openDirectory;
295+
confirmBtn.innerText = this.options.buttonLabel || "Confirm";
293296
confirmBtn.addEventListener("click", () => {
294-
if (this._path && !openFile) {
297+
if (this._path && openDirectory) {
295298
this.selectEmitter.emit(this._path);
296299
}
297300
});
298-
// Since a single click opens a file, the only time this button can be
299-
// used is on a directory, which is invalid for opening files.
300-
if (openFile) {
301+
// Disable if we can't open directories, otherwise you can open a directory
302+
// as a file which won't work. This is because our button currently just
303+
// always opens whatever directory is opened and will not open selected
304+
// files. (A single click on a file is used to open it instead.)
305+
if (!openDirectory) {
301306
confirmBtn.disabled = true;
302307
}
303308
buttonsNode.appendChild(confirmBtn);
@@ -407,8 +412,9 @@ class Dialog {
407412
isDirectory: stat.isDirectory(),
408413
lastModified: stat.mtime.toDateString(),
409414
size: stat.size,
410-
// If we are opening a directory, show files as disabled.
411-
isDisabled: !stat.isDirectory() && (this.options as OpenDialogOptions).properties.openDirectory,
415+
// If we can't open files, show them as disabled.
416+
isDisabled: !stat.isDirectory()
417+
&& !(this.options as OpenDialogOptions).properties.openFile,
412418
}));
413419
}
414420
}

packages/vscode/src/fill/windowsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ export class WindowsService implements IWindowsService {
142142
return [await showOpenDialog({
143143
...(options || {}),
144144
properties: {
145-
openDirectory: true,
146-
openFile: true,
145+
openDirectory: options && options.properties && options.properties.includes("openDirectory") || false,
146+
openFile: options && options.properties && options.properties.includes("openFile") || false,
147147
},
148148
})];
149149
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy