diff --git a/js/desktop.js b/js/desktop.js index 6237af81..b5b591fd 100644 --- a/js/desktop.js +++ b/js/desktop.js @@ -294,14 +294,14 @@ function openDefaultTexturePath() { if (answer === 0) { return; } else if (answer === 1) { - ElecDialogs.showOpenDialog(currentwindow, { + + let path = Blockbench.pickDirectory({ title: tl('message.default_textures.select'), - properties: ['openDirectory'], - }, function(filePaths) { - if (filePaths) { - settings.default_path.value = filePaths[0] - } - }) + resource_id: 'texture', + }); + if (path) { + settings.default_path.value = path; + } } else { settings.default_path.value = false } diff --git a/js/file_system.js b/js/file_system.js index a9629be7..07af3fe7 100644 --- a/js/file_system.js +++ b/js/file_system.js @@ -58,6 +58,44 @@ Object.assign(Blockbench, { }).click() } }, + pickDirectory(options) { + if (typeof options !== 'object') {options = {}} + /** + resource_id + startpath + title + */ + + if (isApp) { + + if (!options.startpath && options.resource_id) { + options.startpath = StateMemory.dialog_paths[options.resource_id] + } + + let dirNames = electron.dialog.showOpenDialogSync(currentwindow, { + title: options.title ? options.title : '', + dontAddToRecent: true, + properties: ['openDirectory'], + defaultPath: settings.streamer_mode.value + ? app.getPath('desktop') + : options.startpath + }) + + if (!dirNames) return null; + + if (options.resource_id) { + StateMemory.dialog_paths[options.resource_id] = PathModule.dirname(dirNames[0]); + StateMemory.save('dialog_paths'); + } + + return dirNames[0]; + + } else { + + console.warn('Picking directories is currently not supported in the web app'); + + } + }, read(files, options, cb) { if (files == undefined) return false; if (typeof files == 'string') files = [files]; diff --git a/js/interface/dialog.js b/js/interface/dialog.js index b50d496f..ed1b5174 100644 --- a/js/interface/dialog.js +++ b/js/interface/dialog.js @@ -181,11 +181,10 @@ function buildForm(dialog) { }, fileCB); break; case 'folder': - let filePaths = electron.dialog.showOpenDialog(currentwindow, { - properties: ['openDirectory'], - defaultPath: data.value + let path = Blockbench.pickDirectory({ + startpath: data.value, }) - if (filePaths) fileCB([{ path: filePaths[0] }]); + if (path) fileCB([{path}]); break; case 'save': Blockbench.export({ diff --git a/js/texturing/textures.js b/js/texturing/textures.js index 6ea985cf..6701d67a 100644 --- a/js/texturing/textures.js +++ b/js/texturing/textures.js @@ -1308,12 +1308,12 @@ BARS.defineActions(function() { path.splice(-1) path = path.join(osfs) - let filePaths = electron.dialog.showOpenDialogSync(currentwindow, { - properties: ['openDirectory'], - defaultPath: path + let dirPath = Blockbench.pickDirectory({ + resource_id: 'texture', + startpath: path, }) - if (filePaths && filePaths.length) { - var new_path = filePaths[0] + if (dirPath && dirPath.length) { + var new_path = dirPath[0] Undo.initEdit({textures}) textures.forEach(function(t) { if (typeof t.path === 'string' && t.path.includes(path)) {