diff --git a/scripts/startup/bl_ui/space_userpref.py b/scripts/startup/bl_ui/space_userpref.py index 80a6cb27441..ea427e3818e 100644 --- a/scripts/startup/bl_ui/space_userpref.py +++ b/scripts/startup/bl_ui/space_userpref.py @@ -1581,6 +1581,7 @@ class USERPREF_PT_file_paths_asset_libraries(FilePathsPanel, Panel): layout.prop(active_library, "path") layout.prop(active_library, "import_method", text="Import Method") layout.prop(active_library, "use_relative_path") + layout.prop(active_library, "is_default") class USERPREF_UL_asset_libraries(UIList): diff --git a/source/blender/editors/sculpt_paint/paint_ops.cc b/source/blender/editors/sculpt_paint/paint_ops.cc index 04603e86959..d91f7c73899 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_ops.cc @@ -1052,11 +1052,15 @@ static AssetWeakReference *brush_asset_create_weakref_hack(const bUserAssetLibra static const bUserAssetLibrary *brush_asset_get_editable_library() { - /* TODO: take into account which one is marked as default. */ - LISTBASE_FOREACH (const bUserAssetLibrary *, asset_library, &U.asset_libraries) { - return asset_library; + if (BLI_listbase_is_empty(&U.asset_libraries)) { + return nullptr; } - return nullptr; + LISTBASE_FOREACH (const bUserAssetLibrary *, asset_library, &U.asset_libraries) { + if (asset_library->flag & ASSET_LIBRARY_DEFAULT) { + return asset_library; + } + } + return static_cast(U.asset_libraries.first); } static void brush_asset_refresh_editable_library(const bContext *C) diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h index d3f7022cd3a..7245f635bce 100644 --- a/source/blender/makesdna/DNA_asset_types.h +++ b/source/blender/makesdna/DNA_asset_types.h @@ -126,6 +126,7 @@ typedef enum eAssetImportMethod { typedef enum eAssetLibrary_Flag { ASSET_LIBRARY_RELATIVE_PATH = (1 << 0), + ASSET_LIBRARY_DEFAULT = (1 << 1), } eAssetLibrary_Flag; /** diff --git a/source/blender/makesrna/intern/rna_userdef.cc b/source/blender/makesrna/intern/rna_userdef.cc index 9c5a5baf473..ba0bd22957d 100644 --- a/source/blender/makesrna/intern/rna_userdef.cc +++ b/source/blender/makesrna/intern/rna_userdef.cc @@ -358,6 +358,18 @@ static void rna_userdef_asset_library_path_set(PointerRNA *ptr, const char *valu BKE_preferences_asset_library_path_set(library, value); } +static void rna_UserAssetLibrary_is_default_set(PointerRNA *ptr, bool value) +{ + bUserAssetLibrary *library = static_cast(ptr->data); + if (!value) { + return; + } + LISTBASE_FOREACH (bUserAssetLibrary *, library_iter, &U.asset_libraries) { + library_iter->flag &= ~ASSET_LIBRARY_DEFAULT; + } + library->flag |= ASSET_LIBRARY_DEFAULT; +} + static void rna_userdef_extension_repo_name_set(PointerRNA *ptr, const char *value) { bUserExtensionRepo *repo = (bUserExtensionRepo *)ptr->data; @@ -6617,6 +6629,11 @@ static void rna_def_userdef_filepaths_asset_library(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, nullptr, "flag", ASSET_LIBRARY_RELATIVE_PATH); RNA_def_property_ui_text( prop, "Relative Path", "Use relative path when linking assets from this asset library"); + + prop = RNA_def_property(srna, "is_default", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", ASSET_LIBRARY_DEFAULT); + RNA_def_property_boolean_funcs(prop, nullptr, "rna_UserAssetLibrary_is_default_set"); + RNA_def_property_ui_text(prop, "Default", "Use this library for saving new assets"); } static void rna_def_userdef_filepaths_extension_repo(BlenderRNA *brna)