From d0d9d2601bc317eef57e3f98b26df91a6a2c3351 Mon Sep 17 00:00:00 2001 From: Patrick Euerle Date: Wed, 14 Jul 2021 10:33:20 +0200 Subject: [PATCH] Added default path functionality for open and save-as dialogues --- desktop/sources/scripts/project.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/desktop/sources/scripts/project.js b/desktop/sources/scripts/project.js index c95e7c2..dcb31ce 100644 --- a/desktop/sources/scripts/project.js +++ b/desktop/sources/scripts/project.js @@ -86,7 +86,7 @@ function Project () { this.open = function () { console.log('Open Pages') - const paths = dialog.showOpenDialogSync(app.win, { properties: ['openFile', 'multiSelections'] }) + const paths = dialog.showOpenDialogSync(app.win, { defaultPath: this.default_path(), properties: ['openFile', 'multiSelections'] }) console.log(paths) if (!paths) { console.log('Nothing to load'); return } @@ -117,7 +117,7 @@ function Project () { console.log('Save As Page') const page = this.page() - const path = dialog.showSaveDialogSync(app.win) + const path = dialog.showSaveDialogSync(app.win, { defaultPath: this.default_path() }) if (!path) { console.log('Nothing to save'); return } @@ -221,6 +221,21 @@ function Project () { return a } + this.default_path = function () { + const path = require('path') + const page = this.page() + const paths = this.paths() + + // If active page has a path use it as default path + if (page.path) { return path.dirname(page.path) } + + // Fallback 1: use path of last opened page as default path + if (paths.length > 0) { return path.dirname(paths[paths.length - 1]) } + + // Fallback 2: return an empty string, Left install dir will be default path + return '' + } + function isJSON (text) { try { JSON.parse(text); return true } catch (error) { return false } } }