[Bf-blender-cvs] [c2ee1af8fa8] asset-browser-poselib: Avoid warning when using FileSelectEntry.id_type on a non-ID file

Julian Eisel noreply at git.blender.org
Thu Apr 22 21:13:39 CEST 2021


Commit: c2ee1af8fa8369047971c701cc27d517bbe8071a
Author: Julian Eisel
Date:   Thu Apr 22 21:09:19 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rBc2ee1af8fa8369047971c701cc27d517bbe8071a

Avoid warning when using FileSelectEntry.id_type on a non-ID file

If the file doesn't represent an ID, the value will be `'NONE'` in
Python. Otherwise a valid ID type (e.g. `'ACTION'`, `'OBJECT'`, etc.).

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

M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 8900e01adf2..08773aeb111 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2684,6 +2684,20 @@ static int rna_FileBrowser_FileSelectEntry_name_length(PointerRNA *ptr)
   return (int)strlen(entry->name);
 }
 
+static const EnumPropertyItem *rna_FileBrowser_FileSelectEntry_id_type_itemf(
+    bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
+{
+  const FileDirEntry *entry = ptr->data;
+  if (entry->blentype == 0) {
+    const static EnumPropertyItem none_items[] = {
+        {0, "NONE", 0, "None", ""},
+    };
+    return none_items;
+  }
+
+  return rna_enum_id_type_items;
+}
+
 static int rna_FileBrowser_FileSelectEntry_id_type_get(PointerRNA *ptr)
 {
   const FileDirEntry *entry = ptr->data;
@@ -6210,11 +6224,15 @@ static void rna_def_fileselect_entry(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_items(prop, rna_enum_id_type_items);
-  RNA_def_property_enum_funcs(prop, "rna_FileBrowser_FileSelectEntry_id_type_get", NULL, NULL);
+  RNA_def_property_enum_funcs(prop,
+                              "rna_FileBrowser_FileSelectEntry_id_type_get",
+                              NULL,
+                              "rna_FileBrowser_FileSelectEntry_id_type_itemf");
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-  RNA_def_property_ui_text(prop,
-                           "Data-block Type",
-                           "The type of the data-block, if the file represents one (0 otherwise)");
+  RNA_def_property_ui_text(
+      prop,
+      "Data-block Type",
+      "The type of the data-block, if the file represents one ('NONE' otherwise)");
 
   prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
   RNA_def_property_struct_type(prop, "ID");



More information about the Bf-blender-cvs mailing list