Blender V5.3
interface_context_menu.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "DNA_screen_types.h"
16
18
19#include "BLI_fileops.hh"
20#include "BLI_path_utils.hh"
21#include "BLI_string_utf8.hh"
22#include "BLI_utildefines.hh"
23
24#include "BLT_translation.hh"
25
26#include "BKE_context.hh"
27#include "BKE_idprop.hh"
28#include "BKE_main.hh"
29#include "BKE_screen.hh"
30
31#include "ED_asset.hh"
33#include "ED_buttons.hh"
34#include "ED_keyframing.hh"
35#include "ED_screen.hh"
36
37#include "UI_abstract_view.hh"
39
40#include "interface_intern.hh"
41
42#include "RNA_access.hh"
43#include "RNA_path.hh"
44#include "RNA_prototypes.hh"
45
46#ifdef WITH_PYTHON
47# include "BPY_extern.hh"
48# include "BPY_extern_run.hh"
49#endif
50
51#include "WM_api.hh"
52#include "WM_types.hh"
53
54/* This hack is needed because we don't have a good way to
55 * re-reference keymap items once added: #42944 */
56#define USE_KEYMAP_ADD_HACK
57
58namespace blender::ui {
59
60/* -------------------------------------------------------------------- */
63
65{
66 /* Compute data path from context to property. */
67
68 /* If this returns null, we won't be able to bind shortcuts to these RNA properties.
69 * Support can be added at #wm_context_member_from_ptr. */
70 std::optional<std::string> final_data_path = WM_context_path_resolve_property_full(
71 C, &but->rnapoin, but->rnaprop, but->rnaindex);
72 if (!final_data_path.has_value()) {
73 return nullptr;
74 }
75
76 /* Create ID property of data path, to pass to the operator. */
77 IDProperty *prop = bke::idprop::create_group(__func__).release();
78 IDP_AddToGroup(prop, bke::idprop::create("data_path", final_data_path.value()).release());
79 return prop;
80}
81
83 Button *but_parent,
84 Button *but)
85{
86 /* This is basically same as #shortcut_property_from_rna but with "value" in IDProperty in group.
87 * It's required for creating keyitem for enum values. */
88
89 /* If this returns null, we won't be able to bind shortcuts to these RNA properties.
90 * Support can be added at #wm_context_member_from_ptr. */
91 std::optional<std::string> final_data_path = WM_context_path_resolve_property_full(
92 C, &but_parent->rnapoin, but_parent->rnaprop, but_parent->rnaindex);
93 if (!final_data_path.has_value()) {
94 return nullptr;
95 }
96
97 const char *identifier = nullptr;
99 C, &but_parent->rnapoin, but_parent->rnaprop, but->retval, &identifier);
100
101 if (identifier == nullptr) {
102 /* Return early when valid identifier is not found for the button representing enum value. */
103 return nullptr;
104 }
105 /* Create ID property of data path and value, to pass to the operator. */
106 IDProperty *prop = bke::idprop::create_group(__func__).release();
107 IDP_AddToGroup(prop, bke::idprop::create("data_path", final_data_path.value()).release());
108 IDP_AddToGroup(prop, bke::idprop::create("value", identifier).release());
109 return prop;
110}
111
112static const char *shortcut_get_operator_property(bContext *C, Button *but, IDProperty **r_prop)
113{
114 if (but->optype) {
115 /* Operator */
116 *r_prop = (but->opptr && *but->opptr) ?
117 IDP_CopyProperty(static_cast<IDProperty *>(but->opptr->data)) :
118 nullptr;
119 return but->optype->idname;
120 }
121
122 if (but->rnaprop) {
123 const PropertyType rnaprop_type = RNA_property_type(but->rnaprop);
124
125 if (rnaprop_type == PROP_BOOLEAN) {
126 /* Boolean */
127 *r_prop = shortcut_property_from_rna(C, but);
128 if (*r_prop == nullptr) {
129 return nullptr;
130 }
131 return "WM_OT_context_toggle";
132 }
133 if (rnaprop_type == PROP_ENUM) {
134 /* `is_enum_menu` is true for expanded enum properties. It's to add shortcut to individual
135 * enum item, see: !163600 */
136 const bool is_enum_menu = but->type == ButtonType::Menu;
137 *r_prop = is_enum_menu ? shortcut_property_from_rna(C, but) :
139 if (*r_prop == nullptr) {
140 return nullptr;
141 }
142 return is_enum_menu ? "WM_OT_context_menu_enum" : "WM_OT_context_set_enum";
143 }
144 }
145
146 if (but->type == ButtonType::ButMenu) {
147 if ((but->block->handle != nullptr)) {
148 Button *but_parent = but->block->handle->popup_create_vars.but;
149 if (but_parent && but_parent->rnaprop &&
150 (RNA_property_type(but_parent->rnaprop) == PROP_ENUM))
151 {
152 *r_prop = shortcut_property_from_rna_for_enum(C, but_parent, but);
153 if (*r_prop == nullptr) {
154 return nullptr;
155 }
156 return "WM_OT_context_set_enum";
157 }
158 }
159 }
160
161 if (MenuType *mt = button_menutype_get(but)) {
162 IDProperty *prop = bke::idprop::create_group(__func__).release();
163 IDP_AddToGroup(prop, bke::idprop::create("name", mt->idname).release());
164 *r_prop = prop;
165 return "WM_OT_call_menu";
166 }
167
168 if (std::optional asset_shelf_idname = button_asset_shelf_type_idname_get(but)) {
169 IDProperty *prop = bke::idprop::create_group(__func__).release();
170 IDP_AddToGroup(prop, bke::idprop::create("name", *asset_shelf_idname).release());
171 *r_prop = prop;
172 return "WM_OT_call_asset_shelf_popover";
173 }
174
175 if (PanelType *pt = button_paneltype_get(but)) {
176 IDProperty *prop = bke::idprop::create_group(__func__).release();
177 IDP_AddToGroup(prop, bke::idprop::create("name", pt->idname).release());
178 *r_prop = prop;
179 return "WM_OT_call_panel";
180 }
181
182 *r_prop = nullptr;
183 return nullptr;
184}
185
187{
188 if (prop) {
189 IDP_FreeProperty(prop);
190 }
191}
192
199 const Button *but,
200 const char *idname,
201 IDProperty *prop,
202 const short include_mask,
203 const short exclude_mask,
204 wmKeyMap **r_km)
205{
207 C, idname, but->opcontext, prop, include_mask, exclude_mask, r_km))
208 {
209 return kmi;
210 }
211
212 wmKeyMap *km = WM_keymap_guess_opname(C, idname);
213 if (km == nullptr) {
214 return nullptr;
215 }
217 km, idname, prop, include_mask, exclude_mask);
218 if (kmi) {
219 *r_km = km;
220 }
221 return kmi;
222}
223
224static void but_shortcut_name_func(bContext *C, void *arg1, int /*event*/)
225{
226 Button *but = static_cast<Button *>(arg1);
227
228 IDProperty *prop;
229 const char *idname = shortcut_get_operator_property(C, but, &prop);
230 if (idname == nullptr) {
231 return;
232 }
233
234 /* complex code to change name of button */
235 if (std::optional<std::string> shortcut_str = WM_key_event_operator_string(
236 C, idname, but->opcontext, prop, true))
237 {
238 button_add_shortcut(but, shortcut_str->c_str(), true);
239 }
240 else {
241 /* simply strip the shortcut */
242 button_add_shortcut(but, nullptr, true);
243 }
244
246}
247
248static Block *menu_change_shortcut(bContext *C, ARegion *region, void *arg)
249{
251 Button *but = static_cast<Button *>(arg);
252 const uiStyle *style = style_get_dpi();
253 IDProperty *prop;
254 const char *idname = shortcut_get_operator_property(C, but, &prop);
255
256 wmKeyMap *km;
257 wmKeyMapItem *kmi = shortcut_find(C, but, idname, prop, EVT_TYPE_MASK_ALL, 0, &km);
258 U.runtime.is_dirty = true;
259
260 BLI_assert(kmi != nullptr);
261
262 PointerRNA ptr = RNA_pointer_create_discrete(&wm->id, RNA_KeyMapItem, kmi);
263
264 Block *block = block_begin(C, region, "_popup", EmbossType::Emboss);
268
269 Layout &layout = block_layout(block,
272 0,
273 0,
274 U.widget_unit * 10,
275 U.widget_unit * 2,
276 0,
277 style);
278
279 layout.label(CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Change Shortcut..."), ICON_HAND);
280 layout.prop(&ptr, "type", ITEM_R_FULL_EVENT | ITEM_R_IMMEDIATE, "", ICON_NONE);
281
282 const int bounds_offset[2] = {int(-100 * UI_SCALE_FAC), int(36 * UI_SCALE_FAC)};
283 block_bounds_set_popup(block, 6 * UI_SCALE_FAC, bounds_offset);
284
286
287 return block;
288}
289
290#ifdef USE_KEYMAP_ADD_HACK
291static int g_kmi_id_hack;
292#endif
293
294static Block *menu_add_shortcut(bContext *C, ARegion *region, void *arg)
295{
297 Button *but = static_cast<Button *>(arg);
298 const uiStyle *style = style_get_dpi();
299 IDProperty *prop;
300 const char *idname = shortcut_get_operator_property(C, but, &prop);
301
302 /* XXX this guess_opname can potentially return a different keymap
303 * than being found on adding later... */
304 wmKeyMap *km = WM_keymap_guess_opname(C, idname);
305 KeyMapItem_Params params{};
306 params.type = EVT_AKEY;
307 params.value = KM_PRESS;
308 params.modifier = 0;
309 params.direction = KM_ANY;
310 wmKeyMapItem *kmi = WM_keymap_add_item(km, idname, &params);
311 const int kmi_id = kmi->id;
312
313 /* This takes ownership of prop, or prop can be nullptr for reset. */
315
316 /* update and get pointers again */
318 U.runtime.is_dirty = true;
319
320 km = WM_keymap_guess_opname(C, idname);
321 kmi = WM_keymap_item_find_id(km, kmi_id);
322
323 PointerRNA ptr = RNA_pointer_create_discrete(&wm->id, RNA_KeyMapItem, kmi);
324
325 Block *block = block_begin(C, region, "_popup", EmbossType::Emboss);
328
329 Layout &layout = block_layout(block,
332 0,
333 0,
334 U.widget_unit * 10,
335 U.widget_unit * 2,
336 0,
337 style);
338
339 layout.label(CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Assign Shortcut..."), ICON_HAND);
340 layout.prop(&ptr, "type", ITEM_R_FULL_EVENT | ITEM_R_IMMEDIATE, "", ICON_NONE);
341
342 const int bounds_offset[2] = {int(-100 * UI_SCALE_FAC), int(36 * UI_SCALE_FAC)};
343 block_bounds_set_popup(block, 6 * UI_SCALE_FAC, bounds_offset);
344
345#ifdef USE_KEYMAP_ADD_HACK
346 g_kmi_id_hack = kmi_id;
347#endif
348
349 return block;
350}
351
352static void menu_add_shortcut_cancel(bContext *C, void *arg1)
353{
354 Button *but = static_cast<Button *>(arg1);
355
356 IDProperty *prop;
357 const char *idname = shortcut_get_operator_property(C, but, &prop);
358
359#ifdef USE_KEYMAP_ADD_HACK
360 wmKeyMap *km = WM_keymap_guess_opname(C, idname);
361 const int kmi_id = g_kmi_id_hack;
362 UNUSED_VARS(but);
363#else
364 int kmi_id = WM_key_event_operator_id(C, idname, but->opcontext, prop, true, &km);
365#endif
366
368
369 wmKeyMapItem *kmi = WM_keymap_item_find_id(km, kmi_id);
370 WM_keymap_remove_item(km, kmi);
371}
372
374{
375 IDProperty *prop;
376 const char *idname = shortcut_get_operator_property(C, but, &prop);
377
378 wmKeyMap *km;
379 wmKeyMapItem *kmi = shortcut_find(C, but, idname, prop, EVT_TYPE_MASK_ALL, 0, &km);
380 BLI_assert(kmi != nullptr);
381
382 WM_keymap_remove_item(km, kmi);
383 U.runtime.is_dirty = true;
384
386 but_shortcut_name_func(C, but, 0);
387}
388
390{
391 bool result = false;
392 if (but->optype) {
393 result = true;
394 }
395 else if (but->rnaprop) {
397 std::optional<std::string> data_path = WM_context_path_resolve_full(C, &but->rnapoin);
398 if (data_path.has_value()) {
399 result = true;
400 }
401 }
402 }
403 else if (button_menutype_get(but)) {
404 result = true;
405 }
406 else if (button_operatortype_get_from_enum_menu(but, nullptr)) {
407 result = true;
408 }
409
410 return result;
411}
412
414{
415 if (but->optype) {
416 IDProperty *prop = (but->opptr) ? static_cast<IDProperty *>(but->opptr->data) : nullptr;
417 return reinterpret_cast<bUserMenuItem *>(
419 }
420 if (but->rnaprop) {
421 std::optional<std::string> member_id_data_path = WM_context_path_resolve_full(C,
422 &but->rnapoin);
423 /* NOTE(@ideasman42): It's highly unlikely this ever occurs since the path must be resolved
424 * for this to be added in the first place, there might be some cases where manually
425 * constructed RNA paths don't resolve and in this case a crash should be avoided. */
426 if (!member_id_data_path.has_value()) [[unlikely]] {
427 /* Assert because this should never happen for typical usage. */
429 return nullptr;
430 }
431 /* Ignore the actual array index [pass -1] since the index is handled separately. */
432 const std::string prop_id = RNA_property_is_idprop(but->rnaprop) ?
433 RNA_path_property_py(&but->rnapoin, but->rnaprop, -1) :
436 &um->items, member_id_data_path->c_str(), prop_id.c_str(), but->rnaindex));
437 return umi;
438 }
439
440 wmOperatorType *ot = nullptr;
441 PropertyRNA *prop_enum = nullptr;
442 if ((ot = button_operatortype_get_from_enum_menu(but, &prop_enum))) {
443 return reinterpret_cast<bUserMenuItem *>(ED_screen_user_menu_item_find_operator(
444 &um->items, ot, nullptr, RNA_property_identifier(prop_enum), but->opcontext));
445 }
446
447 MenuType *mt = button_menutype_get(but);
448 if (mt != nullptr) {
449 return reinterpret_cast<bUserMenuItem *>(ED_screen_user_menu_item_find_menu(&um->items, mt));
450 }
451 return nullptr;
452}
453
455{
457
458 std::string drawstr = button_drawstr_without_sep_char(but);
459
460 /* Used for USER_MENU_TYPE_MENU. */
461 MenuType *mt = nullptr;
462 /* Used for USER_MENU_TYPE_OPERATOR (property enum used). */
463 wmOperatorType *ot = nullptr;
464 PropertyRNA *prop = nullptr;
465 if (but->optype) {
466 if (drawstr[0] == '\0') {
467 /* Hard code overrides for generic operators. */
468 if (but_is_tool(but)) {
469 char idname[64];
470 RNA_string_get(but->opptr, "name", idname);
471#ifdef WITH_PYTHON
472 {
473 const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
474 char expr[256];
475 SNPRINTF_UTF8(expr,
476 "bl_ui.space_toolsystem_common.item_from_id("
477 "bpy.context, "
478 "bpy.context.space_data.type, "
479 "'%s').label",
480 idname);
481 char *expr_result = nullptr;
482 if (BPY_run_string_as_string(C, expr_imports, expr, nullptr, &expr_result)) {
483 drawstr = expr_result;
484 MEM_delete(expr_result);
485 }
486 else {
487 BLI_assert(0);
488 drawstr = idname;
489 }
490 }
491#else
492 drawstr = idname;
493#endif
494 }
495 else if (but->tip_quick_func) {
496 /* The "quick tooltip" often contains a short string that can be used as a fallback. */
497 drawstr = but->tip_quick_func(but);
498 }
499 }
501 &um->items,
502 drawstr.c_str(),
503 but->optype,
504 but->opptr ? static_cast<const IDProperty *>(but->opptr->data) : nullptr,
505 "",
506 but->opcontext);
507 }
508 else if (but->rnaprop) {
509 /* NOTE: 'member_id' may be a path. */
510 std::optional<std::string> member_id_data_path = WM_context_path_resolve_full(C,
511 &but->rnapoin);
512 if (!member_id_data_path.has_value()) {
513 /* See #but_user_menu_find code-comment. */
515 }
516 else {
517 /* Ignore the actual array index [pass -1] since the index is handled separately. */
518 const std::string prop_id = RNA_property_is_idprop(but->rnaprop) ?
519 RNA_path_property_py(&but->rnapoin, but->rnaprop, -1) :
521 /* NOTE: ignore 'drawstr', use property idname always. */
523 &um->items, "", member_id_data_path->c_str(), prop_id.c_str(), but->rnaindex);
524 }
525 }
526 else if ((mt = button_menutype_get(but))) {
527 ED_screen_user_menu_item_add_menu(&um->items, drawstr.c_str(), mt);
528 }
529 else if ((ot = button_operatortype_get_from_enum_menu(but, &prop))) {
531 WM_operatortype_name(ot, nullptr).c_str(),
532 ot,
533 nullptr,
535 but->opcontext);
536 }
537}
538
540{
541 const PropertySubType subtype = RNA_property_subtype(prop);
542 wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true);
543 char filepath[FILE_MAX];
544 char dir[FILE_MAXDIR];
545 char file[FILE_MAXFILE];
546 PointerRNA props_ptr;
547
549 UNUSED_VARS_NDEBUG(subtype);
550
551 RNA_property_string_get(ptr, prop, filepath);
552
553 if (BLI_path_is_rel(filepath)) {
554 if (ptr->owner_id == nullptr) {
555 return false;
556 }
557 const char *base_path = ID_BLEND_PATH_FROM_GLOBAL(ptr->owner_id);
558 if (base_path[0] == '\0') {
559 return false;
560 }
561 BLI_path_abs(filepath, base_path);
562 }
563
564 if (!BLI_exists(filepath)) {
565 return false;
566 }
567
568 if (BLI_is_file(filepath)) {
569 BLI_assert(subtype == PROP_FILEPATH);
570 props_ptr = layout.op(ot,
571 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open File Externally"),
572 ICON_NONE,
575 RNA_string_set(&props_ptr, "filepath", filepath);
576 }
577 else {
578 /* This is a directory, so ensure it ends in a slash. */
579 BLI_path_slash_ensure(filepath, ARRAY_SIZE(filepath));
580 }
581
582 BLI_path_split_dir_file(filepath, dir, sizeof(dir), file, sizeof(file));
583
584 props_ptr = layout.op(ot,
585 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open Location Externally"),
586 ICON_NONE,
589 RNA_string_set(&props_ptr, "filepath", dir);
590
591 return true;
592}
593
595{
596 if (!but->context) {
597 return;
598 }
599 layout.context_copy(but->context);
600 CTX_store_set(C, layout.context_store());
601}
602
604{
605 /* but_is_interactive() may let some buttons through that should not get a context menu - it
606 * doesn't make sense for them. */
608 return false;
609 }
610
611 const bContextStore *previous_ctx = CTX_store_get(C);
613 C, button_context_menu_title_from_button(*but).c_str(), ICON_NONE);
614 Layout &layout = *popup_menu_layout(pup);
615
616 set_layout_context_from_button(C, layout, but);
618
619 const bool is_disabled = but->flag & BUT_DISABLED;
620
621 if (is_disabled) {
622 /* Suppress editing commands. */
623 }
624 else if (but->type == ButtonType::Tab) {
625 ButtonTab *tab = static_cast<ButtonTab *>(but);
626 if (tab->menu) {
627 menutype_draw(C, tab->menu, &layout);
628 layout.separator();
629 }
630 }
631 else if (but->rnapoin && but->rnaprop) {
632 PointerRNA *ptr = &but->rnapoin;
633 PropertyRNA *prop = but->rnaprop;
634 const PropertyType type = RNA_property_type(prop);
635 const PropertySubType subtype = RNA_property_subtype(prop);
636 bool is_anim = RNA_property_anim_editable(ptr, prop);
637 const bool is_idprop = RNA_property_is_idprop(prop);
638
639 /* second slower test,
640 * saved people finding keyframe items in menus when its not possible */
641 if (is_anim) {
642 is_anim = RNA_property_path_from_ID_check(&but->rnapoin, but->rnaprop);
643 }
644
645 /* determine if we can key a single component of an array */
646 const bool is_array = RNA_property_array_length(&but->rnapoin, but->rnaprop) != 0;
647 const bool is_array_component = (is_array && but->rnaindex != -1);
648 const bool is_whole_array = (is_array && but->rnaindex == -1);
649
651 CTX_data_main(C), ptr, prop, -1);
652 const bool is_overridable = flag_is_set(override_status, eRNAOverrideStatus::LibOverridable);
653
654 /* Set the (button_pointer, button_prop)
655 * and pointer data for Python access to the hovered UI element. */
656 layout.context_set_from_but(but);
657
658 /* Keyframes */
659 if (but->flag & BUT_ANIMATED_KEY) {
660 /* Replace/delete keyframes. */
661 if (is_array_component) {
662 PointerRNA op_ptr = layout.op(
663 "ANIM_OT_keyframe_insert_button",
664 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframes"),
665 ICON_KEY_HLT);
666 RNA_boolean_set(&op_ptr, "all", true);
667 op_ptr = layout.op("ANIM_OT_keyframe_insert_button",
668 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Single Keyframe"),
669 ICON_NONE);
670 RNA_boolean_set(&op_ptr, "all", false);
671 op_ptr = layout.op("ANIM_OT_keyframe_delete_button",
672 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Keyframes"),
673 ICON_NONE);
674 RNA_boolean_set(&op_ptr, "all", true);
675 op_ptr = layout.op("ANIM_OT_keyframe_delete_button",
676 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Single Keyframe"),
677 ICON_NONE);
678 RNA_boolean_set(&op_ptr, "all", false);
679 }
680 else {
681 PointerRNA op_ptr = layout.op(
682 "ANIM_OT_keyframe_insert_button",
683 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframe"),
684 ICON_KEY_HLT);
685 RNA_boolean_set(&op_ptr, "all", true);
686 op_ptr = layout.op("ANIM_OT_keyframe_delete_button",
688 ICON_NONE);
689 RNA_boolean_set(&op_ptr, "all", true);
690 }
691
692 /* keyframe settings */
693 layout.separator();
694 }
695 else if (but->flag & BUT_DRIVEN) {
696 /* pass */
697 }
698 else if (is_anim) {
699 if (is_array_component) {
700 PointerRNA op_ptr = layout.op(
701 "ANIM_OT_keyframe_insert_button",
702 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframes"),
703 ICON_KEY_HLT);
704 RNA_boolean_set(&op_ptr, "all", true);
705 op_ptr = layout.op("ANIM_OT_keyframe_insert_button",
706 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Single Keyframe"),
707 ICON_NONE);
708 RNA_boolean_set(&op_ptr, "all", false);
709 }
710 else {
711 PointerRNA op_ptr = layout.op(
712 "ANIM_OT_keyframe_insert_button",
714 ICON_KEY_HLT);
715 RNA_boolean_set(&op_ptr, "all", true);
716 }
717 }
718
719 if ((but->flag & BUT_ANIMATED) && (but->rnapoin.type != RNA_NlaStrip)) {
720 if (is_array_component) {
721 PointerRNA op_ptr = layout.op(
722 "ANIM_OT_keyframe_clear_button",
724 ICON_KEY_DEHLT);
725 RNA_boolean_set(&op_ptr, "all", true);
726 op_ptr = layout.op("ANIM_OT_keyframe_clear_button",
727 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Single Keyframes"),
728 ICON_NONE);
729 RNA_boolean_set(&op_ptr, "all", false);
730 }
731 else {
732 PointerRNA op_ptr = layout.op(
733 "ANIM_OT_keyframe_clear_button",
735 ICON_KEY_DEHLT);
736 RNA_boolean_set(&op_ptr, "all", true);
737 }
738 }
739
740 if (but->flag & BUT_ANIMATED) {
741 layout.separator();
742 if (is_array_component) {
743 PointerRNA op_ptr;
744 wmOperatorType *ot;
745 ot = WM_operatortype_find("ANIM_OT_view_curve_in_graph_editor", false);
746 op_ptr = layout.op(
747 ot,
748 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "View All in Graph Editor"),
749 ICON_GRAPH,
752 RNA_boolean_set(&op_ptr, "all", true);
753
754 op_ptr = layout.op(
755 ot,
756 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "View Single in Graph Editor"),
757 ICON_NONE,
760 RNA_boolean_set(&op_ptr, "all", false);
761 }
762 else {
763 PointerRNA op_ptr;
764 wmOperatorType *ot;
765 ot = WM_operatortype_find("ANIM_OT_view_curve_in_graph_editor", false);
766
767 op_ptr = layout.op(ot,
768 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "View in Graph Editor"),
769 ICON_NONE,
772 RNA_boolean_set(&op_ptr, "all", false);
773 }
774 }
775
776 /* Drivers */
777 if (but->flag & BUT_DRIVEN) {
778 layout.separator();
779
780 if (is_array_component) {
781 PointerRNA op_ptr = layout.op(
782 "ANIM_OT_driver_button_remove",
784 ICON_X);
785 RNA_boolean_set(&op_ptr, "all", true);
786 op_ptr = layout.op("ANIM_OT_driver_button_remove",
787 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Single Driver"),
788 ICON_NONE);
789 RNA_boolean_set(&op_ptr, "all", false);
790 }
791 else {
792 PointerRNA op_ptr = layout.op(
793 "ANIM_OT_driver_button_remove",
795 ICON_X);
796 RNA_boolean_set(&op_ptr, "all", true);
797 }
798
799 if (is_whole_array) {
800 PointerRNA op_ptr = layout.op(
801 "UI_OT_copy_driver_to_selected_button",
802 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Drivers to Selected"),
803 ICON_NONE);
804 RNA_boolean_set(&op_ptr, "all", true);
805 }
806 else {
807 layout.op("ANIM_OT_copy_driver_button",
809 ICON_NONE);
810 if (ANIM_driver_can_paste()) {
811 layout.op("ANIM_OT_paste_driver_button",
813 ICON_NONE);
814 }
815 PointerRNA op_ptr = layout.op(
816 "UI_OT_copy_driver_to_selected_button",
817 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Driver to Selected"),
818 ICON_NONE);
819 RNA_boolean_set(&op_ptr, "all", false);
820 if (is_array_component) {
821 PointerRNA op_ptr = layout.op(
822 "UI_OT_copy_driver_to_selected_button",
823 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy All Drivers to Selected"),
824 ICON_NONE);
825 RNA_boolean_set(&op_ptr, "all", true);
826 }
827
828 layout.op("ANIM_OT_driver_button_edit",
830 ICON_DRIVER);
831 }
832
833 layout.op("SCREEN_OT_drivers_editor_show",
834 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open Drivers Editor"),
835 ICON_NONE);
836 }
837 else if (but->flag & (BUT_ANIMATED_KEY | BUT_ANIMATED)) {
838 /* pass */
839 }
840 else if (is_anim) {
841 layout.separator();
842
843 layout.op("ANIM_OT_driver_button_add",
845 ICON_DRIVER);
846
847 if (!is_whole_array) {
848 if (ANIM_driver_can_paste()) {
849 layout.op("ANIM_OT_paste_driver_button",
851 ICON_NONE);
852 }
853 }
854
855 layout.op("SCREEN_OT_drivers_editor_show",
856 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open Drivers Editor"),
857 ICON_NONE);
858 }
859
860 /* Keying Sets */
861 /* TODO: check on modifiability of Keying Set when doing this. */
862 if (is_anim) {
863 layout.separator();
864
865 if (is_array_component) {
866 PointerRNA op_ptr = layout.op(
867 "ANIM_OT_keyingset_button_add",
868 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add All to Keying Set"),
869 ICON_KEYINGSET);
870 RNA_boolean_set(&op_ptr, "all", true);
871 op_ptr = layout.op(
872 "ANIM_OT_keyingset_button_add",
873 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single to Keying Set"),
874 ICON_NONE);
875 RNA_boolean_set(&op_ptr, "all", false);
876 layout.op("ANIM_OT_keyingset_button_remove",
877 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Keying Set"),
878 ICON_NONE);
879 }
880 else {
881 PointerRNA op_ptr = layout.op(
882 "ANIM_OT_keyingset_button_add",
883 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Keying Set"),
884 ICON_KEYINGSET);
885 RNA_boolean_set(&op_ptr, "all", true);
886 layout.op("ANIM_OT_keyingset_button_remove",
887 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Keying Set"),
888 ICON_NONE);
889 }
890 }
891
892 if (is_overridable) {
893 wmOperatorType *ot;
894 PointerRNA op_ptr;
895 /* Override Operators */
896 layout.separator();
897
898 if (but->flag & BUT_OVERRIDDEN) {
899 if (is_array_component) {
900 PointerRNA op_ptr = layout.op(
901 "UI_OT_override_remove_button",
902 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Overrides"),
903 ICON_X);
904 RNA_boolean_set(&op_ptr, "all", true);
905 op_ptr = layout.op(
906 "UI_OT_override_remove_button",
907 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Single Override"),
908 ICON_X);
909 RNA_boolean_set(&op_ptr, "all", false);
910 }
911 else {
912 PointerRNA op_ptr = layout.op(
913 "UI_OT_override_remove_button",
915 ICON_X);
916 RNA_boolean_set(&op_ptr, "all", true);
917 }
918 }
919 else {
920 ot = WM_operatortype_find("UI_OT_override_add_button", false);
921 if (is_array_component) {
922 op_ptr = layout.op(ot,
924 ICON_NONE,
927 RNA_boolean_set(&op_ptr, "all", true);
928 op_ptr = layout.op(ot,
929 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single Override"),
930 ICON_NONE,
933 RNA_boolean_set(&op_ptr, "all", false);
934 }
935 else {
936 op_ptr = layout.op(ot,
938 ICON_NONE,
941 RNA_boolean_set(&op_ptr, "all", false);
942 }
943 }
944 }
945
946 layout.separator();
947
948 /* Property Operators */
949 /* Swap render X and Y dimensions. */
950 if (but->rnaprop && but->rnapoin.type == RNA_RenderSettings) {
951 const std::string prop_id = RNA_property_identifier(but->rnaprop);
952 if (ELEM(prop_id, "resolution_x", "resolution_y")) {
953 layout.op("RENDER_OT_swap_dimensions",
955 ICON_RENDER_SWAP_DIMENSIONS);
956 layout.separator();
957 }
958 }
959
960 /* Copy Property Value
961 * Paste Property Value */
962
963 if (is_array_component) {
964 PointerRNA op_ptr = layout.op(
965 "UI_OT_reset_default_button",
966 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Reset All to Default Values"),
967 ICON_LOOP_BACK);
968 RNA_boolean_set(&op_ptr, "all", true);
969 op_ptr = layout.op(
970 "UI_OT_reset_default_button",
971 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Reset Single to Default Value"),
972 ICON_NONE);
973 RNA_boolean_set(&op_ptr, "all", false);
974 }
975 else {
976 PointerRNA op_ptr = layout.op(
977 "UI_OT_reset_default_button",
978 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Reset to Default Value"),
979 ICON_LOOP_BACK);
980 RNA_boolean_set(&op_ptr, "all", true);
981 }
982
983 if (is_idprop && !is_array && ELEM(type, PROP_INT, PROP_FLOAT)) {
984 layout.op("UI_OT_assign_default_button",
985 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Assign Value as Default"),
986 ICON_NONE);
987
988 layout.separator();
989 }
990
991 if (is_array_component) {
992 PointerRNA op_ptr = layout.op(
993 "UI_OT_copy_to_selected_button",
994 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy All to Selected"),
995 ICON_NONE);
996 RNA_boolean_set(&op_ptr, "all", true);
997 op_ptr = layout.op("UI_OT_copy_to_selected_button",
998 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Single to Selected"),
999 ICON_NONE);
1000 RNA_boolean_set(&op_ptr, "all", false);
1001 }
1002 else {
1003 PointerRNA op_ptr = layout.op(
1004 "UI_OT_copy_to_selected_button",
1005 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy to Selected"),
1006 ICON_NONE);
1007 RNA_boolean_set(&op_ptr, "all", true);
1008 }
1009
1010 layout.op("UI_OT_copy_data_path_button",
1012 ICON_NONE);
1013 PointerRNA op_ptr = layout.op(
1014 "UI_OT_copy_data_path_button",
1015 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Full Data Path"),
1016 ICON_NONE);
1017 RNA_boolean_set(&op_ptr, "full_path", true);
1018
1019 if (ptr->owner_id && !is_whole_array &&
1021 {
1022 layout.op("UI_OT_copy_as_driver_button",
1023 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy as New Driver"),
1024 ICON_NONE);
1025 }
1026
1027 layout.separator();
1028
1029 if (type == PROP_STRING && ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH)) {
1030 if (but_menu_add_path_operators(layout, ptr, prop)) {
1031 layout.separator();
1032 }
1033 }
1034 }
1035 else if (button_opens_link(but)) {
1036 std::string link = button_get_link(but, C);
1037 layout.button(
1038 IFACE_("Copy Link"), ICON_COPYDOWN, [link = std::move(link)](blender::bContext & /*C*/) {
1039 WM_clipboard_text_set(link.c_str(), false);
1040 });
1041 layout.separator();
1042 }
1043 else if (but->optype && but->opptr && RNA_struct_property_is_set(but->opptr, "filepath")) {
1044 /* Operator with "filepath" string property of PROP_FILEPATH subtype. */
1045 PropertyRNA *prop = RNA_struct_find_property(but->opptr, "filepath");
1046 const PropertySubType subtype = RNA_property_subtype(prop);
1047
1048 if (prop && RNA_property_type(prop) == PROP_STRING &&
1050 {
1051 char filepath[FILE_MAX] = {0};
1052 RNA_property_string_get(but->opptr, prop, filepath);
1053 if (filepath[0] && BLI_exists(filepath)) {
1054 wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true);
1055 PointerRNA props_ptr;
1056 char dir[FILE_MAXDIR];
1057 BLI_path_split_dir_part(filepath, dir, sizeof(dir));
1058 props_ptr = layout.op(ot,
1059 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open File Location"),
1060 ICON_NONE,
1062 UI_ITEM_NONE);
1063 RNA_string_set(&props_ptr, "filepath", dir);
1064 layout.separator();
1065 }
1066 }
1067 }
1068
1069 /* Download online assets. */
1070 if (but->optype &&
1072 /* Node tools are special and store the asset reference in custom data. Allow them to
1073 * display the download button as well. */
1074 but->optype->flag & OPTYPE_NODE_TOOL))
1075 {
1077 if (asset && asset->is_online_only()) {
1078 layout.op("ASSET_OT_assets_download", {}, ICON_DOWNLOAD);
1079 }
1080 }
1081
1082 {
1084 ButtonViewItem *view_item_but = (but->type == ButtonType::ViewItem) ?
1085 static_cast<ButtonViewItem *>(but) :
1086 static_cast<ButtonViewItem *>(
1087 view_item_find_mouse_over(region, event->xy));
1088 if (view_item_but) {
1089 BLI_assert(view_item_but->type == ButtonType::ViewItem);
1090
1091 const bContextStore *prev_ctx = CTX_store_get(C);
1092 /* Sub-layout for context override. */
1093 Layout &sub = layout.column(false);
1094 set_layout_context_from_button(C, sub, view_item_but);
1095 view_item_but->view_item->build_context_menu(*C, sub);
1096
1097 /* Reset context. */
1098 CTX_store_set(C, prev_ctx);
1099
1100 layout.separator();
1101 }
1102 }
1103
1104 /* Expose id specific operators in context menu when button has no operator associated. Otherwise
1105 * they would appear in nested context menus, see: #126006. */
1106 if ((but->optype == nullptr) && (but->menu_create_func == nullptr)) {
1107 /* If the button represents an id, it can set the "id" context pointer. */
1109 const ID *id = static_cast<const ID *>(CTX_data_pointer_get_type(C, "id", RNA_ID).data);
1110
1111 /* Gray out items depending on if data-block is an asset. Preferably this could be done via
1112 * operator poll, but that doesn't work since the operator also works with "selected_ids",
1113 * which isn't cheap to check. */
1114 Layout *sub = &layout.column(true);
1115 sub->enabled_set(!id->asset_data);
1116 sub->op("ASSET_OT_mark_single",
1118 ICON_ASSET_MANAGER);
1119 sub = &layout.column(true);
1120 sub->enabled_set(id->asset_data);
1121 sub->op("ASSET_OT_clear_single",
1123 ICON_NONE);
1124 layout.separator();
1125 }
1126
1127 MenuType *mt_idtemplate_liboverride = WM_menutype_find("UI_MT_idtemplate_liboverride", true);
1128 if (mt_idtemplate_liboverride && mt_idtemplate_liboverride->poll(C, mt_idtemplate_liboverride))
1129 {
1130 layout.menu(mt_idtemplate_liboverride, IFACE_("Library Override"), ICON_NONE);
1131 layout.separator();
1132 }
1133 }
1134
1135 /* Pointer properties and string properties with
1136 * prop_search support jumping to target object/bone. */
1137 if (but->rnapoin && but->rnaprop) {
1138 const PropertyType prop_type = RNA_property_type(but->rnaprop);
1139 if (((prop_type == PROP_POINTER) ||
1140 (prop_type == PROP_STRING && but->type == ButtonType::SearchMenu &&
1141 (static_cast<ButtonSearch *>(but))->items_update_fn ==
1144 {
1145 layout.op("UI_OT_jump_to_target_button",
1147 ICON_NONE);
1148 layout.separator();
1149 }
1150 }
1151
1152 /* Favorites Menu */
1153 if (but_is_user_menu_compatible(C, but)) {
1154 Block *block = layout.block();
1155 const int w = layout.width();
1156 bool item_found = false;
1157
1158 uint um_array_len;
1159 bUserMenu **um_array = ED_screen_user_menus_find(C, &um_array_len);
1160 for (int um_index = 0; um_index < um_array_len; um_index++) {
1161 bUserMenu *um = um_array[um_index];
1162 if (um == nullptr) {
1163 continue;
1164 }
1165 bUserMenuItem *umi = but_user_menu_find(C, but, um);
1166 if (umi != nullptr) {
1167 Button *but2 = uiDefIconTextBut(
1168 block,
1170 ICON_MENU_PANEL,
1171 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Quick Favorites"),
1172 0,
1173 0,
1174 w,
1175 UI_UNIT_Y,
1176 nullptr,
1177 "");
1178 item_found = true;
1179 button_func_set(but2, [um, umi](bContext &) {
1180 U.runtime.is_dirty = true;
1182 });
1183 }
1184 }
1185 if (um_array) {
1186 MEM_delete(um_array);
1187 }
1188
1189 if (!item_found) {
1190 Button *but2 = uiDefIconTextBut(
1191 block,
1193 ICON_MENU_PANEL,
1194 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Quick Favorites"),
1195 0,
1196 0,
1197 w,
1198 UI_UNIT_Y,
1199 nullptr,
1200 TIP_("Add to a user defined context menu (stored in the user preferences)"));
1201 button_func_set(but2, [but](bContext &C) {
1203 U.runtime.is_dirty = true;
1204 but_user_menu_add(&C, but, um);
1205 });
1206 }
1207
1208 layout.separator();
1209 }
1210
1211 /* Shortcut menu */
1212 IDProperty *prop;
1213 const char *idname = shortcut_get_operator_property(C, but, &prop);
1214 if (idname != nullptr) {
1215 Block *block = layout.block();
1216 const int w = layout.width();
1217
1218 /* We want to know if this op has a shortcut, be it hotkey or not. */
1219 wmKeyMap *km;
1220 wmKeyMapItem *kmi = shortcut_find(C, but, idname, prop, EVT_TYPE_MASK_ALL, 0, &km);
1221
1222 /* We do have a shortcut, but only keyboard ones are editable that way... */
1223 if (kmi) {
1224 if (ISKEYBOARD(kmi->type) || ISNDOF_BUTTON(kmi->type)) {
1225#if 0 /* would rather use a block but, but gets weirdly positioned... */
1226 uiDefBlockBut(block,
1228 but,
1229 "Change Shortcut...",
1230 0,
1231 0,
1232 layout.width(),
1233 UI_UNIT_Y,
1234 "");
1235#endif
1236
1237 Button *but2 = uiDefIconTextBut(
1238 block,
1240 ICON_HAND,
1241 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Change Shortcut..."),
1242 0,
1243 0,
1244 w,
1245 UI_UNIT_Y,
1246 nullptr,
1247 "");
1248 button_func_set(but2, [but](bContext &C) {
1249 popup_block_invoke(&C, menu_change_shortcut, but, nullptr);
1250 });
1251 }
1252 else {
1253 Button *but2 = uiDefIconTextBut(block,
1255 ICON_HAND,
1256 IFACE_("Non-Keyboard Shortcut"),
1257 0,
1258 0,
1259 w,
1260 UI_UNIT_Y,
1261 nullptr,
1262 TIP_("Only keyboard shortcuts can be edited that way, "
1263 "please use User Preferences otherwise"));
1265 }
1266
1267 Button *but2 = uiDefIconTextBut(
1268 block,
1270 ICON_BLANK1,
1271 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Shortcut"),
1272 0,
1273 0,
1274 w,
1275 UI_UNIT_Y,
1276 nullptr,
1277 "");
1278 button_func_set(but2, [but](bContext &C) { remove_shortcut_func(&C, but); });
1279 }
1280 /* only show 'assign' if there's a suitable key map for it to go in */
1281 else if (WM_keymap_guess_opname(C, idname)) {
1282 Button *but2 = uiDefIconTextBut(
1283 block,
1285 ICON_HAND,
1286 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Assign Shortcut..."),
1287 0,
1288 0,
1289 w,
1290 UI_UNIT_Y,
1291 nullptr,
1292 "");
1293 button_func_set(but2, [but](bContext &C) {
1295 });
1296 }
1297
1299
1300 /* Set the operator pointer for python access */
1301 layout.context_set_from_but(but);
1302
1303 layout.separator();
1304 }
1305
1306 { /* Docs */
1307 if (std::optional<std::string> manual_id = button_online_manual_id(but)) {
1308 PointerRNA ptr_props;
1309 layout.op("WM_OT_doc_view_manual_ui_context",
1311 ICON_URL);
1312
1313 if (U.flag & USER_DEVELOPER_UI) {
1314 ptr_props = layout.op(
1315 "WM_OT_doc_view",
1316 CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
1317 ICON_NONE,
1319 UI_ITEM_NONE);
1320 RNA_string_set(&ptr_props, "doc_id", manual_id.value().c_str());
1321 }
1322 }
1323 }
1324
1325 if (but->optype && U.flag & USER_DEVELOPER_UI) {
1326 layout.op("UI_OT_copy_python_command_button", std::nullopt, ICON_NONE);
1327 }
1328
1329 /* perhaps we should move this into (G.debug & G_DEBUG) - campbell */
1330 if (U.flag & USER_DEVELOPER_UI) {
1331 if (!block_is_menu(but->block) || (but->block->handle && but->block->handle->can_refresh)) {
1332 Layout &sub = layout.column(true);
1333 if (but->block->handle) {
1335 id_cast<ID *>(CTX_wm_screen(C)), RNA_Region, but->block->handle->region);
1336 sub.context_ptr_set("popup_region", &region_ptr);
1337 }
1338 sub.op("UI_OT_editsource",
1339 std::nullopt,
1340 ICON_NONE,
1342 UI_ITEM_NONE);
1343 }
1344 }
1345
1346 /* Show header tools for header buttons. */
1347 if (block_is_popup_any(but->block) == false) {
1348 const ARegion *region = CTX_wm_region(C);
1349
1350 if (!region) {
1351 /* skip */
1352 }
1354 layout.menu_fn(IFACE_("Header"), ICON_NONE, ED_screens_header_tools_menu_create, nullptr);
1355 }
1356 else if (region->regiontype == RGN_TYPE_NAV_BAR) {
1357 layout.menu_fn(IFACE_("Navigation Bar"), ICON_NONE, ED_buttons_navbar_menu, nullptr);
1358 const ScrArea *area = CTX_wm_area(C);
1359 if (area && area->spacetype == SPACE_PROPERTIES) {
1360 layout.menu_fn(IFACE_("Visible Tabs"), ICON_NONE, ED_buttons_visible_tabs_menu, nullptr);
1361 }
1362 }
1363 else if (region->regiontype == RGN_TYPE_FOOTER) {
1364 layout.menu_fn(IFACE_("Footer"), ICON_NONE, ED_screens_footer_tools_menu_create, nullptr);
1365 }
1366 }
1367
1368 /* UI List item context menu. Scripts can add items to it, by default there's nothing shown. */
1370 const bool is_inside_listbox = listbox_find_mouse_over(region, event) != nullptr;
1371 const bool is_inside_listrow = is_inside_listbox ?
1372 listrow_find_mouse_over(region, event->xy) != nullptr :
1373 false;
1374 if (is_inside_listrow) {
1375 MenuType *mt = WM_menutype_find("UI_MT_list_item_context_menu", true);
1376 if (mt) {
1377 menutype_draw(C, mt, &layout.column(false));
1378 }
1379 }
1380
1381 MenuType *mt = WM_menutype_find("UI_MT_button_context_menu", true);
1382 if (mt) {
1383 menutype_draw(C, mt, &layout.column(false));
1384 }
1385
1386 if (but->context) {
1387 CTX_store_set(C, previous_ctx);
1388 }
1389
1390 return popup_menu_end_or_cancel(C, pup);
1391}
1392
1394
1395/* -------------------------------------------------------------------- */
1398
1400{
1401 bScreen *screen = CTX_wm_screen(C);
1402 const bool has_panel_category = panel_category_tabs_is_visible(region);
1403 const bool any_item_visible = has_panel_category;
1404
1405 if (!any_item_visible) {
1407 }
1408 if (panel && panel->type->parent != nullptr) {
1410 }
1411
1414 }
1415
1416 PointerRNA ptr = RNA_pointer_create_discrete(&screen->id, RNA_Panel, panel);
1417
1418 PopupMenu *pup = popup_menu_begin(C, IFACE_("Sidebar"), ICON_NONE);
1419 Layout &layout = *popup_menu_layout(pup);
1420
1422 layout.op("UI_OT_region_start_filter",
1423 IFACE_("Search..."),
1424 ICON_VIEWZOOM,
1426 UI_ITEM_NONE);
1427 layout.separator();
1428 }
1429
1430 if (has_panel_category && panel && panel_can_be_pinned(panel)) {
1431 char tmpstr[80];
1433 tmpstr, "%s" UI_SEP_CHAR_S "%s", IFACE_("Pin Panel"), IFACE_("Shift Left Mouse"));
1434 layout.prop(&ptr, "use_pin", UI_ITEM_NONE, tmpstr, ICON_NONE);
1435
1436 /* evil, force shortcut flag */
1437 {
1438 Block *block = layout.block();
1439 Button *but = block->buttons_ptrs.last().get();
1440 but->flag |= BUT_HAS_SEP_CHAR;
1441 }
1442 layout.separator();
1443 }
1444
1445 PointerRNA prefs_ptr = RNA_pointer_create_discrete(nullptr, RNA_PreferencesSystem, &U);
1446 layout.prop(
1447 &prefs_ptr, "show_panel_tabs_compact", UI_ITEM_NONE, IFACE_("Compact Tabs"), ICON_NONE);
1448
1449 popup_menu_end(C, pup);
1450 return WM_UI_HANDLER_BREAK;
1451}
1452
1454
1455} // namespace blender::ui
Main runtime representation of an asset.
File and directory operations.
#define FILE_MAXFILE
#define FILE_MAX
#define FILE_MAXDIR
#define SNPRINTF_UTF8(dst, format,...)
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Definition DNA_ID.h:691
#define UI_SCALE_FAC
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_SEP_CHAR_S
#define UI_ITEM_NONE
#define WM_UI_HANDLER_CONTINUE
Definition WM_types.hh:361
#define WM_UI_HANDLER_BREAK
Definition WM_types.hh:362
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
virtual void build_context_menu(bContext &C, Layout &column) const
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
bool can_mark_single_from_context(const bContext *C)
bool operator_asset_reference_props_is_set(PointerRNA &ptr)
Button * uiDefIconTextBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, StringRef str, int x, int y, short width, short height, void *poin, std::optional< StringRef > tip)
static const char * shortcut_get_operator_property(bContext *C, Button *but, IDProperty **r_prop)
void block_direction_set(Block *block, char direction)
std::optional< std::string > button_online_manual_id(const Button *but) ATTR_WARN_UNUSED_RESULT
static void shortcut_free_operator_property(IDProperty *prop)
void button_func_set(Button *but, std::function< void(bContext &)> func)
bool panel_can_be_pinned(const Panel *panel)
Button * view_item_find_mouse_over(const ARegion *region, const int xy[2]) ATTR_NONNULL(1
static void set_layout_context_from_button(bContext *C, Layout &layout, Button *but)
void popup_block_ex(bContext *C, BlockCreateFunc func, BlockHandleFunc popup_func, BlockCancelFunc cancel_func, void *arg, wmOperator *op)
std::string button_context_menu_title_from_button(Button &but)
int popup_context_menu_for_panel(bContext *C, ARegion *region, Panel *panel)
static IDProperty * shortcut_property_from_rna_for_enum(bContext *C, Button *but_parent, Button *but)
static void but_user_menu_add(bContext *C, Button *but, bUserMenu *um)
std::optional< StringRefNull > button_asset_shelf_type_idname_get(const Button *but)
static wmKeyMapItem * shortcut_find(bContext *C, const Button *but, const char *idname, IDProperty *prop, const short include_mask, const short exclude_mask, wmKeyMap **r_km)
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
wmOperatorType * button_operatortype_get_from_enum_menu(Button *but, PropertyRNA **r_prop)
bool jump_to_target_button_poll(bContext *C)
static bool but_menu_add_path_operators(Layout &layout, PointerRNA *ptr, PropertyRNA *prop)
bool popup_menu_end_or_cancel(bContext *C, PopupMenu *pup)
void block_flag_enable(Block *block, int flag)
static void remove_shortcut_func(bContext *C, Button *but)
bool block_is_menu(const Block *block) ATTR_WARN_UNUSED_RESULT
Button * uiDefBlockBut(Block *block, BlockCreateFunc func, void *arg, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
const uiStyle * style_get_dpi()
PanelType * button_paneltype_get(const Button *but)
static IDProperty * shortcut_property_from_rna(bContext *C, Button *but)
void popup_block_invoke(bContext *C, BlockCreateFunc func, void *arg, FreeArgFunc arg_free, StructRNA *srna_owner=nullptr)
void button_flag_enable(Button *but, int64_t flag)
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
Layout * popup_menu_layout(PopupMenu *pup)
static bUserMenuItem * but_user_menu_find(bContext *C, Button *but, bUserMenu *um)
static Block * menu_change_shortcut(bContext *C, ARegion *region, void *arg)
static Block * menu_add_shortcut(bContext *C, ARegion *region, void *arg)
bool panel_category_tabs_is_visible(const ARegion *region)
static bool but_is_user_menu_compatible(bContext *C, Button *but)
Button * listrow_find_mouse_over(const ARegion *region, const int xy[2]) ATTR_NONNULL(1
void rna_collection_search_update_fn(const bContext *C, void *arg, const char *str, SearchItems *items, bool is_first)
void menutype_draw(bContext *C, MenuType *mt, Layout *layout)
void block_func_handle_set(Block *block, BlockHandleFunc func, void *arg)
static void but_shortcut_name_func(bContext *C, void *arg1, int)
void block_bounds_set_popup(Block *block, int addval, const int bounds_offset[2])
Definition interface.cc:667
bool button_opens_link(const Button *button)
Button * listbox_find_mouse_over(const ARegion *region, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
bool popup_context_menu_for_button(bContext *C, Button *but, const wmEvent *event)
MenuType * button_menutype_get(const Button *but)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
std::string button_get_link(const Button *button, bContext *C)
void popup_menu_end(bContext *C, PopupMenu *pup)
bool block_is_popup_any(const Block *block) ATTR_WARN_UNUSED_RESULT
StringRef button_drawstr_without_sep_char(const Button *but) ATTR_NONNULL()
static void menu_add_shortcut_cancel(bContext *C, void *arg1)
void button_add_shortcut(Button *but, const char *shortcut_str, const bool do_strip)
bool but_is_tool(const Button *but)
void WM_keymap_item_properties_reset(wmKeyMapItem *kmi, IDProperty *properties)
Definition wm_keymap.cc:210
UserDef U
Definition blender.cc:58
bUserMenu * ED_screen_user_menu_ensure(bContext *C)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ScrArea * CTX_wm_area(const bContext *C)
bool BKE_regiontype_uses_panel_categories_search(const ARegionType *region_type)
Definition screen.cc:417
std::optional< std::string > WM_context_path_resolve_property_full(const bContext *C, const PointerRNA *ptr, PropertyRNA *prop, int index)
void ED_screen_user_menu_item_add_menu(ListBaseT< bUserMenuItem > *lb, const char *ui_name, const MenuType *mt)
wmKeyMapItem * WM_keymap_item_find_id(wmKeyMap *keymap, const int id)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
unsigned int uint
Definition BKE_text.h:55
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
void ED_screens_footer_tools_menu_create(bContext *C, ui::Layout *layout, void *arg)
const char * RNA_property_identifier(const PropertyRNA *prop)
wmKeyMapItem * WM_key_event_operator_from_keymap(wmKeyMap *keymap, const char *opname, IDProperty *properties, const short include_mask, const short exclude_mask)
class asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
bool BKE_regiontype_uses_category_tabs(const ARegionType *region_type)
Definition screen.cc:407
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
void WM_keyconfig_update(wmWindowManager *wm)
wmKeyMap * WM_keymap_guess_opname(const bContext *C, const char *opname)
bUserMenu ** ED_screen_user_menus_find(const bContext *C, uint *r_len)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void ED_screen_user_menu_item_add_prop(ListBaseT< bUserMenuItem > *lb, const char *ui_name, const char *context_data_path, const char *prop_id, int prop_index)
bool ANIM_driver_can_paste()
Definition drivers.cc:561
void ED_buttons_navbar_menu(bContext *C, ui::Layout *layout, void *)
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
void ED_screen_user_menu_item_add_operator(ListBaseT< bUserMenuItem > *lb, const char *ui_name, const wmOperatorType *ot, const IDProperty *prop, const char *op_prop_enum, wm::OpCallContext opcontext)
std::optional< std::string > WM_context_path_resolve_full(bContext *C, const PointerRNA *ptr)
wmKeyMapItem * WM_keymap_add_item(wmKeyMap *keymap, const char *idname, const KeyMapItem_Params *params)
Definition wm_keymap.cc:563
bUserMenuItem_Menu * ED_screen_user_menu_item_find_menu(ListBaseT< bUserMenuItem > *lb, const MenuType *mt)
const bContextStore * CTX_store_get(const bContext *C)
PropertyType RNA_property_type(PropertyRNA *prop)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
bool RNA_property_anim_editable(const PointerRNA *ptr, PropertyRNA *prop_orig)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
wmWindowManager * CTX_wm_manager(const bContext *C)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool RNA_property_is_idprop(const PropertyRNA *prop)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void ED_screens_header_tools_menu_create(bContext *C, ui::Layout *layout, void *arg)
eRNAOverrideStatus RNA_property_override_library_status(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, const int index)
std::string RNA_path_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index)
Definition rna_path.cc:1410
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
wmKeyMapItem * WM_key_event_operator(const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const short include_mask, const short exclude_mask, wmKeyMap **r_keymap)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
Main * CTX_data_main(const bContext *C)
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void WM_clipboard_text_set(const char *buf, bool selection)
ARegion * CTX_wm_region_popup(const bContext *C)
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
bScreen * CTX_wm_screen(const bContext *C)
@ OPTYPE_NODE_TOOL
Definition WM_types.hh:234
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void CTX_store_set(bContext *C, const bContextStore *store)
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_DIRPATH
Definition RNA_types.hh:285
void ED_buttons_visible_tabs_menu(bContext *C, ui::Layout *layout, void *)
void ED_screen_user_menu_item_remove(ListBaseT< bUserMenuItem > *lb, bUserMenuItem *umi)
bUserMenuItem_Prop * ED_screen_user_menu_item_find_prop(ListBaseT< bUserMenuItem > *lb, const char *context_data_path, const char *prop_id, int prop_index)
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:469
ARegion * CTX_wm_region(const bContext *C)
void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
Definition wm_keymap.cc:595
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
bool bool bool bool BPY_run_string_as_string(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
bUserMenuItem_Op * ED_screen_user_menu_item_find_operator(ListBaseT< bUserMenuItem > *lb, const wmOperatorType *ot, IDProperty *prop, const char *op_prop_enum, wm::OpCallContext opcontext)
bke::ARegionRuntime * runtime
eRegion_Type regiontype
bool(*) poll(const bContext *C, MenuType *mt)
PanelType * parent
struct PanelType * type
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< bUserMenuItem > items
struct ARegionType * type
Vector< std::unique_ptr< Button > > buttons_ptrs
PopupBlockHandle * handle
wm::OpCallContext opcontext
std::function< std::string(const Button *)> tip_quick_func
MenuCreateFunc menu_create_func
wmOperatorType * optype
const bContextStore * context
void enabled_set(bool enabled)
bContextStore * context_store() const
void operator_context_set(wm::OpCallContext opcontext)
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void context_set_from_but(const Button *but)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void menu(MenuType *mt, std::optional< StringRef > name, int icon)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Button * button(StringRef name, int icon, std::function< void(bContext &)> func, std::optional< StringRef > tooltip=std::nullopt)
void context_ptr_set(StringRef name, const PointerRNA *ptr)
void context_copy(const bContextStore *context)
void menu_fn(StringRefNull name, int icon, MenuCreateFunc func, void *arg)
#define ISNDOF_BUTTON(event_type)
#define ISKEYBOARD(event_type)
#define EVT_TYPE_MASK_ALL