Fix Reset Layout not working with new panel system

This commit is contained in:
JannisX11 2023-04-07 14:44:32 +02:00
parent 2d792137e1
commit 8cd1ec1e07
3 changed files with 38 additions and 16 deletions

View File

@ -919,3 +919,37 @@ onVueSetup(function() {
Interface.status_bar.vue.modifier_keys[key].remove(text);
};
})
BARS.defineActions(function() {
new Action('reset_layout', {
icon: 'replay',
category: 'blockbench',
click: function () {
Interface.data = $.extend(true, {}, Interface.default_data);
for (let id in Panels) {
let panel = Panels[id];
if (!Interface.data.panels[id]) Interface.data.panels[id] = {};
panel.position_data = Interface.data.panels[id];
let defaultp = panel.default_position || 0;
if (!panel.position_data.slot) panel.position_data.slot = defaultp.slot || 'left_bar';
if (!panel.position_data.float_position)panel.position_data.float_position = defaultp.float_position || [0, 0];
if (!panel.position_data.float_size) panel.position_data.float_size = defaultp.float_size || [300, 300];
if (!panel.position_data.height) panel.position_data.height = defaultp.height || 300;
if (panel.position_data.folded == undefined) panel.position_data.folded = defaultp.folded || false;
console.log(id, panel.slot)
panel.moveTo(panel.slot);
}
Blockbench.dispatchEvent('reset_layout', {});
updateInterface();
updateSidebarOrder();
}
})
})

View File

@ -21,7 +21,7 @@ class Panel extends EventSystem {
if (!Interface.data.panels[this.id]) Interface.data.panels[this.id] = {};
this.position_data = Interface.data.panels[this.id];
let defaultp = data.default_position || 0;
let defaultp = this.default_position = data.default_position || 0;
if (defaultp && defaultp.slot) this.previous_slot = defaultp.slot;
if (!this.position_data.slot) this.position_data.slot = defaultp.slot || (data.default_side ? (data.default_side+'_bar') : 'left_bar');
if (!this.position_data.float_position) this.position_data.float_position = defaultp.float_position || [0, 0];
@ -331,6 +331,9 @@ class Panel extends EventSystem {
}
set folded(state) {
this.position_data.folded = !!state;
}
resetCustomLayout() {
}
addToolbar(toolbar, position = this.toolbars.length) {
let nodes = [];

View File

@ -513,21 +513,6 @@ BARS.defineActions(function() {
})
}
})
//Only interface
new Action('reset_layout', {
icon: 'replay',
category: 'blockbench',
click: function () {
Interface.data = $.extend(true, {}, Interface.default_data)
Interface.data.left_bar.forEach((id) => {
$('#left_bar').append(Interface.Panels[id].node)
})
Interface.data.right_bar.forEach((id) => {
$('#right_bar').append(Interface.Panels[id].node)
})
updateInterface()
}
})
BarItems.import_theme.toElement('#layout_title_bar')
BarItems.export_theme.toElement('#layout_title_bar')
})