1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 20:55:25 +00:00

Fix open dialog

- Fixes #508
This commit is contained in:
Asher 2019-04-18 12:08:44 -05:00
parent 55bfeab208
commit f51823b51f
No known key found for this signature in database
GPG Key ID: 7BB4BA9C783D2BBC
2 changed files with 17 additions and 11 deletions

View File

@ -270,9 +270,12 @@ class Dialog {
return; 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) { if (element.isDirectory) {
this.path = element.fullPath; 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); this.selectEmitter.emit(element.fullPath);
} }
}); });
@ -288,16 +291,18 @@ class Dialog {
}); });
buttonsNode.appendChild(cancelBtn); buttonsNode.appendChild(cancelBtn);
const confirmBtn = document.createElement("button"); const confirmBtn = document.createElement("button");
const openFile = (this.options as OpenDialogOptions).properties.openFile; const openDirectory = (this.options as OpenDialogOptions).properties.openDirectory;
confirmBtn.innerText = openFile ? "Open" : "Confirm"; confirmBtn.innerText = this.options.buttonLabel || "Confirm";
confirmBtn.addEventListener("click", () => { confirmBtn.addEventListener("click", () => {
if (this._path && !openFile) { if (this._path && openDirectory) {
this.selectEmitter.emit(this._path); this.selectEmitter.emit(this._path);
} }
}); });
// Since a single click opens a file, the only time this button can be // Disable if we can't open directories, otherwise you can open a directory
// used is on a directory, which is invalid for opening files. // as a file which won't work. This is because our button currently just
if (openFile) { // 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; confirmBtn.disabled = true;
} }
buttonsNode.appendChild(confirmBtn); buttonsNode.appendChild(confirmBtn);
@ -407,8 +412,9 @@ class Dialog {
isDirectory: stat.isDirectory(), isDirectory: stat.isDirectory(),
lastModified: stat.mtime.toDateString(), lastModified: stat.mtime.toDateString(),
size: stat.size, size: stat.size,
// If we are opening a directory, show files as disabled. // If we can't open files, show them as disabled.
isDisabled: !stat.isDirectory() && (this.options as OpenDialogOptions).properties.openDirectory, isDisabled: !stat.isDirectory()
&& !(this.options as OpenDialogOptions).properties.openFile,
})); }));
} }
} }

View File

@ -142,8 +142,8 @@ export class WindowsService implements IWindowsService {
return [await showOpenDialog({ return [await showOpenDialog({
...(options || {}), ...(options || {}),
properties: { properties: {
openDirectory: true, openDirectory: options && options.properties && options.properties.includes("openDirectory") || false,
openFile: true, openFile: options && options.properties && options.properties.includes("openFile") || false,
}, },
})]; })];
} }