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

@@ -1268,6 +1268,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
SpaceNode *snode = CTX_wm_space_node(C);
bNodeTree *ntree = snode->edittree;
const bool keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs");
bool changed = false;
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
@@ -1280,6 +1281,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
bNode *new_node = blender::bke::node_copy_with_mapping(
ntree, *node, LIB_ID_COPY_DEFAULT, true, socket_map);
node_map.add_new(node, new_node);
changed = true;
}
/* make sure we don't copy new nodes again! */
@@ -1288,6 +1290,10 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
}
}
if (!changed) {
return OPERATOR_CANCELLED;
}
/* Copy links between selected nodes. */
bNodeLink *lastlink = (bNodeLink *)ntree->links.last;
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {