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:
@@ -878,11 +878,12 @@ void ACTION_OT_keyframe_insert(wmOperatorType *ot)
|
||||
|
||||
/* ******************** Duplicate Keyframes Operator ************************* */
|
||||
|
||||
static void duplicate_action_keys(bAnimContext *ac)
|
||||
static bool duplicate_action_keys(bAnimContext *ac)
|
||||
{
|
||||
ListBase anim_data = {NULL, NULL};
|
||||
bAnimListElem *ale;
|
||||
int filter;
|
||||
bool changed = false;
|
||||
|
||||
/* filter data */
|
||||
if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) {
|
||||
@@ -898,10 +899,11 @@ static void duplicate_action_keys(bAnimContext *ac)
|
||||
/* loop through filtered data and delete selected keys */
|
||||
for (ale = anim_data.first; ale; ale = ale->next) {
|
||||
if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) {
|
||||
duplicate_fcurve_keys((FCurve *)ale->key_data);
|
||||
changed |= duplicate_fcurve_keys((FCurve *)ale->key_data);
|
||||
}
|
||||
else if (ale->type == ANIMTYPE_GPLAYER) {
|
||||
ED_gpencil_layer_frames_duplicate((bGPDlayer *)ale->data);
|
||||
changed |= ED_gpencil_layer_frame_select_check((bGPDlayer *)ale->data);
|
||||
}
|
||||
else if (ale->type == ANIMTYPE_MASKLAYER) {
|
||||
ED_masklayer_frames_duplicate((MaskLayer *)ale->data);
|
||||
@@ -915,6 +917,8 @@ static void duplicate_action_keys(bAnimContext *ac)
|
||||
|
||||
ANIM_animdata_update(ac, &anim_data);
|
||||
ANIM_animdata_freelist(&anim_data);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* ------------------- */
|
||||
@@ -929,7 +933,9 @@ static int actkeys_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
}
|
||||
|
||||
/* duplicate keyframes */
|
||||
duplicate_action_keys(&ac);
|
||||
if (!duplicate_action_keys(&ac)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* set notifier that keyframes have changed */
|
||||
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL);
|
||||
|
||||
Reference in New Issue
Block a user