From 79281336c0555351a1580e4055a57a75509c0832 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 1 Sep 2021 15:06:25 +0200 Subject: 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. --- source/blender/makesrna/intern/rna_space.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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, -- cgit v1.2.3