Little modification of the duplicate operator on artist request: The default behavior...
authorLukas Toenne <lukas.toenne@googlemail.com>
Sun, 17 Jul 2011 18:04:28 +0000 (18:04 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Sun, 17 Jul 2011 18:04:28 +0000 (18:04 +0000)
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_ops.c

index e760c9021c25835787da5764e6d86cabbb79337d..36e8bc35e7304173b4d2115f6b351fb0f3c49fec 100644 (file)
@@ -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 ******************** */
index 4d181a3489489e75d3795e7609882755adffc037..905347d6b80f3f26846ed315826c25ed0de375a1 100644 (file)
@@ -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);