Custom Properties: support default values for strings

Differential Revision: https://developer.blender.org/D8102
This commit is contained in:
Demeter Dzadik 2020-06-30 15:01:56 +02:00 committed by Brecht Van Lommel
parent e93663363e
commit 5b03f49302
3 changed files with 36 additions and 2 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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);