UI: Properly cancel dragging on escape or right-click

This is refering to drag & drop within Blender which is using the
drop-box system.

Previously Escape would cancel the dragging, but still pass on the event
to other event handlers, which could trigger other behavior. For example
cancelling dragging a file in a file browser dialog would also cancel
the file browser operation and close the window. Right-click didn't
cancel anything even though we usually use both Escape and right-click
as a way to cancel the operation.

Now both escape and right-click both cancel the dragging and the event
is not passed on further.

Pull Request: #104838
This commit is contained in:
Julian Eisel
2023-02-22 16:54:07 +01:00
parent d6a61bc864
commit d58e422ac3

View File

@@ -3669,22 +3669,26 @@ static void wm_paintcursor_test(bContext *C, const wmEvent *event)
}
}
static void wm_event_drag_and_drop_test(wmWindowManager *wm, wmWindow *win, wmEvent *event)
static eHandlerActionFlag wm_event_drag_and_drop_test(wmWindowManager *wm,
wmWindow *win,
wmEvent *event)
{
bScreen *screen = WM_window_get_active_screen(win);
if (BLI_listbase_is_empty(&wm->drags)) {
return;
return WM_HANDLER_CONTINUE;
}
if (event->type == MOUSEMOVE || ISKEYMODIFIER(event->type)) {
screen->do_draw_drag = true;
}
else if (event->type == EVT_ESCKEY) {
else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
wm_drags_exit(wm, win);
WM_drag_free_list(&wm->drags);
screen->do_draw_drag = true;
return WM_HANDLER_BREAK;
}
else if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
event->type = EVT_DROP;
@@ -3703,6 +3707,8 @@ static void wm_event_drag_and_drop_test(wmWindowManager *wm, wmWindow *win, wmEv
/* Restore cursor (disabled, see `wm_dragdrop.cc`) */
// WM_cursor_modal_restore(win);
}
return WM_HANDLER_CONTINUE;
}
/**
@@ -4025,7 +4031,7 @@ void wm_event_do_handlers(bContext *C)
}
/* Check dragging, creates new event or frees, adds draw tag. */
wm_event_drag_and_drop_test(wm, win, event);
action |= wm_event_drag_and_drop_test(wm, win, event);
if ((action & WM_HANDLER_BREAK) == 0) {
/* NOTE: setting sub-window active should be done here,