Asset Browser: Let "Clear Asset" act on entire selection

Users were confused that "Clear Asset" would only act on the clicked on
asset, not the entire selection. They would have to clear them one by
one, which can be quite annoying. The previous commit prepared the asset
clearing operator for this, so all this commit has to do is expose the
selected IDs to context.
This commit is contained in:
Julian Eisel
2023-04-25 16:52:23 +02:00
parent f22e2bab72
commit 20f54a5698
3 changed files with 31 additions and 0 deletions

View File

@@ -2188,6 +2188,14 @@ int filelist_file_find_id(const FileList *filelist, const ID *id)
return -1;
}
ID *filelist_entry_get_id(const FileList *filelist, const int index)
{
BLI_assert(index >= 0 && index < filelist->filelist.entries_filtered_num);
const FileListInternEntry *intern_entry = filelist->filelist_intern.filtered[index];
return intern_entry->local_data.id;
}
ID *filelist_file_get_id(const FileDirEntry *file)
{
return file->id;

View File

@@ -130,6 +130,10 @@ int filelist_file_find_id(const struct FileList *filelist, const struct ID *id);
* Get the ID a file represents (if any). For #FILE_MAIN, #FILE_MAIN_ASSET.
*/
struct ID *filelist_file_get_id(const struct FileDirEntry *file);
/**
* Same as #filelist_file_get_id(), but gets the file by index (doesn't require the file to be
* cached, uses #FileListInternEntry only). */
struct ID *filelist_entry_get_id(const struct FileList *filelist, int index);
bool filelist_uid_is_set(const FileUID uid);
void filelist_uid_unset(FileUID *r_uid);
void filelist_file_cache_slidingwindow_set(struct FileList *filelist, size_t window_size);

View File

@@ -823,6 +823,7 @@ const char *file_context_dir[] = {
"asset_library_ref",
"selected_asset_files",
"id",
"selected_ids",
NULL,
};
@@ -911,6 +912,24 @@ static int /*eContextResult*/ file_context(const bContext *C,
CTX_data_id_pointer_set(result, id);
return CTX_RESULT_OK;
}
if (CTX_data_equals(member, "selected_ids")) {
const int num_files_filtered = filelist_files_ensure(sfile->files);
for (int file_index = 0; file_index < num_files_filtered; file_index++) {
if (!filelist_entry_is_selected(sfile->files, file_index)) {
continue;
}
ID *id = filelist_entry_get_id(sfile->files, file_index);
if (!id) {
continue;
}
CTX_data_id_list_add(result, id);
}
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return CTX_RESULT_OK;
}
return CTX_RESULT_MEMBER_NOT_FOUND;
}