node toggle preview and hidden socket key shortcuts (Ctrl+H, Shift+H)
authorCampbell Barton <ideasman42@gmail.com>
Mon, 7 Jun 2010 20:03:40 +0000 (20:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 7 Jun 2010 20:03:40 +0000 (20:03 +0000)
release/scripts/ui/space_node.py
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/node_state.c

index db641a4..3658350 100644 (file)
@@ -139,8 +139,10 @@ class NODE_MT_node(bpy.types.Menu):
 
         layout.separator()
 
-        layout.operator("node.hide")
-        layout.operator("node.mute")
+        layout.operator("node.hide_toggle")
+        layout.operator("node.mute_toggle")
+        layout.operator("node.preview_toggle")
+        layout.operator("node.hide_socket_toggle")
 
         # XXX
         # layout.operator("node.rename")
index ff93f70..befb37a 100644 (file)
@@ -1988,49 +1988,132 @@ void NODE_OT_group_make(wmOperatorType *ot)
 
 /* ****************** Hide operator *********************** */
 
-static int node_hide_exec(bContext *C, wmOperator *op)
+static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag)
 {
-       SpaceNode *snode= CTX_wm_space_node(C);
+       int tot_eq= 0, tot_neq= 0;
        bNode *node;
-       int nothidden=0, ishidden=0;
-       
-       /* sanity checking (poll callback checks this already) */
-       if((snode == NULL) || (snode->edittree == NULL))
-               return OPERATOR_CANCELLED;
-       
+
        for(node= snode->edittree->nodes.first; node; node= node->next) {
                if(node->flag & SELECT) {
-                       if(node->flag & NODE_HIDDEN)
-                               ishidden++;
+                       if(node->flag & toggle_flag)
+                               tot_eq++;
                        else
-                               nothidden++;
+                               tot_neq++;
                }
        }
        for(node= snode->edittree->nodes.first; node; node= node->next) {
                if(node->flag & SELECT) {
-                       if( (ishidden && nothidden) || ishidden==0)
-                               node->flag |= NODE_HIDDEN;
-                       else 
-                               node->flag &= ~NODE_HIDDEN;
+                       if( (tot_eq && tot_neq) || tot_eq==0)
+                               node->flag |= toggle_flag;
+                       else
+                               node->flag &= ~toggle_flag;
                }
        }
+}
+
+static int node_hide_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode= CTX_wm_space_node(C);
+       
+       /* sanity checking (poll callback checks this already) */
+       if((snode == NULL) || (snode->edittree == NULL))
+               return OPERATOR_CANCELLED;
+       
+       node_flag_toggle_exec(snode, NODE_HIDDEN);
        
        snode_notify(C, snode);
        
        return OPERATOR_FINISHED;
 }
 
-void NODE_OT_hide(wmOperatorType *ot)
+void NODE_OT_hide_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Hide";
-       ot->description= "Toggle hiding of the nodes";
-       ot->idname= "NODE_OT_hide";
+       ot->description= "Toggle hiding of selected nodes";
+       ot->idname= "NODE_OT_hide_toggle";
        
        /* callbacks */
        ot->exec= node_hide_exec;
        ot->poll= ED_operator_node_active;
-       
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int node_preview_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode= CTX_wm_space_node(C);
+
+       /* sanity checking (poll callback checks this already) */
+       if((snode == NULL) || (snode->edittree == NULL))
+               return OPERATOR_CANCELLED;
+
+       node_flag_toggle_exec(snode, NODE_PREVIEW);
+
+       snode_notify(C, snode);
+
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_preview_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Node Preview";
+       ot->description= "Toggle preview display for selected nodes";
+       ot->idname= "NODE_OT_preview_toggle";
+
+       /* callbacks */
+       ot->exec= node_preview_exec;
+       ot->poll= ED_operator_node_active;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int node_socket_toggle_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode= CTX_wm_space_node(C);
+       bNode *node;
+       int hidden= 0;
+
+       /* sanity checking (poll callback checks this already) */
+       if((snode == NULL) || (snode->edittree == NULL))
+               return OPERATOR_CANCELLED;
+
+       for(node= snode->edittree->nodes.first; node; node= node->next) {
+               if(node->flag & SELECT) {
+                       if(node_has_hidden_sockets(node)) {
+                               hidden= 1;
+                               break;
+                       }
+               }
+       }
+
+       for(node= snode->edittree->nodes.first; node; node= node->next) {
+               if(node->flag & SELECT) {
+                       node_set_hidden_sockets(snode, node, !hidden);
+               }
+       }
+
+       node_tree_verify_groups(snode->nodetree);
+
+       snode_notify(C, snode);
+
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_hide_socket_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Hidden Node Sockets";
+       ot->description= "Toggle unused node socket display";
+       ot->idname= "NODE_OT_hide_socket_toggle";
+
+       /* callbacks */
+       ot->exec= node_socket_toggle_exec;
+       ot->poll= ED_operator_node_active;
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
@@ -2060,12 +2143,12 @@ static int node_mute_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void NODE_OT_mute(wmOperatorType *ot)
+void NODE_OT_mute_toggle(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Mute";
+       ot->name= "Toggle Node Mute";
        ot->description= "Toggle muting of the nodes";
-       ot->idname= "NODE_OT_mute";
+       ot->idname= "NODE_OT_mute_toggle";
        
        /* callbacks */
        ot->exec= node_mute_exec;
index 9cbd3ab..77fda06 100644 (file)
@@ -90,6 +90,8 @@ bNode *node_tree_get_editgroup(bNodeTree *ntree);
 void node_tree_verify_groups(bNodeTree *nodetree);
 void snode_autoconnect(SpaceNode *snode, int allow_multiple, int replace);
 int node_has_hidden_sockets(bNode *node);
+void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set);
+
 
 void NODE_OT_duplicate(struct wmOperatorType *ot);
 void NODE_OT_delete(struct wmOperatorType *ot);
@@ -103,8 +105,10 @@ void NODE_OT_group_make(struct wmOperatorType *ot);
 void NODE_OT_group_ungroup(struct wmOperatorType *ot);
 void NODE_OT_group_edit(struct wmOperatorType *ot);
 
-void NODE_OT_mute(struct wmOperatorType *ot);
-void NODE_OT_hide(struct wmOperatorType *ot);
+void NODE_OT_mute_toggle(struct wmOperatorType *ot);
+void NODE_OT_hide_toggle(struct wmOperatorType *ot);
+void NODE_OT_hide_socket_toggle(struct wmOperatorType *ot);
+void NODE_OT_preview_toggle(struct wmOperatorType *ot);
 
 void NODE_OT_show_cyclic_dependencies(struct wmOperatorType *ot);
 void NODE_OT_link_viewer(struct wmOperatorType *ot);
index 5b8e6fe..654fdc6 100644 (file)
@@ -57,8 +57,10 @@ void node_operatortypes(void)
 
        WM_operatortype_append(NODE_OT_view_all);
        WM_operatortype_append(NODE_OT_visibility_toggle);
-       WM_operatortype_append(NODE_OT_mute);
-       WM_operatortype_append(NODE_OT_hide);
+       WM_operatortype_append(NODE_OT_mute_toggle);
+       WM_operatortype_append(NODE_OT_hide_toggle);
+       WM_operatortype_append(NODE_OT_preview_toggle);
+       WM_operatortype_append(NODE_OT_hide_socket_toggle);
        WM_operatortype_append(NODE_OT_show_cyclic_dependencies);
        
        WM_operatortype_append(NODE_OT_duplicate);
@@ -143,8 +145,10 @@ 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);
        
-       WM_keymap_add_item(keymap, "NODE_OT_hide", HKEY, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "NODE_OT_mute", MKEY, KM_PRESS, 0, 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);
+       WM_keymap_add_item(keymap, "NODE_OT_preview_toggle", HKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "NODE_OT_hide_socket_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
        
        WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
        
index 43c80f6..6b3cfd1 100644 (file)
 
 /* **************** Node Header Buttons ************** */
 
-static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
-{
+/* note: call node_tree_verify_groups(snode->nodetree) after this
+ */
+void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
+{      
        bNodeSocket *sock;
-       
-       /* unhide all */
-       if( node_has_hidden_sockets(node) ) {
+
+       if(set==0) {
                for(sock= node->inputs.first; sock; sock= sock->next)
                        sock->flag &= ~SOCK_HIDDEN;
                for(sock= node->outputs.first; sock; sock= sock->next)
@@ -64,7 +65,7 @@ static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
        }
        else {
                bNode *gnode= node_tree_get_editgroup(snode->nodetree);
-               
+
                /* hiding inside group should not break links in other group users */
                if(gnode) {
                        nodeGroupSocketUseFlags((bNodeTree *)gnode->id);
@@ -89,7 +90,11 @@ static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
                        }
                }
        }
+}
 
+static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
+{
+       node_set_hidden_sockets(snode, node, !node_has_hidden_sockets(node));
        node_tree_verify_groups(snode->nodetree);
 }