diff options
author | Julian Eisel <julian@blender.org> | 2021-09-01 16:06:25 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-09-01 16:12:50 +0300 |
commit | 79281336c0555351a1580e4055a57a75509c0832 (patch) | |
tree | 44fd4f659b6bf39ad37fa5b07cd11779270bbcef /source/blender/makesrna/intern/rna_space.c | |
parent | 8355e3fc778f2bb2199b8a57a876addab55f606e (diff) |
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.
Diffstat (limited to 'source/blender/makesrna/intern/rna_space.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 23 |
1 files changed, 23 insertions, 0 deletions
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, |