[Bf-blender-cvs] [32b33e91ebf] master: Asset Browser: Use directory name as default when adding asset libraries

Julian Eisel noreply at git.blender.org
Tue Feb 1 14:59:22 CET 2022


Commit: 32b33e91ebfa0629277ba28490ba9a842b0265ab
Author: Julian Eisel
Date:   Tue Feb 1 14:56:07 2022 +0100
Branches: master
https://developer.blender.org/rB32b33e91ebfa0629277ba28490ba9a842b0265ab

Asset Browser: Use directory name as default when adding asset libraries

When adding an asset library in the Preferences, set the name of the new
library to the chosen directory's name by default. That avoids having to
set it manually which can be annoying. Previously I thought it would be
nice to show the name button in red then, making the user aware that
they have to give it a name, but that appears to be more annoying than
useful/practical after all.

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

M	source/blender/editors/space_userpref/userpref_ops.c

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

diff --git a/source/blender/editors/space_userpref/userpref_ops.c b/source/blender/editors/space_userpref/userpref_ops.c
index d40229332fd..e4c11bc8668 100644
--- a/source/blender/editors/space_userpref/userpref_ops.c
+++ b/source/blender/editors/space_userpref/userpref_ops.c
@@ -30,6 +30,7 @@
 #ifdef WIN32
 #  include "BLI_winstuff.h"
 #endif
+#include "BLI_path_util.h"
 
 #include "BKE_context.h"
 #include "BKE_main.h"
@@ -142,16 +143,20 @@ static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot)
 
 static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *op)
 {
-  char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
+  char *path = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
+  char dirname[FILE_MAXFILE];
+
+  BLI_path_slash_rstrip(path);
+  BLI_split_file_part(path, dirname, sizeof(dirname));
 
   /* NULL is a valid directory path here. A library without path will be created then. */
-  BKE_preferences_asset_library_add(&U, NULL, directory);
+  BKE_preferences_asset_library_add(&U, dirname, path);
   U.runtime.is_dirty = true;
 
   /* There's no dedicated notifier for the Preferences. */
   WM_main_add_notifier(NC_WINDOW, NULL);
 
-  MEM_freeN(directory);
+  MEM_freeN(path);
   return OPERATOR_FINISHED;
 }



More information about the Bf-blender-cvs mailing list