diff --git a/css/dialogs.css b/css/dialogs.css index 96e8aa01..08539590 100644 --- a/css/dialogs.css +++ b/css/dialogs.css @@ -148,13 +148,16 @@ } label.name_space_left { float: left; - min-width: 140px; + min-width: 90px; padding-top: 4px; padding-left: 1px; padding-right: 8px; flex-shrink: 0; overflow-wrap: break-word; } + .dialog label.name_space_left { + min-width: 140px; + } .dialog_bar.form_bar.full_width_dialog_bar { flex-wrap: wrap; } diff --git a/css/window.css b/css/window.css index aa7e8592..31ad8285 100644 --- a/css/window.css +++ b/css/window.css @@ -1228,20 +1228,9 @@ width: fit-content; z-index: 3; } - #amend_edit_menu > div.amend_edit_line { + #amend_edit_menu > form { background-color: var(--color-ui); - padding: 0px 8px; - height: 30px; - display: flex; - } - #amend_edit_menu > div.amend_edit_line .nslide_tool { - float: none; - } - #amend_edit_menu > div.amend_edit_line > input { - width: 73px; - } - #amend_edit_menu > div.amend_edit_line > label { - padding: 4px 6px; + padding: 2px 10px; } .amend_edit_close_button { position: absolute; diff --git a/js/interface/dialog.js b/js/interface/dialog.js index 7010bb8e..ff92e46c 100644 --- a/js/interface/dialog.js +++ b/js/interface/dialog.js @@ -6,6 +6,9 @@ function buildForm(dialog) { dialog_content.append(dialog.form.node); dialog.max_label_width = Math.max(dialog.max_label_width, dialog.form.max_label_width); if (dialog.form.uses_wide_inputs) dialog.uses_wide_inputs = true; + dialog.form.on('change', ({result}) => { + if (dialog.onFormChange) dialog.onFormChange(result); + }) } function buildLines(dialog) { let dialog_content = $(dialog.object).find('.dialog_content') diff --git a/js/interface/form.js b/js/interface/form.js index 1e182a8c..d08b9c2b 100644 --- a/js/interface/form.js +++ b/js/interface/form.js @@ -1,9 +1,10 @@ -class InputForm { +class InputForm extends EventSystem { constructor(form_config, options = {}) { + super(); this.uuid = guid(); this.form_config = form_config; this.form_data = {}; - this.node = Interface.createElement('div'); + this.node = Interface.createElement('form', {class: 'form'}); this.max_label_width = 0; this.uses_wide_inputs = false; @@ -430,6 +431,7 @@ class InputForm { data.bar = bar; } } + this.node.style.setAttribute } updateValues(initial) { let form_result = this.getResult(); @@ -441,8 +443,8 @@ class InputForm { data.bar.toggle(show); } } - if (!initial && typeof this.onFormChange == 'function') { - this.onFormChange(form_result) + if (!initial) { + this.dispatchEvent('change', {result: form_result}); } return form_result; } diff --git a/js/modeling/mesh_editing.js b/js/modeling/mesh_editing.js index fd169796..7fffbd08 100644 --- a/js/modeling/mesh_editing.js +++ b/js/modeling/mesh_editing.js @@ -1291,6 +1291,7 @@ BARS.defineActions(function() { }, onConfirm(result) { let original_selection_group = Group.selected && Group.selected.uuid; + let iteration = 0; function runEdit(amended, result) { let elements = []; if (original_selection_group && !Group.selected) { @@ -1624,9 +1625,10 @@ BARS.defineActions(function() { UVEditor.setAutoSize(null, true, Object.keys(mesh.faces)); Undo.finishEdit('Add primitive'); Blockbench.dispatchEvent( 'add_mesh', {object: mesh} ) + iteration++; Vue.nextTick(function() { - if (settings.create_rename.value) { + if (settings.create_rename.value && iteration == 1) { mesh.rename() } }) diff --git a/js/undo.js b/js/undo.js index 55d36d70..fd407b07 100644 --- a/js/undo.js +++ b/js/undo.js @@ -76,13 +76,11 @@ class UndoSystem { } } amendEdit(form, callback) { - let scope = this; - let input_elements = {}; let dialog = document.createElement('div'); dialog.id = 'amend_edit_menu'; this.amend_edit_menu = { node: dialog, - form: {} + form: null }; let close_button = document.createElement('div'); @@ -94,72 +92,16 @@ class UndoSystem { }) dialog.append(close_button); - function updateValue() { - let form_values = {}; - for (let key in form) { - let input = scope.amend_edit_menu.form[key]; - if (input) { - if (input.type == 'number') { - form_values[key] = input.slider.get(); - } else if (input.type == 'checkbox') { - form_values[key] = !!input.node.checked; - } - } - } + this.amend_edit_menu.form = new InputForm(form); + this.amend_edit_menu.form.on('change', ({result}) => { if (Undo.history.length != Undo.index) { console.error('Detected error in amending edit. Skipping this edit.'); return; } Undo.undo(null, true); - callback(form_values, scope.amend_edit_menu.form); - } - - for (let key in form) { - let form_line = form[key]; - if (!Condition(form_line.condition)) continue; - let line = document.createElement('div'); - line.className = 'amend_edit_line'; - dialog.append(line); - this.amend_edit_menu.form[key] = { - type: form_line.type || 'number', - label: form_line.label - } - - if (this.amend_edit_menu.form[key].type == 'number') { - let getInterval = form_line.getInterval; - if (form_line.interval_type == 'position') getInterval = getSpatialInterval; - if (form_line.interval_type == 'rotation') getInterval = getRotationInterval; - let slider = new NumSlider({ - id: 'amend_edit_slider', - name: tl(form_line.label), - private: true, - onChange: updateValue, - getInterval, - settings: { - default: form_line.value || 0, - min: form_line.min, - max: form_line.max, - step: form_line.step||1, - }, - }); - line.append(slider.node); - input_elements[key] = slider; - this.amend_edit_menu.form[key].slider = slider - slider.update(); - - } else if (this.amend_edit_menu.form[key].type == 'checkbox') { - - let toggle = Interface.createElement('input', {type: 'checkbox', checked: form_line.value ? true : undefined}); - toggle.addEventListener('input', updateValue); - line.append(toggle); - input_elements[key] = toggle; - this.amend_edit_menu.form[key].node = toggle; - } - - let label = document.createElement('label'); - label.innerText = tl(form_line.label); - line.append(label); - } + callback(result, this.amend_edit_menu.form); + }) + dialog.append(this.amend_edit_menu.form.node); let preview_container = document.getElementById('preview'); preview_container.append(dialog);