Brush Assets: Show new catalog in asset shelf when duplicating brush #120531

Merged
Hans Goudey merged 5 commits from HooglyBoogly/blender:brush-assets-duplicate-show-catalog into brush-assets-project 2024-04-26 18:36:37 +02:00
3 changed files with 21 additions and 1 deletions

View File

@ -88,6 +88,8 @@ void type_unlink(const Main &bmain, const AssetShelfType &shelf_type);
int tile_width(const AssetShelfSettings &settings);
int tile_height(const AssetShelfSettings &settings);
AssetShelf *active_shelf_from_area(const ScrArea *area);
int context(const bContext *C, const char *member, bContextDataResult *result);
} // namespace blender::ed::asset::shelf

View File

@ -562,7 +562,7 @@ void region_blend_write(BlendWriter *writer, ARegion *region)
/** \name Asset Shelf Context
* \{ */
static AssetShelf *active_shelf_from_area(const ScrArea *area)
AssetShelf *active_shelf_from_area(const ScrArea *area)
{
const ARegion *shelf_region = BKE_area_find_region_type(area, RGN_TYPE_ASSET_SHELF);
if (!shelf_region) {

View File

@ -40,12 +40,14 @@
#include "BKE_paint.hh"
#include "BKE_preferences.h"
#include "BKE_report.hh"
#include "BKE_screen.hh"
#include "ED_asset_handle.hh"
#include "ED_asset_library.hh"
#include "ED_asset_list.hh"
#include "ED_asset_mark_clear.hh"
#include "ED_asset_menu_utils.hh"
#include "ED_asset_shelf.hh"
#include "ED_image.hh"
#include "ED_paint.hh"
#include "ED_screen.hh"
@ -884,6 +886,21 @@ static asset_system::AssetCatalog &asset_library_ensure_catalogs_in_path(
return *library.catalog_service().find_catalog_by_path(path);
}
static void show_catalog_in_asset_shelf(const bContext &C, const StringRefNull catalog_path)
{
ScrArea *area = CTX_wm_area(&C);
if (!area) {
return;
}
HooglyBoogly marked this conversation as resolved Outdated

Code here is duplicated from active_shelf_from_area(), better make this shared.

Code here is duplicated from `active_shelf_from_area()`, better make this shared.
const AssetShelf *shelf = asset::shelf::active_shelf_from_area(area);
if (!BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(
&U, shelf->idname, catalog_path.c_str()))
{
return;
}
U.runtime.is_dirty = true;
}

This does assume that the currently active shelf displays brushes, which may not be true. I'm not sure how we could improve this though since there's nothing to explicitly connect this to a certain asset shelf. If we had traits we could check that the asset shelf traits include "brush". I guess for now the asset shelf should hide empty catalog tabs.
Nothing for you to do, just noting as a weakness.

This does assume that the currently active shelf displays brushes, which may not be true. I'm not sure how we could improve this though since there's nothing to explicitly connect this to a certain asset shelf. If we had traits we could check that the asset shelf traits include "brush". I guess for now the asset shelf should hide empty catalog tabs. Nothing for you to do, just noting as a weakness.

Yeah, maybe that will get clearer if we ever actually have two conflicting asset shelf types here.

Yeah, maybe that will get clearer if we ever actually have two conflicting asset shelf types here.
static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
@ -937,6 +954,7 @@ static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
}
library->catalog_service().write_to_disk(*final_full_asset_filepath);
show_catalog_in_asset_shelf(*C, catalog_path);
AssetWeakReference new_brush_weak_ref = brush_asset_create_weakref_hack(
user_library, *final_full_asset_filepath);