File/Asset Browser: Extend file-entry and asset handle Python API

Adds the following to `bpy.types.FileSelectEntry`:
* `id_type`: The data-block type the file represenets, if any.
* `local_id`: The local data-block it represents, if any (assets only).

And the following to `bpy.types.AssetHandle`:
* `local_id`: The local data-block the asset represents, if any.

This kind of information and the references are important for asset related
operators and UIs. They will be used by upcoming Pose Library features.
This commit is contained in:
Julian Eisel 2021-07-09 15:50:21 +02:00 committed by Sybren A. Stüvel
parent a26a059244
commit 55d48defc5
2 changed files with 64 additions and 0 deletions

View File

@ -143,6 +143,13 @@ static void rna_AssetHandle_get_full_library_path(
ED_asset_handle_get_full_library_path(C, library, &asset, r_result);
}
static PointerRNA rna_AssetHandle_local_id_get(PointerRNA *ptr)
{
const AssetHandle *asset = ptr->data;
ID *id = ED_assetlist_asset_local_id_get(asset);
return rna_pointer_inherit_refine(ptr, &RNA_ID, id);
}
static void rna_AssetHandle_file_data_set(PointerRNA *ptr,
PointerRNA value,
struct ReportList *UNUSED(reports))
@ -344,6 +351,15 @@ static void rna_def_asset_handle(BlenderRNA *brna)
prop, "rna_AssetHandle_file_data_get", "rna_AssetHandle_file_data_set", NULL, NULL);
RNA_def_property_ui_text(prop, "File Entry", "File data used to refer to the asset");
prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "ID");
RNA_def_property_pointer_funcs(prop, "rna_AssetHandle_local_id_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop,
"",
"The local data-block this asset represents; only valid if that is a "
"data-block in this file");
RNA_def_property_flag(prop, PROP_HIDDEN);
rna_def_asset_handle_api(srna);
}

View File

@ -2694,6 +2694,32 @@ 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;
return entry->blentype;
}
static PointerRNA rna_FileBrowser_FileSelectEntry_local_id_get(PointerRNA *ptr)
{
const FileDirEntry *entry = ptr->data;
return rna_pointer_inherit_refine(ptr, &RNA_ID, entry->id);
}
static int rna_FileBrowser_FileSelectEntry_preview_icon_id_get(PointerRNA *ptr)
{
const FileDirEntry *entry = ptr->data;
@ -6306,6 +6332,28 @@ 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, "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,
"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 ('NONE' otherwise)");
prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "ID");
RNA_def_property_pointer_funcs(
prop, "rna_FileBrowser_FileSelectEntry_local_id_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop,
"",
"The local data-block this file represents; only valid if that is a "
"data-block in this file");
RNA_def_property_flag(prop, PROP_HIDDEN);
prop = RNA_def_int(
srna,
"preview_icon_id",