Brush Assets: Support adding shortcut to asset shelf items #117861
|
@ -197,44 +197,14 @@ void AssetViewItem::disable_asset_drag()
|
||||||
|
|
||||||
void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
||||||
{
|
{
|
||||||
const ui::GridViewStyle &style = this->get_view().get_style();
|
const AssetView &asset_view = reinterpret_cast<const AssetView &>(this->get_view());
|
||||||
|
|
||||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
|
||||||
const AssetView &asset_view = dynamic_cast<const AssetView &>(get_view());
|
|
||||||
const AssetShelfType &shelf_type = *asset_view.shelf_.type;
|
const AssetShelfType &shelf_type = *asset_view.shelf_.type;
|
||||||
|
wmOperatorType *ot = WM_operatortype_find(shelf_type.activate_operator.c_str(), false);
|
||||||
|
PointerRNA op_props;
|
||||||
|
WM_operator_properties_create_ptr(&op_props, ot);
|
||||||
|
asset::operator_asset_reference_props_set(*handle_get_representation(&asset_), op_props);
|
||||||
|
|
||||||
uiBut *but = uiDefIconTextButO(block,
|
ui::PreviewGridItem::build_grid_tile_button(layout, ot, op_props);
|
||||||
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,
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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_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
|
void AssetViewItem::build_context_menu(bContext &C, uiLayout &column) const
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "UI_resources.hh"
|
#include "UI_resources.hh"
|
||||||
|
|
||||||
struct bContext;
|
struct bContext;
|
||||||
|
struct PointerRNA;
|
||||||
struct uiBlock;
|
struct uiBlock;
|
||||||
struct uiButViewItem;
|
struct uiButViewItem;
|
||||||
struct uiLayout;
|
struct uiLayout;
|
||||||
|
@ -197,12 +198,15 @@ class PreviewGridItem : public AbstractGridViewItem {
|
||||||
bool hide_label_ = false;
|
bool hide_label_ = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string label{};
|
std::string label;
|
||||||
int preview_icon_id = ICON_NONE;
|
int preview_icon_id = ICON_NONE;
|
||||||
|
|
||||||
PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id);
|
PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id);
|
||||||
|
|
||||||
void build_grid_tile(uiLayout &layout) const override;
|
void build_grid_tile(uiLayout &layout) const override;
|
||||||
|
void build_grid_tile_button(uiLayout &layout,
|
||||||
|
const wmOperatorType *ot,
|
||||||
|
const PointerRNA &op_props) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
HooglyBoogly marked this conversation as resolved
|
|||||||
* Set a custom callback to execute when activating this view item. This way users don't have to
|
* Set a custom callback to execute when activating this view item. This way users don't have to
|
||||||
|
|
|
@ -2335,6 +2335,7 @@ static void ui_apply_but(
|
||||||
switch (but_type) {
|
switch (but_type) {
|
||||||
case UI_BTYPE_BUT:
|
case UI_BTYPE_BUT:
|
||||||
case UI_BTYPE_DECORATOR:
|
case UI_BTYPE_DECORATOR:
|
||||||
|
case UI_BTYPE_PREVIEW_TILE:
|
||||||
ui_apply_but_BUT(C, but, data);
|
ui_apply_but_BUT(C, but, data);
|
||||||
break;
|
break;
|
||||||
case UI_BTYPE_TEXT:
|
case UI_BTYPE_TEXT:
|
||||||
|
|
|
@ -372,35 +372,33 @@ static bool ui_tooltip_data_append_from_keymap(bContext *C, uiTooltipData *data,
|
||||||
|
|
||||||
LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
|
LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
|
||||||
wmOperatorType *ot = WM_operatortype_find(kmi->idname, true);
|
wmOperatorType *ot = WM_operatortype_find(kmi->idname, true);
|
||||||
if (ot != nullptr) {
|
if (!ot) {
|
||||||
/* Tip. */
|
continue;
|
||||||
{
|
}
|
||||||
UI_tooltip_text_field_add(data,
|
/* Tip. */
|
||||||
ot->description ? ot->description : ot->name,
|
UI_tooltip_text_field_add(data,
|
||||||
{},
|
ot->description ? ot->description : ot->name,
|
||||||
UI_TIP_STYLE_NORMAL,
|
{},
|
||||||
UI_TIP_LC_MAIN,
|
UI_TIP_STYLE_NORMAL,
|
||||||
true);
|
UI_TIP_LC_MAIN,
|
||||||
}
|
true);
|
||||||
/* Shortcut. */
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
if (WM_keymap_item_to_string(kmi, false, buf, sizeof(buf))) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
UI_tooltip_text_field_add(data,
|
|
||||||
fmt::format(TIP_("Shortcut: {}"), found ? buf : "None"),
|
|
||||||
{},
|
|
||||||
UI_TIP_STYLE_NORMAL,
|
|
||||||
UI_TIP_LC_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Python. */
|
/* Shortcut. */
|
||||||
if (U.flag & USER_TOOLTIPS_PYTHON) {
|
bool found = false;
|
||||||
std::string str = ui_tooltip_text_python_from_op(C, ot, kmi->ptr);
|
if (WM_keymap_item_to_string(kmi, false, buf, sizeof(buf))) {
|
||||||
UI_tooltip_text_field_add(
|
found = true;
|
||||||
data, fmt::format(TIP_("Python: {}"), str), {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_PYTHON);
|
}
|
||||||
}
|
UI_tooltip_text_field_add(data,
|
||||||
|
fmt::format(TIP_("Shortcut: {}"), found ? buf : "None"),
|
||||||
|
{},
|
||||||
|
UI_TIP_STYLE_NORMAL,
|
||||||
|
UI_TIP_LC_NORMAL);
|
||||||
|
|
||||||
|
/* Python. */
|
||||||
|
if (U.flag & USER_TOOLTIPS_PYTHON) {
|
||||||
|
std::string str = ui_tooltip_text_python_from_op(C, ot, kmi->ptr);
|
||||||
|
UI_tooltip_text_field_add(
|
||||||
|
data, fmt::format(TIP_("Python: {}"), str), {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_PYTHON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "WM_types.hh"
|
#include "WM_types.hh"
|
||||||
|
|
||||||
|
#include "RNA_access.hh"
|
||||||
|
|
||||||
#include "UI_interface.hh"
|
#include "UI_interface.hh"
|
||||||
#include "interface_intern.hh"
|
#include "interface_intern.hh"
|
||||||
|
|
||||||
|
@ -409,25 +411,42 @@ PreviewGridItem::PreviewGridItem(StringRef identifier, StringRef label, int prev
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewGridItem::build_grid_tile(uiLayout &layout) const
|
void PreviewGridItem::build_grid_tile_button(uiLayout &layout,
|
||||||
|
const wmOperatorType *ot,
|
||||||
|
const PointerRNA &op_props) const
|
||||||
{
|
{
|
||||||
const GridViewStyle &style = this->get_view().get_style();
|
const GridViewStyle &style = get_view().get_style();
|
||||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
uiBlock *block = uiLayoutGetBlock(&layout);
|
||||||
|
|
||||||
uiBut *but = uiDefBut(block,
|
uiBut *but;
|
||||||
|
if (ot) {
|
||||||
|
but = uiDefButO_ptr(block,
|
||||||
UI_BTYPE_PREVIEW_TILE,
|
UI_BTYPE_PREVIEW_TILE,
|
||||||
0,
|
const_cast<wmOperatorType *>(ot),
|
||||||
|
WM_OP_INVOKE_REGION_WIN,
|
||||||
hide_label_ ? "" : label.c_str(),
|
hide_label_ ? "" : label.c_str(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
style.tile_width,
|
style.tile_width,
|
||||||
style.tile_height,
|
style.tile_height,
|
||||||
nullptr,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
"");
|
"");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
but = uiDefBut(block,
|
||||||
|
UI_BTYPE_PREVIEW_TILE,
|
||||||
|
0,
|
||||||
|
hide_label_ ? "" : label.c_str(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
style.tile_width,
|
||||||
|
style.tile_height,
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"");
|
||||||
|
}
|
||||||
/* Draw icons that are not previews or images as normal icons with a fixed icon size. Otherwise
|
/* 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. */
|
* 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) ||
|
const int is_preview_flag = (BKE_icon_is_preview(preview_icon_id) ||
|
||||||
|
@ -442,6 +461,11 @@ void PreviewGridItem::build_grid_tile(uiLayout &layout) const
|
||||||
but->emboss = UI_EMBOSS_NONE;
|
but->emboss = UI_EMBOSS_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewGridItem::build_grid_tile(uiLayout &layout) const
|
||||||
|
{
|
||||||
|
this->build_grid_tile_button(layout, nullptr, {});
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewGridItem::set_on_activate_fn(ActivateFn fn)
|
void PreviewGridItem::set_on_activate_fn(ActivateFn fn)
|
||||||
{
|
{
|
||||||
activate_fn_ = fn;
|
activate_fn_ = fn;
|
||||||
|
|
Loading…
Reference in New Issue
Would add default arguments for convenience, but also to simply communicate that these are optional.