add batch widget add / delete for usability / performance with very large #s of widgets
This commit is contained in:
parent
406cacc453
commit
7704b51d5f
3 changed files with 52 additions and 16 deletions
|
|
@ -596,7 +596,7 @@ gapp.register("kiri.main", [], (root, exports) => {
|
||||||
toload.forEach(function(widgetid) {
|
toload.forEach(function(widgetid) {
|
||||||
Widget.loadFromState(widgetid, function(widget) {
|
Widget.loadFromState(widgetid, function(widget) {
|
||||||
if (widget) {
|
if (widget) {
|
||||||
platform.add(widget, 0, position);
|
platform.add(widget, 0, position, true);
|
||||||
let ann = api.widgets.annotate(widgetid);
|
let ann = api.widgets.annotate(widgetid);
|
||||||
widget.meta.file = ann.file;
|
widget.meta.file = ann.file;
|
||||||
widget.meta.url = ann.url;
|
widget.meta.url = ann.url;
|
||||||
|
|
|
||||||
|
|
@ -383,24 +383,52 @@ function platformGroupDone(skipLayout) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function platformAdd(widget, shift, nolayout) {
|
let deferred = [];
|
||||||
|
let deferTimeout;
|
||||||
|
|
||||||
|
function platformAdd(widget, shift, nolayout, defer) {
|
||||||
api.widgets.add(widget);
|
api.widgets.add(widget);
|
||||||
space.world.add(widget.mesh);
|
space.world.add(widget.mesh);
|
||||||
widget.anno.extruder = widget.anno.extruder || 0;
|
widget.anno.extruder = widget.anno.extruder || 0;
|
||||||
platform.select(widget, shift);
|
if (defer) {
|
||||||
platform.compute_max_z();
|
deferred.push({widget, shift, nolayout});
|
||||||
api.event.emit('widget.add', widget);
|
clearTimeout(deferTimeout);
|
||||||
api.space.auto_save();
|
deferTimeout = setTimeout(platformAddDeferred, 150);
|
||||||
platformChanged();
|
} else {
|
||||||
if (nolayout) {
|
platform.select(widget, shift);
|
||||||
return;
|
platform.compute_max_z();
|
||||||
|
api.space.auto_save();
|
||||||
|
platformChanged();
|
||||||
|
api.event.emit('widget.add', widget);
|
||||||
|
if (nolayout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!grouping) {
|
||||||
|
platformGroupDone();
|
||||||
|
if (!current().controller.autoLayout) {
|
||||||
|
positionNewWidget(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!grouping) {
|
}
|
||||||
platformGroupDone();
|
|
||||||
if (!current().controller.autoLayout) {
|
function platformAddDeferred() {
|
||||||
|
console.log('platform_add_deferred');
|
||||||
|
for (let rec of deferred) {
|
||||||
|
let { widget, shift, nolayout } = rec;
|
||||||
|
// platform.select(widget, shift);
|
||||||
|
if (!nolayout && !current().controller.autoLayout) {
|
||||||
positionNewWidget(widget);
|
positionNewWidget(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!grouping) {
|
||||||
|
platformGroupDone();
|
||||||
|
}
|
||||||
|
api.event.emit('widget.add', deferred.map(r => r.widget));
|
||||||
|
platform.compute_max_z();
|
||||||
|
api.space.auto_save();
|
||||||
|
platformChanged();
|
||||||
|
deferred = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function positionNewWidget(widget) {
|
function positionNewWidget(widget) {
|
||||||
|
|
@ -451,15 +479,17 @@ function positionNewWidget(widget) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function platformDelete(widget) {
|
function platformDelete(widget, defer) {
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Array.isArray(widget)) {
|
if (Array.isArray(widget)) {
|
||||||
const mc = widget.slice();
|
const mc = widget.slice();
|
||||||
for (let i = 0; i < mc.length; i++) {
|
for (let i = 0; i < mc.length; i++) {
|
||||||
platform.delete(mc[i].widget || mc[i]);
|
platform.delete(mc[i].widget || mc[i], true);
|
||||||
}
|
}
|
||||||
|
platformDeletePost();
|
||||||
|
api.event.emit('widget.delete', widget);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
kiri.client.clear(widget);
|
kiri.client.clear(widget);
|
||||||
|
|
@ -467,6 +497,13 @@ function platformDelete(widget) {
|
||||||
api.selection.remove(widget);
|
api.selection.remove(widget);
|
||||||
Widget.Groups.remove(widget);
|
Widget.Groups.remove(widget);
|
||||||
space.world.remove(widget.mesh);
|
space.world.remove(widget.mesh);
|
||||||
|
if (!defer) {
|
||||||
|
platformDeletePost();
|
||||||
|
api.event.emit('widget.delete', widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function platformDeletePost() {
|
||||||
api.view.update_slider_max();
|
api.view.update_slider_max();
|
||||||
platform.compute_max_z();
|
platform.compute_max_z();
|
||||||
if (get_mode() !== MODES.FDM) {
|
if (get_mode() !== MODES.FDM) {
|
||||||
|
|
@ -477,7 +514,6 @@ function platformDelete(widget) {
|
||||||
if (api.feature.drop_layout) {
|
if (api.feature.drop_layout) {
|
||||||
platform.layout();
|
platform.layout();
|
||||||
}
|
}
|
||||||
api.event.emit('widget.delete', widget);
|
|
||||||
api.space.auto_save();
|
api.space.auto_save();
|
||||||
platformChanged();
|
platformChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -560,7 +560,7 @@ function settingsImport(data, ask) {
|
||||||
if (isWork) {
|
if (isWork) {
|
||||||
api.platform.clear();
|
api.platform.clear();
|
||||||
kiri.codec.decode(data.work).forEach(widget => {
|
kiri.codec.decode(data.work).forEach(widget => {
|
||||||
api.platform.add(widget, 0, true);
|
api.platform.add(widget, 0, true, true);
|
||||||
});
|
});
|
||||||
if (data.view) {
|
if (data.view) {
|
||||||
space.view.load(data.view);
|
space.view.load(data.view);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue