Blender V5.0
interface_template_keymap.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_context.hh"
10
11#include "RNA_access.hh"
12#include "RNA_prototypes.hh"
13
14#include "WM_api.hh"
15
17#include "interface_intern.hh"
18
19static void keymap_item_modified(bContext * /*C*/, void *kmi_p, void * /*unused*/)
20{
21 wmKeyMapItem *kmi = (wmKeyMapItem *)kmi_p;
22 WM_keyconfig_update_tag(nullptr, kmi);
23 U.runtime.is_dirty = true;
24}
25
26static void template_keymap_item_properties(uiLayout *layout, const char *title, PointerRNA *ptr)
27{
28 layout->separator();
29
30 if (title) {
31 layout->label(title, ICON_NONE);
32 }
33
34 uiLayout *flow = &layout->column_flow(2, false);
35
37 const bool is_set = RNA_property_is_set(ptr, prop);
38 uiBut *but;
39
40 /* recurse for nested properties */
41 if (RNA_property_type(prop) == PROP_POINTER) {
43
44 if (propptr.data && RNA_struct_is_a(propptr.type, &RNA_OperatorProperties)) {
45 const char *name = RNA_property_ui_name(prop);
46 template_keymap_item_properties(layout, name, &propptr);
47 continue;
48 }
49 }
50
51 uiLayout *box = &flow->box();
52 box->active_set(is_set);
53 uiLayout *row = &box->row(false);
54
55 /* property value */
56 row->prop(ptr, prop, -1, 0, UI_ITEM_NONE, std::nullopt, ICON_NONE);
57
58 if (is_set) {
59 /* unset operator */
60 uiBlock *block = row->block();
62 but = uiDefIconButO(block,
64 "UI_OT_unset_property_button",
66 ICON_X,
67 0,
68 0,
71 std::nullopt);
72 but->rnapoin = *ptr;
73 but->rnaprop = prop;
75 }
76 }
78}
79
81{
82 PointerRNA propptr = RNA_pointer_get(ptr, "properties");
83
84 if (propptr.data) {
85 uiBlock *block = layout->block();
86 int i = layout->block()->buttons.size() - 1;
87
88 WM_operator_properties_sanitize(&propptr, false);
89 template_keymap_item_properties(layout, nullptr, &propptr);
90 if (i < 0) {
91 return;
92 }
93 /* attach callbacks to compensate for missing properties update,
94 * we don't know which keymap (item) is being modified there */
95 for (; i < block->buttons.size(); i++) {
96 uiBut *but = block->buttons[i].get();
97 /* operator buttons may store props for use (file selector, #36492) */
98 if (but->rnaprop) {
99 UI_but_func_set(but, keymap_item_modified, ptr->data, nullptr);
100
101 /* Otherwise the keymap will be re-generated which we're trying to edit,
102 * see: #47685 */
104 }
105 }
106 }
107}
#define RNA_STRUCT_END
#define RNA_STRUCT_BEGIN_SKIP_RNA_TYPE(sptr, prop)
@ PROP_POINTER
Definition RNA_types.hh:167
void UI_but_func_set(uiBut *but, std::function< void(bContext &)> func)
#define UI_UNIT_Y
void UI_block_emboss_set(uiBlock *block, blender::ui::EmbossType emboss)
@ UI_BUT_UPDATE_DELAY
uiBut * uiDefIconButO(uiBlock *block, ButType type, blender::StringRefNull opname, blender::wm::OpCallContext opcontext, int icon, int x, int y, short width, short height, std::optional< blender::StringRef > tip)
#define UI_UNIT_X
void UI_but_flag_enable(uiBut *but, int flag)
#define UI_ITEM_NONE
#define U
int64_t size() const
static void template_keymap_item_properties(uiLayout *layout, const char *title, PointerRNA *ptr)
static void keymap_item_modified(bContext *, void *kmi_p, void *)
void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
const char * name
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
PropertyType RNA_property_type(PropertyRNA *prop)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
blender::Vector< std::unique_ptr< uiBut > > buttons
PropertyRNA * rnaprop
PointerRNA rnapoin
uiLayout & column_flow(int number, bool align)
uiBlock * block() const
void label(blender::StringRef name, int icon)
void active_set(bool active)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
uiLayout & row(bool align)
uiLayout & box()
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238
void WM_keyconfig_update_tag(wmKeyMap *keymap, wmKeyMapItem *kmi)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)