mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-27 04:21:46 +08:00
Implement directory picker API
This commit is contained in:
parent
9c0bbd988f
commit
2a65b264dd
@ -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
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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({
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user