[Bf-blender-cvs] [36e38470935] master: Fix T76635: Clicking the text button X in a pop-up doesn't clear
Julian Eisel
noreply at git.blender.org
Tue May 12 20:43:39 CEST 2020
Commit: 36e3847093546232db3f16da9189ab7f30207126
Author: Julian Eisel
Date: Tue May 12 20:30:15 2020 +0200
Branches: master
https://developer.blender.org/rB36e3847093546232db3f16da9189ab7f30207126
Fix T76635: Clicking the text button X in a pop-up doesn't clear
In this case giving `CTX_wm_menu()` priority over `CTX_wm_region()` is all
that's needed and makes sense (since we want exactly the hovered button, not
some other active button in the region/menu hierarchy).
The situation with pop-ups is still tricky, see T73565. But as a first step
it's probably good to let functions be more explicit about what they want when
querying UI context. So I added a variation of a UI-context function for cases
like this.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_ops.c
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 8c591a2d0d4..8b7b0430765 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2411,6 +2411,7 @@ bool UI_context_copy_to_selected_list(struct bContext *C,
/* Helpers for Operators */
uiBut *UI_context_active_but_get(const struct bContext *C);
+uiBut *UI_context_active_but_get_respect_menu(const struct bContext *C);
uiBut *UI_context_active_but_prop_get(const struct bContext *C,
struct PointerRNA *r_ptr,
struct PropertyRNA **r_prop,
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index d229419a958..ead36fdbd19 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -8259,11 +8259,22 @@ static uiBut *ui_context_rna_button_active(const bContext *C)
return ui_context_button_active(CTX_wm_region(C), ui_context_rna_button_active_test);
}
-uiBut *UI_context_active_but_get(const struct bContext *C)
+uiBut *UI_context_active_but_get(const bContext *C)
{
return ui_context_button_active(CTX_wm_region(C), NULL);
}
+/*
+ * Version of #UI_context_active_get() that uses the result of #CTX_wm_menu()
+ * if set. Does not traverse into parent menus, which may be wanted in some
+ * cases.
+ */
+uiBut *UI_context_active_but_get_respect_menu(const bContext *C)
+{
+ ARegion *ar_menu = CTX_wm_menu(C);
+ return ui_context_button_active(ar_menu ? ar_menu : CTX_wm_region(C), NULL);
+}
+
uiBut *UI_region_active_but_get(ARegion *region)
{
return ui_context_button_active(region, NULL);
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 9faa17beff7..909da434554 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -1679,7 +1679,7 @@ static void UI_OT_button_execute(wmOperatorType *ot)
static int button_string_clear_exec(bContext *C, wmOperator *UNUSED(op))
{
- uiBut *but = UI_context_active_but_get(C);
+ uiBut *but = UI_context_active_but_get_respect_menu(C);
if (but) {
ui_but_active_string_clear_and_exit(C, but);
More information about the Bf-blender-cvs
mailing list