diff --git a/js/api.js b/js/api.js index 07f8ce9d..e08f7fa5 100644 --- a/js/api.js +++ b/js/api.js @@ -209,14 +209,35 @@ const Blockbench = { showMessageBox(options = 0, cb) { return new MessageBox(options, cb).show(); }, - async textPrompt(title, value, callback, placeholder = null) { + /** + * + * @param {*} title + * @param {*} value + * @param {*} callback + * @param {object} options Options + * @param {string} options.info Info text + * @param {string} options.description Description for the text input + * @returns {Promise} Input value + */ + async textPrompt(title, value, callback, options = 0) { + if (typeof options == 'string') { + options = {placeholder: options}; + console.warn('textPrompt: 4th argument is expected to be a string'); + } let answer = await new Promise((resolve) => { + let form = { + text: {full_width: true, placeholder: options.placeholder, value, description: options.description} + }; + if (options.info) { + form.description = { + type: 'info', + text: tl(options.info) + } + } new Dialog({ id: 'text_input', title: title || 'dialog.input.title', - form: { - text: {full_width: true, placeholder, value} - }, + form, onConfirm({text}) { if (callback) callback(text); resolve(text); diff --git a/js/io/io.js b/js/io/io.js index 586bb0e9..b22a8a28 100644 --- a/js/io/io.js +++ b/js/io/io.js @@ -676,7 +676,7 @@ BARS.defineActions(function() { Blockbench.showQuickMessage('message.invalid_link') }) } - }, 'https://blckbn.ch/123abc') + }, {placeholder: 'https://blckbn.ch/123abc'}); } }) new Action('extrude_texture', { diff --git a/js/outliner/outliner.js b/js/outliner/outliner.js index 418ede0d..5c408457 100644 --- a/js/outliner/outliner.js +++ b/js/outliner/outliner.js @@ -952,11 +952,15 @@ function renameOutliner(element) { if (name) { Undo.initEdit({elements: selected}) selected.forEach(function(obj, i) { - obj.name = name.replace(/%/g, obj.index).replace(/\$/g, i) + obj.name = name.replace(/%+/g, val => { + return (obj.getParentArray().indexOf(obj)+1).toDigitString(val.length) + }).replace(/\$+/g, val => { + return (i+1).toDigitString(val.length) + }); }) Undo.finishEdit('Rename') } - }) + }, {description: tl('message.rename_elements.numbering')}) } } } diff --git a/lang/en.json b/lang/en.json index 13f2f858..c1b19fcd 100644 --- a/lang/en.json +++ b/lang/en.json @@ -420,6 +420,8 @@ "message.invalid_session.title": "Invalid Session Token", "message.invalid_session.message": "The session you are trying to join has expired or the token provided is invalid.", + "message.rename_elements.numbering": "You can use special characters to generate sequential numbers: % to get the index of the element within its group, $ to get the index within the selection.", + "dialog.project.title": "Project", "dialog.project.name": "File Name", "dialog.project.parent": "Parent Model",