Brush Assets: Support adding shortcut to asset shelf items #117861
|
@ -6801,10 +6801,6 @@ def km_asset_shelf_brushes(_params):
|
|||
{"items": items},
|
||||
)
|
||||
|
||||
items.extend([
|
||||
("brush.asset_select", {"type": 'LEFTMOUSE', "value": 'CLICK'}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "AS_asset_library.hh"
|
||||
#include "AS_asset_representation.hh"
|
||||
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_screen.hh"
|
||||
|
||||
#include "BLI_fnmatch.h"
|
||||
|
@ -22,6 +23,7 @@
|
|||
|
||||
#include "ED_asset_handle.hh"
|
||||
#include "ED_asset_list.hh"
|
||||
#include "ED_asset_menu_utils.hh"
|
||||
#include "ED_asset_shelf.hh"
|
||||
|
||||
#include "UI_grid_view.hh"
|
||||
|
@ -33,6 +35,7 @@
|
|||
|
||||
#include "WM_api.hh"
|
||||
|
||||
#include "../interface/interface_intern.hh"
|
||||
#include "asset_shelf.hh"
|
||||
|
||||
namespace blender::ed::asset::shelf {
|
||||
|
@ -194,16 +197,55 @@ void AssetViewItem::disable_asset_drag()
|
|||
|
||||
void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
||||
{
|
||||
PointerRNA file_ptr = RNA_pointer_create(
|
||||
nullptr,
|
||||
&RNA_FileSelectEntry,
|
||||
/* XXX passing file pointer here, should be asset handle or asset representation. */
|
||||
const_cast<FileDirEntry *>(asset_.file_data));
|
||||
// const ui::GridViewStyle &style = this->get_view().get_style();
|
||||
uiLayoutSetEmboss(&layout, UI_EMBOSS_NONE);
|
||||
uiLayoutSetFixedSize(&layout, true);
|
||||
PointerRNA op_ptr;
|
||||
uiItemFullO(&layout,
|
||||
"BRUSH_OT_asset_select",
|
||||
hide_label_ ? "" : label.c_str(),
|
||||
this->preview_icon_id,
|
||||
nullptr,
|
||||
WM_OP_EXEC_DEFAULT,
|
||||
this->is_active() ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
|
||||
&op_ptr);
|
||||
operator_asset_reference_props_set(*handle_get_representation(&asset_), op_ptr);
|
||||
|
||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
||||
UI_but_context_ptr_set(
|
||||
block, reinterpret_cast<uiBut *>(view_item_but_), "active_file", &file_ptr);
|
||||
ui::PreviewGridItem::build_grid_tile(layout);
|
||||
// uiBlock *block = uiLayoutGetBlock(&layout);
|
||||
HooglyBoogly marked this conversation as resolved
Outdated
|
||||
|
||||
// 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,
|
||||
// "");
|
||||
// PointerRNA *ptr = UI_but_operator_ptr_ensure(but);
|
||||
// operator_asset_reference_props_set(*handle_get_representation(&asset_), *ptr);
|
||||
|
||||
// if (this->is_active()) {
|
||||
// UI_but_flag_enable(but, UI_SELECT_DRAW);
|
||||
// }
|
||||
|
||||
/* Draw icons that are not previews or images as normal icons with a fixed icon size.
|
||||
* Otherwise they will be upscaled to the button size. Should probably be done by the widget
|
||||
* code. */
|
||||
// const int is_preview_flag = (BKE_icon_is_preview(preview_icon_id) ||
|
||||
// BKE_icon_is_image(preview_icon_id)) ?
|
||||
// int(UI_BUT_ICON_PREVIEW) :
|
||||
// 0;
|
||||
// ui_def_but_icon(but,
|
||||
// preview_icon_id,
|
||||
// /* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
|
||||
// UI_HAS_ICON | is_preview_flag);
|
||||
// UI_but_func_set(but, [](bContext &C) {
|
||||
|
||||
// });
|
||||
// UI_but_func_tooltip_label_set(but, [this](const uiBut * /*but*/) { return label; });
|
||||
// but->emboss = UI_EMBOSS_NONE;
|
||||
}
|
||||
|
||||
void AssetViewItem::build_context_menu(bContext &C, uiLayout &column) const
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "ED_asset_handle.hh"
|
||||
#include "ED_asset_list.hh"
|
||||
#include "ED_asset_mark_clear.hh"
|
||||
#include "ED_asset_menu_utils.hh"
|
||||
#include "ED_image.hh"
|
||||
#include "ED_paint.hh"
|
||||
#include "ED_screen.hh"
|
||||
|
@ -987,21 +988,18 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
|
|||
|
||||
/**************************** Brush Assets **********************************/
|
||||
|
||||
static bool brush_asset_select_poll(bContext *C)
|
||||
{
|
||||
if (BKE_paint_get_active_from_context(C) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CTX_wm_asset(C) != nullptr;
|
||||
}
|
||||
|
||||
static int brush_asset_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed;
|
||||
/* This operator currently covers both cases: the file/asset browser file list and the asset list
|
||||
* used for the asset-view template. Once the asset list design is used by the Asset Browser,
|
||||
* this can be simplified to just that case. */
|
||||
blender::asset_system::AssetRepresentation *asset = CTX_wm_asset(C);
|
||||
const asset_system::AssetRepresentation *asset =
|
||||
asset::operator_asset_reference_props_get_asset_from_all_library(*C, *op->ptr, op->reports);
|
||||
if (!asset) {
|
||||
return OPERATOR_CANCELLED;
|
||||
Julian Eisel
commented
Best do some report so this doesn't just fail silently. Best do some report so this doesn't just fail silently.
Hans Goudey
commented
`operator_asset_reference_props_get_asset_from_all_library` handles the reports already
|
||||
}
|
||||
|
||||
AssetWeakReference *brush_asset_reference = asset->make_weak_reference();
|
||||
Brush *brush = BKE_brush_asset_runtime_ensure(CTX_data_main(C), brush_asset_reference);
|
||||
|
@ -1022,12 +1020,15 @@ 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";
|
||||
ot->idname = "BRUSH_OT_asset_select";
|
||||
|
||||
ot->exec = brush_asset_select_exec;
|
||||
ot->poll = brush_asset_select_poll;
|
||||
|
||||
asset::operator_asset_reference_props_register(*ot->srna);
|
||||
}
|
||||
|
||||
/* FIXME Quick dirty hack to generate a weak ref from 'raw' paths.
|
||||
|
|
|
@ -204,11 +204,9 @@ wmKeyMap *WM_keymap_guess_from_context(const bContext *C)
|
|||
wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
|
||||
{
|
||||
/* Op types purposely skipped for now:
|
||||
* BRUSH_OT
|
||||
* BOID_OT
|
||||
* BUTTONS_OT
|
||||
* CONSTRAINT_OT
|
||||
* PAINT_OT
|
||||
* ED_OT
|
||||
* FLUID_OT
|
||||
* TEXTURE_OT
|
||||
|
@ -331,7 +329,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
|
|||
km = WM_keymap_find_all(
|
||||
wm, "Paint Face Mask (Weight, Vertex, Texture)", SPACE_EMPTY, RGN_TYPE_WINDOW);
|
||||
}
|
||||
else if (STRPREFIX(opname, "PAINT_OT")) {
|
||||
else if (STRPREFIX(opname, "PAINT_OT") || STRPREFIX(opname, "BRUSH_OT")) {
|
||||
/* check for relevant mode */
|
||||
switch (CTX_data_mode_enum(C)) {
|
||||
case CTX_MODE_PAINT_WEIGHT:
|
||||
|
@ -346,6 +344,9 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
|
|||
case CTX_MODE_SCULPT:
|
||||
km = WM_keymap_find_all(wm, "Sculpt", SPACE_EMPTY, RGN_TYPE_WINDOW);
|
||||
break;
|
||||
case CTX_MODE_SCULPT_CURVES:
|
||||
km = WM_keymap_find_all(wm, "Sculpt Curves", SPACE_EMPTY, RGN_TYPE_WINDOW);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
This function does not check if
ot
is null (butWM_operator_properties_create
does check).