From a99ec8806281f733ce24a849553ca209c3780ff9 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 15 Jun 2023 17:47:26 +0200 Subject: [PATCH] UI: Use new C++ button apply function No user visible changes expected. --- .../interface/interface_context_menu.cc | 54 +++++++------------ .../interface_template_light_linking.cc | 9 +--- .../interface/interface_template_list.cc | 7 ++- .../blender/windowmanager/intern/wm_files.cc | 17 +++--- 4 files changed, 32 insertions(+), 55 deletions(-) diff --git a/source/blender/editors/interface/interface_context_menu.cc b/source/blender/editors/interface/interface_context_menu.cc index 44460cab0cf..3e22629ee9d 100644 --- a/source/blender/editors/interface/interface_context_menu.cc +++ b/source/blender/editors/interface/interface_context_menu.cc @@ -31,6 +31,7 @@ #include "ED_screen.h" #include "UI_interface.h" +#include "UI_interface.hh" #include "interface_intern.hh" @@ -276,15 +277,8 @@ static void menu_add_shortcut_cancel(bContext *C, void *arg1) WM_keymap_remove_item(km, kmi); } -static void popup_change_shortcut_func(bContext *C, void *arg1, void * /*arg2*/) +static void remove_shortcut_func(bContext *C, uiBut *but) { - uiBut *but = (uiBut *)arg1; - UI_popup_block_invoke(C, menu_change_shortcut, but, nullptr); -} - -static void remove_shortcut_func(bContext *C, void *arg1, void * /*arg2*/) -{ - uiBut *but = (uiBut *)arg1; IDProperty *prop; const char *idname = shortcut_get_operator_property(C, but, &prop); @@ -305,12 +299,6 @@ static void remove_shortcut_func(bContext *C, void *arg1, void * /*arg2*/) but_shortcut_name_func(C, but, 0); } -static void popup_add_shortcut_func(bContext *C, void *arg1, void * /*arg2*/) -{ - uiBut *but = (uiBut *)arg1; - UI_popup_block_ex(C, menu_add_shortcut, nullptr, menu_add_shortcut_cancel, but, nullptr); -} - static bool ui_but_is_user_menu_compatible(bContext *C, uiBut *but) { bool result = false; @@ -444,22 +432,6 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um) } } -static void popup_user_menu_add_or_replace_func(bContext *C, void *arg1, void * /*arg2*/) -{ - uiBut *but = static_cast(arg1); - bUserMenu *um = ED_screen_user_menu_ensure(C); - U.runtime.is_dirty = true; - ui_but_user_menu_add(C, but, um); -} - -static void popup_user_menu_remove_func(bContext * /*C*/, void *arg1, void *arg2) -{ - bUserMenu *um = static_cast(arg1); - bUserMenuItem *umi = static_cast(arg2); - U.runtime.is_dirty = true; - ED_screen_user_menu_item_remove(&um->items, umi); -} - static void ui_but_menu_add_path_operators(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop) { const PropertySubType subtype = RNA_property_subtype(prop); @@ -1043,8 +1015,10 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev 0, 0, ""); - UI_but_func_set(but2, popup_user_menu_remove_func, um, umi); - item_found = true; + UI_but_func_set(but2, [um, umi](bContext &) { + U.runtime.is_dirty = true; + ED_screen_user_menu_item_remove(&um->items, umi); + }); } } if (um_array) { @@ -1068,7 +1042,11 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev 0, 0, "Add to a user defined context menu (stored in the user preferences)"); - UI_but_func_set(but2, popup_user_menu_add_or_replace_func, but, nullptr); + UI_but_func_set(but2, [but](bContext &C) { + bUserMenu *um = ED_screen_user_menu_ensure(&C); + U.runtime.is_dirty = true; + ui_but_user_menu_add(&C, but, um); + }); } uiItemS(layout); @@ -1117,7 +1095,9 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev 0, 0, ""); - UI_but_func_set(but2, popup_change_shortcut_func, but, nullptr); + UI_but_func_set(but2, [but](bContext &C) { + UI_popup_block_invoke(&C, menu_change_shortcut, but, nullptr); + }); } else { uiBut *but2 = uiDefIconTextBut(block, @@ -1155,7 +1135,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev 0, 0, ""); - UI_but_func_set(but2, remove_shortcut_func, but, nullptr); + UI_but_func_set(but2, [but](bContext &C) { remove_shortcut_func(&C, but); }); } /* only show 'assign' if there's a suitable key map for it to go in */ else if (WM_keymap_guess_opname(C, idname)) { @@ -1175,7 +1155,9 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev 0, 0, ""); - UI_but_func_set(but2, popup_add_shortcut_func, but, nullptr); + UI_but_func_set(but2, [but](bContext &C) { + UI_popup_block_ex(&C, menu_add_shortcut, nullptr, menu_add_shortcut_cancel, but, nullptr); + }); } shortcut_free_operator_property(prop); diff --git a/source/blender/editors/interface/interface_template_light_linking.cc b/source/blender/editors/interface/interface_template_light_linking.cc index e20b7b9bf9f..a9326b1ae3f 100644 --- a/source/blender/editors/interface/interface_template_light_linking.cc +++ b/source/blender/editors/interface/interface_template_light_linking.cc @@ -131,13 +131,8 @@ class CollectionViewItem : public BasicTreeViewItem { return ICON_NONE; } - static void link_state_toggle_cb(bContext * /*C*/, - void * /*collection_v*/, - void *collection_light_linking_v) + static void link_state_toggle(CollectionLightLinking &collection_light_linking) { - CollectionLightLinking &collection_light_linking = *static_cast( - collection_light_linking_v); - switch (collection_light_linking.link_state) { case COLLECTION_LIGHT_LINKING_STATE_INCLUDE: collection_light_linking.link_state = COLLECTION_LIGHT_LINKING_STATE_EXCLUDE; @@ -178,7 +173,7 @@ class CollectionViewItem : public BasicTreeViewItem { 0.0f, nullptr); - UI_but_func_set(button, link_state_toggle_cb, &collection_, &collection_light_linking_); + UI_but_func_set(button, [this](bContext &) { link_state_toggle(collection_light_linking_); }); } void build_remove_button(uiLayout &row) diff --git a/source/blender/editors/interface/interface_template_list.cc b/source/blender/editors/interface/interface_template_list.cc index 896c3cd6773..080e93c57de 100644 --- a/source/blender/editors/interface/interface_template_list.cc +++ b/source/blender/editors/interface/interface_template_list.cc @@ -610,9 +610,8 @@ static void uilist_prepare(uiList *ui_list, items->tot_items); } -static void uilist_resize_update_cb(bContext *C, void *arg1, void * /*arg2*/) +static void uilist_resize_update(bContext *C, uiList *ui_list) { - uiList *ui_list = static_cast(arg1); uiListDyn *dyn_data = ui_list->dyn_data; /* This way we get diff in number of additional items to show (positive) or hide (negative). */ @@ -1148,7 +1147,7 @@ static void ui_template_list_layout_draw(const bContext *C, 0, 0, ""); - UI_but_func_set(but, uilist_resize_update_cb, ui_list, nullptr); + UI_but_func_set(but, [ui_list](bContext &C) { uilist_resize_update(&C, ui_list); }); } UI_block_emboss_set(subblock, UI_EMBOSS); @@ -1205,7 +1204,7 @@ static void ui_template_list_layout_draw(const bContext *C, 0, 0, ""); - UI_but_func_set(but, uilist_resize_update_cb, ui_list, nullptr); + UI_but_func_set(but, [ui_list](bContext &C) { uilist_resize_update(&C, ui_list); }); } UI_block_emboss_set(subblock, UI_EMBOSS); diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 30750dbfa18..74c02bb740e 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -109,6 +109,7 @@ #include "GPU_context.h" #include "UI_interface.h" +#include "UI_interface.hh" #include "UI_resources.h" #include "UI_view2d.h" @@ -3483,13 +3484,11 @@ static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void * wm_test_autorun_revert_action_set(nullptr, nullptr); } -static void wm_block_autorun_warning_reload_with_scripts(bContext *C, - void *arg_block, - void * /*arg*/) +static void wm_block_autorun_warning_reload_with_scripts(bContext *C, uiBlock *block) { wmWindow *win = CTX_wm_window(C); - UI_popup_block_close(C, win, static_cast(arg_block)); + UI_popup_block_close(C, win, block); /* Save user preferences for permanent execution. */ if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { @@ -3501,12 +3500,12 @@ static void wm_block_autorun_warning_reload_with_scripts(bContext *C, wm_test_autorun_revert_action_exec(C); } -static void wm_block_autorun_warning_enable_scripts(bContext *C, void *arg_block, void * /*arg*/) +static void wm_block_autorun_warning_enable_scripts(bContext *C, uiBlock *block) { wmWindow *win = CTX_wm_window(C); Main *bmain = CTX_data_main(C); - UI_popup_block_close(C, win, static_cast(arg_block)); + UI_popup_block_close(C, win, block); /* Save user preferences for permanent execution. */ if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { @@ -3586,7 +3585,8 @@ static uiBlock *block_create_autorun_warning(bContext *C, ARegion *region, void 0, 0, TIP_("Reload file with execution of Python scripts enabled")); - UI_but_func_set(but, wm_block_autorun_warning_reload_with_scripts, block, nullptr); + UI_but_func_set( + but, [block](bContext &C) { wm_block_autorun_warning_reload_with_scripts(&C, block); }); } else { but = uiDefIconTextBut(block, @@ -3604,7 +3604,8 @@ static uiBlock *block_create_autorun_warning(bContext *C, ARegion *region, void 0, 0, TIP_("Enable scripts")); - UI_but_func_set(but, wm_block_autorun_warning_enable_scripts, block, nullptr); + UI_but_func_set(but, + [block](bContext &C) { wm_block_autorun_warning_enable_scripts(&C, block); }); } UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); -- 2.30.2