[Bf-blender-cvs] [da1038c] master: UI: Copy to selected nodes now filtered by type

Campbell Barton noreply at git.blender.org
Wed May 13 22:31:03 CEST 2015


Commit: da1038c768557c88d29ce74a98026ca4915ab2c3
Author: Campbell Barton
Date:   Thu May 14 06:23:41 2015 +1000
Branches: master
https://developer.blender.org/rBda1038c768557c88d29ce74a98026ca4915ab2c3

UI: Copy to selected nodes now filtered by type

Was needed because sockets are very generic type which would match on unrelated values.

===================================================================

M	source/blender/editors/interface/interface_ops.c

===================================================================

diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index d13078f..643397b 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -44,6 +44,7 @@
 #include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_global.h"
+#include "BKE_node.h"
 #include "BKE_text.h" /* for UI_OT_reports_to_text */
 #include "BKE_report.h"
 
@@ -278,13 +279,48 @@ bool UI_context_copy_to_selected_list(
 	else if (RNA_struct_is_a(ptr->type, &RNA_Sequence)) {
 		*r_lb = CTX_data_collection_get(C, "selected_editable_sequences");
 	}
-	else if (RNA_struct_is_a(ptr->type, &RNA_Node)) {
-		*r_lb = CTX_data_collection_get(C, "selected_nodes");
-	}
-	else if (RNA_struct_is_a(ptr->type, &RNA_NodeSocket)) {
-		if ((*r_path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Node)) != NULL) {
-			*r_lb = CTX_data_collection_get(C, "selected_nodes");
+	else if (RNA_struct_is_a(ptr->type, &RNA_Node) ||
+	         RNA_struct_is_a(ptr->type, &RNA_NodeSocket))
+	{
+		ListBase lb = {NULL, NULL};
+		char *path = NULL;
+		bNode *node = NULL;
+
+		/* Get the node we're editing */
+		if (RNA_struct_is_a(ptr->type, &RNA_NodeSocket)) {
+			bNodeTree *ntree = ptr->id.data;
+			bNodeSocket *sock = ptr->data;
+			if (nodeFindNode(ntree, sock, &node, NULL)) {
+				if ((path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Node)) != NULL) {
+					/* we're good! */
+				}
+				else {
+					node = NULL;
+				}
+			}
+		}
+		else {
+			node = ptr->data;
+		}
+
+		/* Now filter by type */
+		if (node) {
+			CollectionPointerLink *link, *link_next;
+			lb = CTX_data_collection_get(C, "selected_nodes");
+
+			for (link = lb.first; link; link = link_next) {
+				bNode *node_data = link->ptr.data;
+				link_next = link->next;
+
+				if (node_data->type != node->type) {
+					BLI_remlink(&lb, link);
+					MEM_freeN(link);
+				}
+			}
 		}
+
+		*r_lb = lb;
+		*r_path = path;
 	}
 	else if (ptr->id.data) {
 		ID *id = ptr->id.data;




More information about the Bf-blender-cvs mailing list