mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
UI: Display ID counts when dragging multiple objects
When multiple selected object/collections are dragged from outliner,
their tooltip shows "objects/collections" as plural. As proposed by Harley,
display selected id counts in tooltip ("3 objects" for example).
Changed return type to string for `WM_drag_get_item_name`. That way,
we don't have to worry about freeing char pointer memory manually.
Resolves #139737
See PR description for images
Pull Request: https://projects.blender.org/blender/blender/pulls/139770
This commit is contained in:
parent
7189d9fe6c
commit
ab9bf68756
5 changed files with 13 additions and 13 deletions
|
|
@ -132,7 +132,7 @@ static std::string ui_drop_material_tooltip(bContext *C,
|
|||
|
||||
PointerRNA rna_prev_material = RNA_pointer_get(&mat_slot, "material");
|
||||
Material *prev_mat_in_slot = static_cast<Material *>(rna_prev_material.data);
|
||||
const char *dragged_material_name = WM_drag_get_item_name(drag);
|
||||
const std::string dragged_material_name = WM_drag_get_item_name(drag);
|
||||
|
||||
if (prev_mat_in_slot) {
|
||||
return fmt::format(fmt::runtime(TIP_("Drop {} on slot {} (replacing {}) of {}")),
|
||||
|
|
|
|||
|
|
@ -7372,7 +7372,7 @@ static std::string screen_drop_scene_tooltip(bContext * /*C*/,
|
|||
[2],
|
||||
wmDropBox * /*drop*/)
|
||||
{
|
||||
const char *dragged_scene_name = WM_drag_get_item_name(drag);
|
||||
const std::string dragged_scene_name = WM_drag_get_item_name(drag);
|
||||
wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, ID_SCE);
|
||||
if (asset_drag) {
|
||||
switch (asset_drag->import_settings.method) {
|
||||
|
|
|
|||
|
|
@ -207,13 +207,13 @@ static std::string view3d_mat_drop_tooltip(bContext *C,
|
|||
const int xy[2],
|
||||
wmDropBox * /*drop*/)
|
||||
{
|
||||
const char *name = WM_drag_get_item_name(drag);
|
||||
const std::string name = WM_drag_get_item_name(drag);
|
||||
ARegion *region = CTX_wm_region(C);
|
||||
const int mval[2] = {
|
||||
xy[0] - region->winrct.xmin,
|
||||
xy[1] - region->winrct.ymin,
|
||||
};
|
||||
return ed::object::drop_named_material_tooltip(C, name, mval);
|
||||
return ed::object::drop_named_material_tooltip(C, name.c_str(), mval);
|
||||
}
|
||||
|
||||
static bool view3d_world_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
|
|
|
|||
|
|
@ -1749,7 +1749,7 @@ void WM_drag_add_asset_list_item(wmDrag *drag, const asset_system::AssetRepresen
|
|||
|
||||
const ListBaseT<wmDragAssetListItem> *WM_drag_asset_list_get(const wmDrag *drag);
|
||||
|
||||
const char *WM_drag_get_item_name(wmDrag *drag);
|
||||
const std::string WM_drag_get_item_name(wmDrag *drag);
|
||||
|
||||
/* Paths drag and drop. */
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1027,31 +1027,31 @@ static void wm_drop_redalert_draw(const StringRef redalert_str, int x, int y)
|
|||
ui::fontstyle_draw_simple_backdrop(fstyle, x, y, redalert_str, col_fg, col_bg);
|
||||
}
|
||||
|
||||
const char *WM_drag_get_item_name(wmDrag *drag)
|
||||
const std::string WM_drag_get_item_name(wmDrag *drag)
|
||||
{
|
||||
switch (drag->type) {
|
||||
case WM_DRAG_ID: {
|
||||
ID *id = WM_drag_get_local_ID(drag, 0);
|
||||
bool single = BLI_listbase_is_single(&drag->ids);
|
||||
const int dragged_ids = BLI_listbase_count(&drag->ids);
|
||||
|
||||
if (single) {
|
||||
if (dragged_ids == 1) {
|
||||
return id->name + 2;
|
||||
}
|
||||
if (id) {
|
||||
return BKE_idtype_idcode_to_name_plural(GS(id->name));
|
||||
return std::to_string(dragged_ids) + " " + BKE_idtype_idcode_to_name_plural(GS(id->name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_DRAG_ASSET: {
|
||||
const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
|
||||
return asset_drag->asset->get_name().c_str();
|
||||
return asset_drag->asset->get_name();
|
||||
}
|
||||
case WM_DRAG_PATH: {
|
||||
const wmDragPath *path_drag_data = static_cast<const wmDragPath *>(drag->poin);
|
||||
return path_drag_data->tooltip.c_str();
|
||||
return path_drag_data->tooltip;
|
||||
}
|
||||
case WM_DRAG_NAME:
|
||||
return static_cast<const char *>(drag->poin);
|
||||
return *static_cast<const std::string *>(drag->poin);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -1134,7 +1134,7 @@ static void wm_drag_draw_item_name(wmDrag *drag, const int x, const int y)
|
|||
{
|
||||
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
|
||||
const uchar text_col[] = {255, 255, 255, 255};
|
||||
ui::fontstyle_draw_simple(fstyle, x, y, WM_drag_get_item_name(drag), text_col);
|
||||
ui::fontstyle_draw_simple(fstyle, x, y, WM_drag_get_item_name(drag).c_str(), text_col);
|
||||
}
|
||||
|
||||
void WM_drag_draw_item_name_fn(bContext * /*C*/, wmWindow *win, wmDrag *drag, const int xy[2])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue