diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-30 16:22:02 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-30 16:22:02 +0400 |
commit | 54223ed05b7e2840865b5e46ed6d43573ff2b4ae (patch) | |
tree | 318ecb1a6b2afa8278829f06dfb0a50c0de06b36 /source/blender/windowmanager | |
parent | c8015a27888a4c87360b1af158fc9b70bd4112ae (diff) |
Add active region for operator execution.
This means you can for example, uv unwrap in quad-view and change settings in the toolbar without defaulting back to the first quad-view region available.
This may be displayed to the user later, for now this is set on executing registrable operators.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 55 |
2 files changed, 43 insertions, 14 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index bea54154e47..7f32fd6698e 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -311,6 +311,8 @@ void WM_event_fileselect_event(struct bContext *C, void *ophandle, int eventval void WM_event_print(struct wmEvent *event); #endif +void WM_operator_region_active_win_set(struct bContext *C); + /* drag and drop */ struct wmDrag *WM_event_start_drag(struct bContext *C, int icon, int type, void *poin, double value); void WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale, int sx, int sy); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 84fee9ff34c..4a95c6ac091 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -453,6 +453,22 @@ static void wm_operator_print(bContext *C, wmOperator *op) MEM_freeN(buf); } +/** + * Sets the active region for this space from the context. + * + * \see #BKE_area_find_region_active_win + */ +void WM_operator_region_active_win_set(bContext *C) +{ + ScrArea *sa = CTX_wm_area(C); + if (sa) { + ARegion *ar = CTX_wm_region(C); + if (ar && ar->regiontype == RGN_TYPE_WINDOW) { + sa->region_active_win = BLI_findindex(&sa->regionbase, ar); + } + } +} + /* for debugging only, getting inspecting events manually is tedious */ #ifndef NDEBUG @@ -573,10 +589,13 @@ static void wm_operator_finished(bContext *C, wmOperator *op, int repeat) MEM_freeN(buf); } - if (wm_operator_register_check(wm, op->type)) + if (wm_operator_register_check(wm, op->type)) { wm_operator_register(C, op); - else + WM_operator_region_active_win_set(C); + } + else { WM_operator_free(op); + } } } @@ -1045,7 +1064,14 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA } if (!(ar && ar->regiontype == type) && area) { - ARegion *ar1 = BKE_area_find_region_type(area, type); + ARegion *ar1; + if (type == RGN_TYPE_WINDOW) { + ar1 = BKE_area_find_region_active_win(area); + } + else { + ar1 = BKE_area_find_region_type(area, type); + } + if (ar1) CTX_wm_region_set(C, ar1); } @@ -1417,20 +1443,10 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand if (ot->flag & OPTYPE_UNDO) wm->op_undo_depth--; - /* putting back screen context, reval can pass trough after modal failures! */ - if ((retval & OPERATOR_PASS_THROUGH) || wm_event_always_pass(event)) { - CTX_wm_area_set(C, area); - CTX_wm_region_set(C, region); - } - else { - /* this special cases is for areas and regions that get removed */ - CTX_wm_area_set(C, NULL); - CTX_wm_region_set(C, NULL); - } - if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) wm_operator_reports(C, op, retval, FALSE); + /* important to run 'wm_operator_finished' before NULLing the context members */ if (retval & OPERATOR_FINISHED) { wm_operator_finished(C, op, 0); handler->op = NULL; @@ -1440,6 +1456,17 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand handler->op = NULL; } + /* putting back screen context, reval can pass trough after modal failures! */ + if ((retval & OPERATOR_PASS_THROUGH) || wm_event_always_pass(event)) { + CTX_wm_area_set(C, area); + CTX_wm_region_set(C, region); + } + else { + /* this special cases is for areas and regions that get removed */ + CTX_wm_area_set(C, NULL); + CTX_wm_region_set(C, NULL); + } + /* remove modal handler, operator itself should have been canceled and freed */ if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) { WM_cursor_grab_disable(CTX_wm_window(C), NULL); |