[Bf-blender-cvs] [5b03f49302a] master: Custom Properties: support default values for strings

Demeter Dzadik noreply at git.blender.org
Tue Jun 30 15:09:27 CEST 2020


Commit: 5b03f49302a39577f2373906cfba19feebfaa9ba
Author: Demeter Dzadik
Date:   Tue Jun 30 15:01:56 2020 +0200
Branches: master
https://developer.blender.org/rB5b03f49302a39577f2373906cfba19feebfaa9ba

Custom Properties: support default values for strings

Differential Revision: https://developer.blender.org/D8102

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

M	release/scripts/modules/rna_prop_ui.py
M	release/scripts/startup/bl_operators/wm.py
M	source/blender/makesrna/intern/rna_access.c

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

diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py
index 8dda8c90f85..662c1d908fc 100644
--- a/release/scripts/modules/rna_prop_ui.py
+++ b/release/scripts/modules/rna_prop_ui.py
@@ -130,7 +130,7 @@ def rna_idprop_ui_prop_default_set(item, prop, value):
     try:
         prop_type, is_array = rna_idprop_value_item_type(item[prop])
 
-        if prop_type in {int, float}:
+        if prop_type in {int, float, str}:
             if is_array and isinstance(value, ARRAY_TYPES):
                 value = [prop_type(item) for item in value]
                 if any(value):
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 04bd5687364..a543ea6685c 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -1457,7 +1457,7 @@ class WM_OT_properties_edit(Operator):
         proptype, is_array = rna_idprop_value_item_type(value)
 
         row = layout.row()
-        row.enabled = proptype in {int, float}
+        row.enabled = proptype in {int, float, str}
         row.prop(self, "default")
 
         row = layout.row(align=True)
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index cb9679ad925..79cf993e0cc 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -3473,6 +3473,24 @@ void RNA_property_string_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop,
 {
   StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop);
 
+  if (prop->magic != RNA_MAGIC) {
+    /* attempt to get the local ID values */
+    const IDProperty *idp_ui = rna_idproperty_ui(prop);
+
+    if (idp_ui) {
+      IDProperty *item;
+
+      item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_STRING);
+      if (item) {
+        strcpy(value, IDP_String(item));
+        return;
+      }
+    }
+
+    strcpy(value, "");
+    return;
+  }
+
   BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
   strcpy(value, sprop->defaultvalue);
@@ -3507,6 +3525,22 @@ int RNA_property_string_default_length(PointerRNA *UNUSED(ptr), PropertyRNA *pro
 {
   StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop);
 
+  if (prop->magic != RNA_MAGIC) {
+    /* attempt to get the local ID values */
+    const IDProperty *idp_ui = rna_idproperty_ui(prop);
+
+    if (idp_ui) {
+      IDProperty *item;
+
+      item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_STRING);
+      if (item) {
+        return strlen(IDP_String(item));
+      }
+    }
+
+    return 0;
+  }
+
   BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
   return strlen(sprop->defaultvalue);



More information about the Bf-blender-cvs mailing list