[Bf-blender-cvs] [6238fb4] master: UI: de-duplicate UI_OT_copy_to_selected_button poll/exec

Campbell Barton noreply at git.blender.org
Fri Apr 11 00:35:19 CEST 2014


Commit: 6238fb4c43682f37172ddbb5a6bdac3dcd2a3aa6
Author: Campbell Barton
Date:   Fri Apr 11 08:33:54 2014 +1000
https://developer.blender.org/rB6238fb4c43682f37172ddbb5a6bdac3dcd2a3aa6

UI: de-duplicate UI_OT_copy_to_selected_button poll/exec

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

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 4bbccec..cef7128 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -283,14 +283,24 @@ static bool copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb, bo
 	return true;
 }
 
-static int copy_to_selected_button_poll(bContext *C)
+/**
+ * called from both exec & poll
+ *
+ * \note: normally we wouldn't call a loop from within a poll function,
+ * However this is a special case, and for regular poll calls, getting
+ * the context from the button will fail early.
+ */
+static bool copy_to_selected_button(bContext *C, bool all, bool poll)
 {
 	PointerRNA ptr, lptr, idptr;
 	PropertyRNA *prop, *lprop;
-	int index, success = 0;
+	bool success = false;
+	int index;
 
+	/* try to reset the nominated setting to its default value */
 	uiContextActiveProperty(C, &ptr, &prop, &index);
 
+	/* if there is a valid property that is editable... */
 	if (ptr.data && prop) {
 		char *path = NULL;
 		bool use_path;
@@ -314,8 +324,18 @@ static int copy_to_selected_button_poll(bContext *C)
 					}
 
 					if (lprop == prop) {
-						if (RNA_property_editable(&lptr, prop))
-							success = 1;
+						if (RNA_property_editable(&lptr, lprop)) {
+							if (poll) {
+								success = true;
+								break;
+							}
+							else {
+								if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
+									RNA_property_update(C, &lptr, prop);
+									success = true;
+								}
+							}
+						}
 					}
 				}
 			}
@@ -330,58 +350,19 @@ static int copy_to_selected_button_poll(bContext *C)
 	return success;
 }
 
-static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
+static int copy_to_selected_button_poll(bContext *C)
 {
-	PointerRNA ptr, lptr, idptr;
-	PropertyRNA *prop, *lprop;
-	bool success = false;
-	int index;
-	const bool all = RNA_boolean_get(op->ptr, "all");
-
-	/* try to reset the nominated setting to its default value */
-	uiContextActiveProperty(C, &ptr, &prop, &index);
-	
-	/* if there is a valid property that is editable... */
-	if (ptr.data && prop) {
-		char *path = NULL;
-		bool use_path;
-		CollectionPointerLink *link;
-		ListBase lb;
-
-		if (!copy_to_selected_list(C, &ptr, &lb, &use_path))
-			return OPERATOR_CANCELLED;
+	return copy_to_selected_button(C, false, true);
+}
 
-		if (!use_path || (path = RNA_path_from_ID_to_property(&ptr, prop))) {
-			for (link = lb.first; link; link = link->next) {
-				if (link->ptr.data != ptr.data) {
-					if (use_path) {
-						lprop = NULL;
-						RNA_id_pointer_create(link->ptr.id.data, &idptr);
-						RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
-					}
-					else {
-						lptr = link->ptr;
-						lprop = prop;
-					}
+static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
+{
+	bool success;
 
-					if (lprop == prop) {
-						if (RNA_property_editable(&lptr, lprop)) {
-							if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
-								RNA_property_update(C, &lptr, prop);
-								success = true;
-							}
-						}
-					}
-				}
-			}
+	const bool all = RNA_boolean_get(op->ptr, "all");
 
-			if (path)
-				MEM_freeN(path);
-		}
+	success = copy_to_selected_button(C, all, false);
 
-		BLI_freelistN(&lb);
-	}
-	
 	return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }




More information about the Bf-blender-cvs mailing list