[Bf-blender-cvs] [79281336c05] master: File Browser/BPY: Expose relative path of a file via BPY

Julian Eisel noreply at git.blender.org
Wed Sep 1 15:30:23 CEST 2021


Commit: 79281336c0555351a1580e4055a57a75509c0832
Author: Julian Eisel
Date:   Wed Sep 1 15:06:25 2021 +0200
Branches: master
https://developer.blender.org/rB79281336c0555351a1580e4055a57a75509c0832

File Browser/BPY: Expose relative path of a file via BPY

There were requests to be able to track the file selection in the File
Browser. Just using the file name for that wouldn't if the file browser
has the recursive display enabled. File names could be duplicated then.
So expose the entire path relative to the currently displayed directory.

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

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 886d38356cc..09fa2c84005 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2608,6 +2608,18 @@ static int rna_FileBrowser_FileSelectEntry_name_length(PointerRNA *ptr)
   return (int)strlen(entry->name);
 }
 
+static void rna_FileBrowser_FileSelectEntry_relative_path_get(PointerRNA *ptr, char *value)
+{
+  const FileDirEntry *entry = ptr->data;
+  strcpy(value, entry->relpath);
+}
+
+static int rna_FileBrowser_FileSelectEntry_relative_path_length(PointerRNA *ptr)
+{
+  const FileDirEntry *entry = ptr->data;
+  return (int)strlen(entry->relpath);
+}
+
 static const EnumPropertyItem *rna_FileBrowser_FileSelectEntry_id_type_itemf(
     bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
 {
@@ -6184,6 +6196,17 @@ static void rna_def_fileselect_entry(BlenderRNA *brna)
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_struct_name_property(srna, prop);
 
+  prop = RNA_def_property(srna, "relative_path", PROP_STRING, PROP_NONE);
+  RNA_def_property_string_funcs(prop,
+                                "rna_FileBrowser_FileSelectEntry_relative_path_get",
+                                "rna_FileBrowser_FileSelectEntry_relative_path_length",
+                                NULL);
+  RNA_def_property_ui_text(prop,
+                           "Relative Path",
+                           "Path relative to the directory currently displayed in the File "
+                           "Browser (includes the file name)");
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
   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,



More information about the Bf-blender-cvs mailing list