diff options
author | Julian Eisel <julian@blender.org> | 2021-09-23 15:43:21 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-09-23 15:46:13 +0300 |
commit | 222fd1abf09ae65b7082f58bf2ac43422c77162c (patch) | |
tree | aeb1c3723f8e3d80723e28660d35889c3dfdeaa9 /source/blender/makesrna/intern/rna_space.c | |
parent | 059d01d42e049a5d4a42f81c8b860540127efeb6 (diff) |
Asset Browser: Disable metadata editing for external asset libraries
Buttons to edit asset metadata are now disabled for assets from an
external library (i.e. assets not stored in the current .blend file).
Their tooltips explain why they are disabled.
Had to do some RNA trickery to disable the metadata properties at RNA
level, not at UI script level.
The basic idea is:
* Local data-block assets set the data-block as owning ID for the asset
metadata RNA pointer now.
* That way we can use the owner ID to see where the metadata belongs to
and decide if it's editable that way.
* Additionaly, some Python operators needed better polling so they show
as grayed out, and don't just fail.
One important thing: Custom properties of the metadata can still be
edited. The edits won't be saved however. Would be nice to disable that,
but it's currently not supported on BPY/IDProperty/RNA level.
Addresses T82943.
Differential Revision: https://developer.blender.org/D12127
Diffstat (limited to 'source/blender/makesrna/intern/rna_space.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index a05cef7a1cd..7b57c0fd6a5 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2616,6 +2616,40 @@ static uint64_t rna_FileAssetSelectParams_asset_category_get(PointerRNA *ptr) return params->filter_id; } +static PointerRNA rna_FileBrowser_FileSelectEntry_asset_data_get(PointerRNA *ptr) +{ + const FileDirEntry *entry = ptr->data; + + /* Note that the owning ID of the RNA pointer (`ptr->owner_id`) has to be set carefully: + * Local IDs (`entry->id`) own their asset metadata themselves. Asset metadata from other blend + * files are owned by the file browser (`entry`). Only if this is set correctly, we can tell from + * the metadata RNA pointer if the metadata is stored locally and can thus be edited or not. */ + + if (entry->id) { + PointerRNA id_ptr; + RNA_id_pointer_create(entry->id, &id_ptr); + return rna_pointer_inherit_refine(&id_ptr, &RNA_AssetMetaData, entry->asset_data); + } + + return rna_pointer_inherit_refine(ptr, &RNA_AssetMetaData, entry->asset_data); +} + +static int rna_FileBrowser_FileSelectEntry_name_editable(PointerRNA *ptr, const char **r_info) +{ + const FileDirEntry *entry = ptr->data; + + /* This actually always returns 0 (the name is never editable) but we want to get a disabled + * message returned to `r_info` in some cases. */ + + if (entry->asset_data) { + PointerRNA asset_data_ptr = rna_FileBrowser_FileSelectEntry_asset_data_get(ptr); + /* Get disabled hint from asset metadata polling. */ + rna_AssetMetaData_editable(&asset_data_ptr, r_info); + } + + return 0; +} + static void rna_FileBrowser_FileSelectEntry_name_get(PointerRNA *ptr, char *value) { const FileDirEntry *entry = ptr->data; @@ -2672,12 +2706,6 @@ static int rna_FileBrowser_FileSelectEntry_preview_icon_id_get(PointerRNA *ptr) return ED_file_icon(entry); } -static PointerRNA rna_FileBrowser_FileSelectEntry_asset_data_get(PointerRNA *ptr) -{ - const FileDirEntry *entry = ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_AssetMetaData, entry->asset_data); -} - static StructRNA *rna_FileBrowser_params_typef(PointerRNA *ptr) { SpaceFile *sfile = ptr->data; @@ -6260,12 +6288,13 @@ static void rna_def_fileselect_entry(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "File Select Entry", "A file viewable in the File Browser"); prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_editable_func(prop, "rna_FileBrowser_FileSelectEntry_name_editable"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_string_funcs(prop, "rna_FileBrowser_FileSelectEntry_name_get", "rna_FileBrowser_FileSelectEntry_name_length", NULL); RNA_def_property_ui_text(prop, "Name", ""); - 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); |