UI: Close Source Window When Docking Singleton to Empty Space

Docking allows dragging an area out of a window to empty space to make
a new window. And dragging back will close that window if empty.
However dragging an area that is alone in its window to empty space
does not close the source window so you get a duplicate. This PR just
closes that window (when empty) which feels much more natural.

Pull Request: https://projects.blender.org/blender/blender/pulls/125201
This commit is contained in:
Harley Acheson
2024-07-22 03:23:42 +02:00
committed by Harley Acheson
parent e2bc41598d
commit f238b44dee

View File

@@ -3997,7 +3997,15 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* We have to clear handlers or we get an error in wm_gizmomap_modal_get. */
WM_event_modal_handler_region_replace(jd->win1, CTX_wm_region(C), nullptr);
area_dupli_open(C, jd->sa1, blender::int2(event->xy[0], event->xy[1] - jd->sa1->winy));
screen_area_close(C, WM_window_get_active_screen(jd->win1), jd->sa1);
if (!screen_area_close(C, WM_window_get_active_screen(jd->win1), jd->sa1)) {
if (BLI_listbase_is_single(&WM_window_get_active_screen(jd->win1)->areabase) &&
BLI_listbase_is_empty(&jd->win1->global_areas.areabase))
{
/* We've pulled a single editor out of the window into empty space.
* Close the source window so we don't end up with a duplicate. */
jd->close_win = true;
}
}
}
}
else if (jd->sa1 && jd->sa1 == jd->sa2) {
@@ -4027,10 +4035,11 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED;
}
const bool close_win = jd->close_win;
const bool do_close_win = jd->close_win;
wmWindow *close_win = jd->win1;
area_join_exit(C, op);
if (close_win) {
wm_window_close(C, CTX_wm_manager(C), CTX_wm_window(C));
if (do_close_win) {
wm_window_close(C, CTX_wm_manager(C), close_win);
}
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, nullptr);