Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2010-02-08 12:22:17 +0300
committerJoshua Leung <aligorith@gmail.com>2010-02-08 12:22:17 +0300
commit46c0caf7c6eeace0ec218f7a51e5810d0bb3020e (patch)
tree1586a9aaf1d04637d168b4b84d156cc93e5e8a17 /source/blender/makesrna/intern/rna_access.c
parent3a12f3788052cf635c0465e9fef8a3cb4284e604 (diff)
RNA - Added reset to defaults support for Strings too
Many string properties need tweaks to work correctly with this, since many don't have any reasonable defaults set (especially name fields, which often get cleared with these changes).
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r--source/blender/makesrna/intern/rna_access.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 9dd03ed7477..782031d12c6 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1775,6 +1775,36 @@ void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *val
}
}
+void RNA_property_string_get_default(PointerRNA *ptr, PropertyRNA *prop, char *value)
+{
+ StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
+ strcpy(value, sprop->defaultvalue);
+}
+
+char *RNA_property_string_get_default_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen)
+{
+ char *buf;
+ int length;
+
+ length= RNA_property_string_default_length(ptr, prop);
+
+ if(length+1 < fixedlen)
+ buf= fixedbuf;
+ else
+ buf= MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
+
+ RNA_property_string_get_default(ptr, prop, buf);
+
+ return buf;
+}
+
+/* this is the length without \0 terminator */
+int RNA_property_string_default_length(PointerRNA *ptr, PropertyRNA *prop)
+{
+ StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
+ return strlen(sprop->defaultvalue);
+}
+
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
{
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
@@ -4316,8 +4346,15 @@ int RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
return 1;
}
+ case PROP_STRING:
+ {
+ char *value= RNA_property_string_get_default_alloc(ptr, prop, NULL, 0);
+ RNA_property_string_set(ptr, prop, value);
+ MEM_freeN(value);
+ return 1;
+ }
+
//case PROP_POINTER:
- //case PROP_STRING:
default:
// FIXME: many of the other types such as strings and pointers need this implemented too!
return 0;