[Bf-blender-cvs] [ca475479eb2] master: Fix Asset Browser showing old name after renaming data-block

Julian Eisel noreply at git.blender.org
Thu Jan 21 22:26:07 CET 2021


Commit: ca475479eb26b4798857b4e67f03eea89324da4b
Author: Julian Eisel
Date:   Thu Jan 21 21:40:25 2021 +0100
Branches: master
https://developer.blender.org/rBca475479eb26b4798857b4e67f03eea89324da4b

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

===================================================================

M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h

===================================================================

diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index d66219c7549..a50751b6b96 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -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(
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 193b141d528..9fe380e382f 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -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);
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index a1ccf11b8e3..51f8b58da62 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -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,
 };
 
 /** \} */



More information about the Bf-blender-cvs mailing list