forked from bartvdbraak/blender
Little modification of the duplicate operator on artist request: The default behavior (shift+dkey) is now to copy nodes and internal links, but not the input links from unselected nodes. This feature is available with the alternate duplicate operator (alt+dkey).
This commit is contained in:
parent
b29b0acdce
commit
756ef16e21
@ -2000,12 +2000,13 @@ bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float
|
||||
|
||||
/* ****************** Duplicate *********************** */
|
||||
|
||||
static int node_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int node_duplicate_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceNode *snode= CTX_wm_space_node(C);
|
||||
bNodeTree *ntree= snode->edittree;
|
||||
bNode *node, *newnode, *lastnode;
|
||||
bNodeLink *link, *newlink, *lastlink;
|
||||
int keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs");
|
||||
|
||||
ED_preview_kill_jobs(C);
|
||||
|
||||
@ -2033,10 +2034,11 @@ static int node_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
*/
|
||||
lastlink = ntree->links.last;
|
||||
for (link=ntree->links.first; link; link=link->next) {
|
||||
/* this creates new links between copied nodes,
|
||||
* as well as input links from unselected (when fromnode==NULL) !
|
||||
/* This creates new links between copied nodes.
|
||||
* If keep_inputs is set, also copies input links from unselected (when fromnode==NULL)!
|
||||
*/
|
||||
if (link->tonode && (link->tonode->flag & NODE_SELECT)) {
|
||||
if (link->tonode && (link->tonode->flag & NODE_SELECT)
|
||||
&& (keep_inputs || link->fromnode && (link->fromnode->flag & NODE_SELECT))) {
|
||||
newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink");
|
||||
newlink->flag = link->flag;
|
||||
newlink->tonode = link->tonode->new_node;
|
||||
@ -2096,6 +2098,8 @@ void NODE_OT_duplicate(wmOperatorType *ot)
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
||||
RNA_def_boolean(ot->srna, "keep_inputs", 0, "Keep Inputs", "Keep the input links to duplicated nodes");
|
||||
}
|
||||
|
||||
/* *************************** add link op ******************** */
|
||||
|
@ -101,11 +101,18 @@ void node_operatortypes(void)
|
||||
void ED_operatormacros_node(void)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
wmOperatorTypeMacro *mot;
|
||||
|
||||
ot= WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
|
||||
WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
|
||||
WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
|
||||
|
||||
/* modified operator call for duplicating with input links */
|
||||
ot= WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
|
||||
mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
|
||||
RNA_boolean_set(mot->ptr, "keep_inputs", 1);
|
||||
WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
|
||||
|
||||
ot= WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer", OPTYPE_UNDO);
|
||||
WM_operatortype_macro_define(ot, "NODE_OT_select");
|
||||
WM_operatortype_macro_define(ot, "NODE_OT_link_viewer");
|
||||
@ -155,6 +162,8 @@ void node_keymap(struct wmKeyConfig *keyconf)
|
||||
|
||||
WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
/* modified operator call for duplicating with input links */
|
||||
WM_keymap_add_item(keymap, "NODE_OT_duplicate_move_keep_inputs", DKEY, KM_PRESS, KM_ALT, 0);
|
||||
|
||||
WM_keymap_add_item(keymap, "NODE_OT_hide_toggle", HKEY, KM_PRESS, 0, 0);
|
||||
WM_keymap_add_item(keymap, "NODE_OT_mute_toggle", MKEY, KM_PRESS, 0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user