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.
This commit is contained in:
Julian Eisel 2022-02-01 14:56:07 +01:00
parent 34449ba9a6
commit 32b33e91eb
1 changed files with 8 additions and 3 deletions

View File

@ -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;
}