[Bf-blender-cvs] [a0f2923fd82] master: Fix active workspace changes when deleting workspace

Dalai Felinto noreply at git.blender.org
Fri Mar 8 22:54:55 CET 2019


Commit: a0f2923fd821099039c6350f3e8666d1d4d37ec9
Author: Dalai Felinto
Date:   Fri Mar 8 18:48:27 2019 -0300
Branches: master
https://developer.blender.org/rBa0f2923fd821099039c6350f3e8666d1d4d37ec9

Fix active workspace changes when deleting workspace

Tested for multi-window as well, which failed with the previous code even
before we introduced ordered workspaces.

===================================================================

M	source/blender/editors/screen/workspace_edit.c

===================================================================

diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index b63a755368e..c777308e435 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -221,20 +221,31 @@ WorkSpace *ED_workspace_duplicate(
 bool ED_workspace_delete(
         WorkSpace *workspace, Main *bmain, bContext *C, wmWindowManager *wm)
 {
-	ID *workspace_id = (ID *)workspace;
-
 	if (BLI_listbase_is_single(&bmain->workspaces)) {
 		return false;
 	}
 
-	for (wmWindow *win = wm->windows.first; win; win = win->next) {
-		WorkSpace *prev = workspace_id->prev;
-		WorkSpace *next = workspace_id->next;
+	ListBase ordered;
+	BKE_id_ordered_list(&ordered, &bmain->workspaces);
+	WorkSpace *prev = NULL, *next = NULL;
+	for (LinkData *link = ordered.first; link; link = link->next) {
+		if (link->data == workspace) {
+			prev = link->prev ? link->prev->data : NULL;
+			next = link->next ? link->next->data : NULL;
+			break;
+		}
+	}
+	BLI_freelistN(&ordered);
+	BLI_assert((prev != NULL) || (next != NULL));
 
-		ED_workspace_change((prev != NULL) ? prev : next, C, wm, win);
+	for (wmWindow *win = wm->windows.first; win; win = win->next) {
+		WorkSpace *workspace_active = WM_window_get_active_workspace(win);
+		if (workspace_active == workspace) {
+			ED_workspace_change((prev != NULL) ? prev : next, C, wm, win);
+		}
 	}
-	BKE_id_free(bmain, workspace_id);
 
+	BKE_id_free(bmain, &workspace->id);
 	return true;
 }



More information about the Bf-blender-cvs mailing list