From 64cae3d650075217487b16f6f1544fd8806c9df8 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 12 Jun 2023 13:06:22 +0200 Subject: [PATCH 1/2] UI: Attempt to restore region for redo from Adjust Last Operation panel The Adjust Last Operation panel would attempt to use the main region, even when the operator was initially executed in a different region. This becomes an issue when the operator relies on context of the region. For example the pose library gets the active asset from context, which is only available in the region (e.g. asset shelf) displaying the assets. In general it seems like redo should restore the region of invokation. This uses the region type from the initial operator call context to lookup a region to restore on redo. While not completely bullet proof (multiple regions of the same type may be present), this should mitigate the issue quite a bit. --- source/blender/editors/include/ED_screen.h | 5 +++++ .../editors/interface/interface_region_hud.cc | 12 ++++++++++++ source/blender/editors/undo/ed_undo.cc | 14 +++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 2610918074b..59090e87a92 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -697,6 +697,11 @@ ARegion *ED_area_find_region_xy_visual(const ScrArea *area, int regiontype, cons struct ARegionType *ED_area_type_hud(int space_type); void ED_area_type_hud_clear(struct wmWindowManager *wm, ScrArea *area_keep); void ED_area_type_hud_ensure(struct bContext *C, struct ScrArea *area); +/** Lookup the region the operation was executed in, and which should be used to redo the + * operation. The lookup is based on the region type, so it can return a different region when the + * same region type is present multiple times. */ +ARegion *ED_area_type_hud_redo_region_find(const struct ScrArea *area, + const struct ARegion *hud_region); /** * Default key-maps, bit-flags (matches order of evaluation). diff --git a/source/blender/editors/interface/interface_region_hud.cc b/source/blender/editors/interface/interface_region_hud.cc index ccb65453e2c..fae96a895b2 100644 --- a/source/blender/editors/interface/interface_region_hud.cc +++ b/source/blender/editors/interface/interface_region_hud.cc @@ -385,4 +385,16 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) region->visible = !((region->flag & RGN_FLAG_HIDDEN) || (region->flag & RGN_FLAG_TOO_SMALL)); } +ARegion *ED_area_type_hud_redo_region_find(const ScrArea *area, const ARegion *hud_region) +{ + BLI_assert(hud_region->regiontype == RGN_TYPE_HUD); + HudRegionData *hrd = static_cast(hud_region->regiondata); + + if (hrd->regionid == -1) { + return nullptr; + } + + return BKE_area_find_region_type(area, hrd->regionid); +} + /** \} */ diff --git a/source/blender/editors/undo/ed_undo.cc b/source/blender/editors/undo/ed_undo.cc index 24d245b688b..a592327b135 100644 --- a/source/blender/editors/undo/ed_undo.cc +++ b/source/blender/editors/undo/ed_undo.cc @@ -668,14 +668,22 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op) if (op) { CLOG_INFO(&LOG, 1, "idname='%s'", op->type->idname); wmWindowManager *wm = CTX_wm_manager(C); + const ScrArea *area = CTX_wm_area(C); Scene *scene = CTX_data_scene(C); /* keep in sync with logic in view3d_panel_operator_redo() */ ARegion *region_orig = CTX_wm_region(C); - ARegion *region_win = BKE_area_find_region_active_win(CTX_wm_area(C)); + /* If the redo is called from a HUD, this knows about the region type the operator was + * initially called in, so attempt to restore that. */ + ARegion *redo_region_from_hud = (region_orig->regiontype == RGN_TYPE_HUD) ? + ED_area_type_hud_redo_region_find(area, region_orig) : + nullptr; + ARegion *region_repeat = redo_region_from_hud ? + redo_region_from_hud : + BKE_area_find_region_active_win(CTX_wm_area(C)); - if (region_win) { - CTX_wm_region_set(C, region_win); + if (region_repeat) { + CTX_wm_region_set(C, region_repeat); } if (WM_operator_repeat_check(C, op) && WM_operator_poll(C, op->type) && -- 2.30.2 From 51e66060749e87e73ab7efbf683ca2c967ffe74b Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 25 Jul 2023 12:26:33 +0200 Subject: [PATCH 2/2] Address points from review --- source/blender/editors/include/ED_screen.h | 6 ++++-- source/blender/editors/undo/ed_undo.cc | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index f0889c28cbd..1538b13cc62 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -699,9 +699,11 @@ ARegion *ED_area_find_region_xy_visual(const ScrArea *area, int regiontype, cons struct ARegionType *ED_area_type_hud(int space_type); void ED_area_type_hud_clear(struct wmWindowManager *wm, ScrArea *area_keep); void ED_area_type_hud_ensure(struct bContext *C, struct ScrArea *area); -/** Lookup the region the operation was executed in, and which should be used to redo the +/** + * Lookup the region the operation was executed in, and which should be used to redo the * operation. The lookup is based on the region type, so it can return a different region when the - * same region type is present multiple times. */ + * same region type is present multiple times. + */ ARegion *ED_area_type_hud_redo_region_find(const struct ScrArea *area, const struct ARegion *hud_region); diff --git a/source/blender/editors/undo/ed_undo.cc b/source/blender/editors/undo/ed_undo.cc index 21dca02a1b8..d543d3eae70 100644 --- a/source/blender/editors/undo/ed_undo.cc +++ b/source/blender/editors/undo/ed_undo.cc @@ -678,9 +678,8 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op) ARegion *redo_region_from_hud = (region_orig->regiontype == RGN_TYPE_HUD) ? ED_area_type_hud_redo_region_find(area, region_orig) : nullptr; - ARegion *region_repeat = redo_region_from_hud ? - redo_region_from_hud : - BKE_area_find_region_active_win(CTX_wm_area(C)); + ARegion *region_repeat = redo_region_from_hud ? redo_region_from_hud : + BKE_area_find_region_active_win(area); if (region_repeat) { CTX_wm_region_set(C, region_repeat); -- 2.30.2