Brush Assets: Support adding shortcut to asset shelf items #117861
|
@ -8744,6 +8744,7 @@ class VIEW3D_PT_viewport_debug(Panel):
|
|||
class BrushAssetShelf:
|
||||
bl_space_type = "VIEW_3D"
|
||||
bl_options = {'NO_ASSET_DRAG'}
|
||||
bl_activate_operator = "BRUSH_OT_asset_select"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
|
|
|
@ -523,6 +523,8 @@ struct AssetShelfType {
|
|||
|
||||
int space_type;
|
||||
|
||||
std::string activate_operator;
|
||||
|
||||
AssetShelfTypeFlag flag;
|
||||
|
||||
/** Determine if asset shelves of this type should be available in current context or not. */
|
||||
|
|
|
@ -231,7 +231,9 @@ static void spacetype_free(SpaceType *st)
|
|||
}
|
||||
|
||||
BLI_freelistN(&st->regiontypes);
|
||||
BLI_freelistN(&st->asset_shelf_types);
|
||||
LISTBASE_FOREACH_MUTABLE (AssetShelfType *, shelf_type, &st->asset_shelf_types) {
|
||||
delete shelf_type;
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_spacetypes_free()
|
||||
|
|
|
@ -200,21 +200,25 @@ void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
|||
const ui::GridViewStyle &style = this->get_view().get_style();
|
||||
|
||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
||||
const AssetView &asset_view = dynamic_cast<const AssetView &>(get_view());
|
||||
const AssetShelfType &shelf_type = *asset_view.shelf_.type;
|
||||
|
||||
uiBut *but = uiDefButO(block,
|
||||
UI_BTYPE_BUT,
|
||||
"BRUSH_OT_asset_select",
|
||||
WM_OP_EXEC_DEFAULT,
|
||||
hide_label_ ? "" : label.c_str(),
|
||||
0,
|
||||
0,
|
||||
style.tile_width,
|
||||
style.tile_height,
|
||||
"");
|
||||
uiBut *but = uiDefIconTextButO(block,
|
||||
UI_BTYPE_BUT,
|
||||
shelf_type.activate_operator.c_str(),
|
||||
WM_OP_EXEC_DEFAULT,
|
||||
this->preview_icon_id,
|
||||
hide_label_ ? "" : label.c_str(),
|
||||
0,
|
||||
0,
|
||||
style.tile_width,
|
||||
HooglyBoogly marked this conversation as resolved
Outdated
|
||||
style.tile_height,
|
||||
"");
|
||||
PointerRNA *ptr = UI_but_operator_ptr_ensure(but);
|
||||
operator_asset_reference_props_set(*handle_get_representation(&asset_), *ptr);
|
||||
|
||||
if (this->is_active()) {
|
||||
printf("IS ACTIVE!\n");
|
||||
UI_but_flag_enable(but, UI_SELECT_DRAW);
|
||||
}
|
||||
|
||||
|
|
|
@ -342,9 +342,9 @@ void GridViewLayoutBuilder::build_grid_tile(uiLayout &grid_layout,
|
|||
void GridViewLayoutBuilder::build_from_view(const AbstractGridView &grid_view,
|
||||
const View2D &v2d) const
|
||||
{
|
||||
uiLayout *parent_layout = current_layout();
|
||||
uiLayout *parent_layout = this->current_layout();
|
||||
|
||||
uiLayout &layout = *uiLayoutColumn(current_layout(), true);
|
||||
uiLayout &layout = *uiLayoutColumn(parent_layout, true);
|
||||
const GridViewStyle &style = grid_view.get_style();
|
||||
|
||||
const int cols_per_row = std::max(uiLayoutGetWidth(&layout) / style.tile_width, 1);
|
||||
|
@ -367,7 +367,7 @@ void GridViewLayoutBuilder::build_from_view(const AbstractGridView &grid_view,
|
|||
row = uiLayoutRow(&layout, true);
|
||||
}
|
||||
|
||||
build_grid_tile(*row, item);
|
||||
this->build_grid_tile(*row, item);
|
||||
item_idx++;
|
||||
});
|
||||
|
||||
|
@ -411,7 +411,7 @@ PreviewGridItem::PreviewGridItem(StringRef identifier, StringRef label, int prev
|
|||
|
||||
void PreviewGridItem::build_grid_tile(uiLayout &layout) const
|
||||
{
|
||||
const GridViewStyle &style = get_view().get_style();
|
||||
const GridViewStyle &style = this->get_view().get_style();
|
||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
||||
|
||||
uiBut *but = uiDefBut(block,
|
||||
|
|
|
@ -1020,7 +1020,6 @@ static int brush_asset_select_exec(bContext *C, wmOperator *op)
|
|||
|
||||
static void BRUSH_OT_asset_select(wmOperatorType *ot)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed;
|
||||
ot->name = "Select Brush Asset";
|
||||
ot->description = "Select a brush asset as current sculpt and paint tool";
|
||||
|
|
|
@ -1185,7 +1185,8 @@ static bool rna_AssetShelf_unregister(Main *bmain, StructRNA *type)
|
|||
RNA_struct_free_extension(type, &shelf_type->rna_ext);
|
||||
RNA_struct_free(&BLENDER_RNA, type);
|
||||
|
||||
BLI_freelinkN(&space_type->asset_shelf_types, shelf_type);
|
||||
BLI_remlink(&space_type->asset_shelf_types, shelf_type);
|
||||
delete shelf_type;
|
||||
|
||||
/* update while blender is running */
|
||||
WM_main_add_notifier(NC_WINDOW, nullptr);
|
||||
|
@ -1201,11 +1202,11 @@ static StructRNA *rna_AssetShelf_register(Main *bmain,
|
|||
StructCallbackFunc call,
|
||||
StructFreeFunc free)
|
||||
{
|
||||
AssetShelfType dummy_shelf_type = {};
|
||||
AssetShelf dummy_shelf = {};
|
||||
std::unique_ptr<AssetShelfType> shelf_type = std::make_unique<AssetShelfType>();
|
||||
|
||||
/* setup dummy shelf & shelf type to store static properties in */
|
||||
dummy_shelf.type = &dummy_shelf_type;
|
||||
AssetShelf dummy_shelf = {};
|
||||
dummy_shelf.type = shelf_type.get();
|
||||
PointerRNA dummy_shelf_ptr = RNA_pointer_create(nullptr, &RNA_AssetShelf, &dummy_shelf);
|
||||
|
||||
bool have_function[3];
|
||||
|
@ -1215,16 +1216,16 @@ static StructRNA *rna_AssetShelf_register(Main *bmain,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (strlen(identifier) >= sizeof(dummy_shelf_type.idname)) {
|
||||
if (strlen(identifier) >= sizeof(shelf_type->idname)) {
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
"Registering asset shelf class: '%s' is too long, maximum length is %d",
|
||||
identifier,
|
||||
(int)sizeof(dummy_shelf_type.idname));
|
||||
(int)sizeof(shelf_type->idname));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SpaceType *space_type = BKE_spacetype_from_id(dummy_shelf_type.space_type);
|
||||
SpaceType *space_type = BKE_spacetype_from_id(shelf_type->space_type);
|
||||
if (!space_type) {
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
|
@ -1232,47 +1233,63 @@ static StructRNA *rna_AssetShelf_register(Main *bmain,
|
|||
|
||||
/* Check if we have registered this asset shelf type before, and remove it. */
|
||||
LISTBASE_FOREACH (AssetShelfType *, iter_shelf_type, &space_type->asset_shelf_types) {
|
||||
if (STREQ(iter_shelf_type->idname, dummy_shelf_type.idname)) {
|
||||
if (STREQ(iter_shelf_type->idname, shelf_type->idname)) {
|
||||
if (iter_shelf_type->rna_ext.srna) {
|
||||
BKE_reportf(reports,
|
||||
RPT_INFO,
|
||||
"Registering asset shelf class: '%s' has been registered before, "
|
||||
"unregistering previous",
|
||||
dummy_shelf_type.idname);
|
||||
shelf_type->idname);
|
||||
|
||||
rna_AssetShelf_unregister(bmain, iter_shelf_type->rna_ext.srna);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!RNA_struct_available_or_report(reports, dummy_shelf_type.idname)) {
|
||||
if (!RNA_struct_available_or_report(reports, shelf_type->idname)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_shelf_type.idname, "_AST_")) {
|
||||
if (!RNA_struct_bl_idname_ok_or_report(reports, shelf_type->idname, "_AST_")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Create the new shelf type. */
|
||||
AssetShelfType *shelf_type = static_cast<AssetShelfType *>(
|
||||
MEM_mallocN(sizeof(*shelf_type), __func__));
|
||||
memcpy(shelf_type, &dummy_shelf_type, sizeof(*shelf_type));
|
||||
|
||||
shelf_type->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, shelf_type->idname, &RNA_AssetShelf);
|
||||
shelf_type->rna_ext.data = data;
|
||||
shelf_type->rna_ext.call = call;
|
||||
shelf_type->rna_ext.free = free;
|
||||
RNA_struct_blender_type_set(shelf_type->rna_ext.srna, shelf_type);
|
||||
RNA_struct_blender_type_set(shelf_type->rna_ext.srna, shelf_type.get());
|
||||
|
||||
shelf_type->poll = have_function[0] ? asset_shelf_poll : nullptr;
|
||||
shelf_type->asset_poll = have_function[1] ? asset_shelf_asset_poll : nullptr;
|
||||
shelf_type->draw_context_menu = have_function[2] ? asset_shelf_draw_context_menu : nullptr;
|
||||
|
||||
BLI_addtail(&space_type->asset_shelf_types, shelf_type);
|
||||
StructRNA *srna = shelf_type->rna_ext.srna;
|
||||
|
||||
BLI_addtail(&space_type->asset_shelf_types, shelf_type.release());
|
||||
|
||||
/* update while blender is running */
|
||||
WM_main_add_notifier(NC_WINDOW, nullptr);
|
||||
|
||||
return shelf_type->rna_ext.srna;
|
||||
return srna;
|
||||
}
|
||||
|
||||
static void rna_AssetShelf_activate_operator_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
|
||||
strcpy(value, shelf->type->activate_operator.c_str());
|
||||
}
|
||||
|
||||
static int rna_AssetShelf_activate_operator_length(PointerRNA *ptr)
|
||||
{
|
||||
AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
|
||||
return shelf->type->activate_operator.size();
|
||||
}
|
||||
|
||||
static void rna_AssetShelf_activate_operator_set(PointerRNA *ptr, const char *value)
|
||||
{
|
||||
AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
|
||||
shelf->type->activate_operator = value;
|
||||
}
|
||||
|
||||
static StructRNA *rna_AssetShelf_refine(PointerRNA *shelf_ptr)
|
||||
|
@ -2293,6 +2310,17 @@ static void rna_def_asset_shelf(BlenderRNA *brna)
|
|||
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
|
||||
RNA_def_property_ui_text(prop, "Options", "Options for this asset shelf type");
|
||||
|
||||
prop = RNA_def_property(srna, "bl_activate_operator", PROP_STRING, PROP_NONE);
|
||||
RNA_def_property_string_funcs(prop,
|
||||
"rna_AssetShelf_activate_operator_get",
|
||||
"rna_AssetShelf_activate_operator_length",
|
||||
"rna_AssetShelf_activate_operator_set");
|
||||
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Activate Operator",
|
||||
"Operator to call when activating an item with asset reference properties");
|
||||
|
||||
PropertyRNA *parm;
|
||||
FunctionRNA *func;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
This function does not check if
ot
is null (butWM_operator_properties_create
does check).