From fe7d70ca40786a43205d2bef2f2cc551e9b9a43d Mon Sep 17 00:00:00 2001 From: bordun Date: Sun, 26 Jan 2020 11:01:34 +0100 Subject: [PATCH] file: allow selecting folders (#588) --- CHANGELOG.md | 1 + src/client/app/ui/utils.js | 6 +++--- src/client/app/widgets/inputs/file.js | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c589c8..5192a1ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - modal: correct popup title color - widgets: - **new** `menu` widget, circular alternative to the dropdown & switch widgets + - file: allow selecting folders - editor: - convert invalid quote characters automatically to avoid errors diff --git a/src/client/app/ui/utils.js b/src/client/app/ui/utils.js index 8a7488aa..06d01d36 100644 --- a/src/client/app/ui/utils.js +++ b/src/client/app/ui/utils.js @@ -204,7 +204,7 @@ module.exports = { var choice = DOM.get(list, ':checked')[0] - if (!choice && (!save || !saveInput.value)) return + if (!choice && (!save || !saveInput.value) && !options.loadDir) return if (choice && choice.classList.contains('folder') && (!save || !saveInputFocus)) { ipc.send('listDir', {path: [path, choice.value]}) @@ -216,7 +216,7 @@ module.exports = { callback([path, saveInput.value]) popup.close() } else { - callback([path, choice.value]) + callback([path, choice && options.loadDir ? choice.value : '']) popup.close() } } @@ -260,7 +260,7 @@ module.exports = { break } } - + if (index !== -1) { list.childNodes[index].firstElementChild.click() list.childNodes[index].firstElementChild.focus() diff --git a/src/client/app/widgets/inputs/file.js b/src/client/app/widgets/inputs/file.js index 6478cefc..def5a71c 100644 --- a/src/client/app/widgets/inputs/file.js +++ b/src/client/app/widgets/inputs/file.js @@ -7,7 +7,7 @@ module.exports = class Input extends Widget { static description() { - return 'File selector (server-side).' + return 'File/Folder selector (server-side).' } @@ -38,10 +38,12 @@ module.exports = class Input extends Widget { remoteBrowse({ extension: this.getProp('extension').replace(/^\.?(.*)$/, '$1'), - directory: this.getProp('directory') === 'auto' ? undefined : this.getProp('directory') + directory: this.getProp('directory') === 'auto' ? undefined : this.getProp('directory'), + loadDir: true }, (path)=>{ - this.setValue(path.join(path[0][0] === '/' ? '/' : '\\'), { + var newPath = path[1] === '' ? path[0] : path.join(path[0][0] === '/' ? '/' : '\\') + this.setValue(newPath, { sync: true, send: true })