Fix Asset Browser showing old name after renaming data-block

The "Current File" asset library didn't get refreshed after the data-block name
changed. But rather than entirely refreshing the file list, or doing possibly
problematic partial refreshes, reference the data-block name directly, so a
simple redraw gets the new name displayed.

Addresses T83751
This commit is contained in:
Julian Eisel 2021-01-21 21:40:25 +01:00
parent 41982af6a0
commit ca475479eb
Notes: blender-bot 2023-02-13 23:17:13 +01:00
Referenced by commit 3469e06c1a, Fix memory leak when opening file browser
Referenced by issue #83751, After renaming, Asset Browser shows old data-block name
3 changed files with 32 additions and 5 deletions

View File

@ -276,6 +276,7 @@ typedef struct FileListInternEntry {
char *redirection_path;
/** not strictly needed, but used during sorting, avoids to have to recompute it there... */
char *name;
bool free_name;
/**
* This is data from the current main, represented by this file. It's crucial that this is
@ -1366,7 +1367,7 @@ static bool filelist_checkdir_main_assets(struct FileList *UNUSED(filelist),
static void filelist_entry_clear(FileDirEntry *entry)
{
if (entry->name) {
if (entry->name && ((entry->flags & FILE_ENTRY_NAME_FREE) != 0)) {
MEM_freeN(entry->name);
}
if (entry->description) {
@ -1451,7 +1452,7 @@ static void filelist_intern_entry_free(FileListInternEntry *entry)
if (entry->redirection_path) {
MEM_freeN(entry->redirection_path);
}
if (entry->name) {
if (entry->name && entry->free_name) {
MEM_freeN(entry->name);
}
/* If we own the asset-data (it was generated from external file data), free it. */
@ -1953,7 +1954,7 @@ static FileDirEntry *filelist_file_create_entry(FileList *filelist, const int in
ret->entry = rev;
ret->relpath = BLI_strdup(entry->relpath);
ret->name = BLI_strdup(entry->name);
ret->name = entry->free_name ? BLI_strdup(entry->name) : entry->name;
ret->description = BLI_strdupcat(filelist->filelist.root, entry->relpath);
memcpy(ret->uuid, entry->uuid, sizeof(ret->uuid));
ret->blentype = entry->blentype;
@ -3175,6 +3176,7 @@ static void filelist_readjob_do(const bool do_lib,
entry->relpath = BLI_strdup(dir + 2); /* + 2 to remove '//'
* added by BLI_path_rel to rel_subdir. */
entry->name = BLI_strdup(fileentry_uiname(root, entry->relpath, entry->typeflag, dir));
entry->free_name = true;
/* Here we decide whether current filedirentry is to be listed too, or not. */
if (max_recursion && (is_lib || (recursion_level <= max_recursion))) {
@ -3288,7 +3290,8 @@ static void filelist_readjob_main_assets(Main *current_main,
entry = MEM_callocN(sizeof(*entry), __func__);
entry->relpath = BLI_strdup(id_code_name);
entry->name = BLI_strdup(id_iter->name + 2);
entry->name = id_iter->name + 2;
entry->free_name = false;
entry->typeflag |= FILE_TYPE_BLENDERLIB | FILE_TYPE_ASSET;
entry->blentype = GS(id_iter->name);
*((uint32_t *)entry->uuid) = atomic_add_and_fetch_uint32(

View File

@ -463,6 +463,12 @@ static void file_main_region_listener(const wmRegionListenerParams *params)
break;
}
break;
case NC_ID:
if (ELEM(wmn->action, NA_RENAME)) {
/* In case the filelist shows ID names. */
ED_region_tag_redraw(region);
}
break;
}
}
@ -650,6 +656,21 @@ static void file_tools_region_listener(const wmRegionListenerParams *UNUSED(para
{
}
static void file_tool_props_region_listener(const wmRegionListenerParams *params)
{
const wmNotifier *wmn = params->notifier;
ARegion *region = params->region;
switch (wmn->category) {
case NC_ID:
if (ELEM(wmn->action, NA_RENAME)) {
/* In case the filelist shows ID names. */
ED_region_tag_redraw(region);
}
break;
}
}
/* add handlers, stuff you only do once or on area/region changes */
static void file_header_region_init(wmWindowManager *wm, ARegion *region)
{
@ -916,7 +937,7 @@ void ED_spacetype_file(void)
art->prefsizex = 240;
art->prefsizey = 60;
art->keymapflag = ED_KEYMAP_UI;
art->listener = file_tools_region_listener;
art->listener = file_tool_props_region_listener;
art->init = file_tools_region_init;
art->draw = file_tools_region_draw;
BLI_addhead(&st->regiontypes, art);

View File

@ -1087,6 +1087,8 @@ typedef struct FileDirEntry {
struct FileDirEntry *next, *prev;
int uuid[4];
/* Name needs freeing if FILE_ENTRY_NAME_FREE is set. Otherwise this is a direct pointer to a
* name buffer. */
char *name;
char *description;
@ -1165,6 +1167,7 @@ enum {
/* FileDirEntry.flags */
enum {
FILE_ENTRY_INVALID_PREVIEW = 1 << 0, /* The preview for this entry could not be generated. */
FILE_ENTRY_NAME_FREE = 1 << 1,
};
/** \} */