WM: avoid unnecessary undo step creation when duplicating

Calling duplicate operation without selecting anything registers an undo
step. If nothing is selected (keyframe, curve, object, etc.), cancel the
operator execution to prevent undo push.

Patch improves following operators:

- ACTION_OT_duplicate
- GPENCIL_OT_duplicate
- GRAPH_OT_duplicate
- MESH_OT_duplicate
- NODE_OT_duplicate
- OBJECT_OT_duplicate

Reviewed By: campbellbarton

Ref D14511
This commit is contained in:
Pratik Borhade
2022-04-05 20:13:03 +10:00
committed by Campbell Barton
parent d88b821d28
commit d00de988c3
8 changed files with 43 additions and 14 deletions

View File

@@ -118,11 +118,13 @@ void clear_fcurve_keys(FCurve *fcu)
/* ---------------- */
void duplicate_fcurve_keys(FCurve *fcu)
bool duplicate_fcurve_keys(FCurve *fcu)
{
bool changed = false;
/* this can only work when there is an F-Curve, and also when there are some BezTriples */
if (ELEM(NULL, fcu, fcu->bezt)) {
return;
return changed;
}
for (int i = 0; i < fcu->totvert; i++) {
@@ -135,7 +137,7 @@ void duplicate_fcurve_keys(FCurve *fcu)
memcpy(newbezt + i + 1, fcu->bezt + i, sizeof(BezTriple));
memcpy(newbezt + i + 2, fcu->bezt + i + 1, sizeof(BezTriple) * (fcu->totvert - (i + 1)));
fcu->totvert++;
changed = true;
/* reassign pointers... (free old, and add new) */
MEM_freeN(fcu->bezt);
fcu->bezt = newbezt;
@@ -148,6 +150,7 @@ void duplicate_fcurve_keys(FCurve *fcu)
BEZT_SEL_ALL(&fcu->bezt[i]);
}
}
return changed;
}
/* **************************************************** */