Add hasAny and hasSelected to improve performance

This commit is contained in:
JannisX11 2023-05-07 00:12:28 +02:00
parent 15ba9dc866
commit c671fe68c2
2 changed files with 9 additions and 3 deletions

View File

@ -420,7 +420,7 @@ BARS.defineActions(function() {
vertex: {name: true, icon: 'fiber_manual_record'},
},
icon_mode: true,
condition: () => Modes.edit && Mesh.all.length,
condition: () => Modes.edit && Mesh.hasAny(),
onChange({value}) {
if (value === previous_selection_mode) return;
if (value === 'object') {
@ -516,7 +516,7 @@ BARS.defineActions(function() {
category: 'tools',
selectElements: true,
modes: ['edit'],
condition: () => Modes.edit && Mesh.all.length,
condition: () => Modes.edit && Mesh.hasAny(),
onCanvasClick(data) {
if (!seam_timeout) {
seam_timeout = setTimeout(() => {
@ -545,7 +545,7 @@ BARS.defineActions(function() {
divide: true,
join: true,
},
condition: () => Modes.edit && Mesh.all.length,
condition: () => Modes.edit && Mesh.hasAny(),
onChange({value}) {
if (value == 'auto') value = null;
Undo.initEdit({elements: Mesh.selected});

View File

@ -519,6 +519,12 @@ class OutlinerElement extends OutlinerNode {
console.warn('You cannot modify this')
}
})
OutlinerElement.hasAny = function() {
return Outliner.elements.length > 0 && Outliner.elements.findIndex(element => element instanceof this) !== -1;
}
OutlinerElement.hasSelected = function() {
return Outliner.selected.length > 0 && Outliner.selected.findIndex(element => element instanceof this) !== -1;
}
OutlinerElement.types = {};