[Bf-blender-cvs] [9db492de6dd] blender2.8: Cleanup: Get rid of ScrArea.butspacetype syncing with ScrArea.spacetype

Julian Eisel noreply at git.blender.org
Mon Apr 23 00:26:06 CEST 2018


Commit: 9db492de6dd07dca93f0de7dbfa92f811fe50765
Author: Julian Eisel
Date:   Sun Apr 22 19:58:27 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9db492de6dd07dca93f0de7dbfa92f811fe50765

Cleanup: Get rid of ScrArea.butspacetype syncing with ScrArea.spacetype

The only real reason we need `butspacetype` is while switching areas, where we
need to delay the actual switch to the RNA _update callback since only there we
can access context.
So instead of trying to sync it with `spacetype`, only set while needed and
unset it afterwards (as in set to `SPACE_EMPTY`).

This should also allow us to re-use `butspacetype` in versioning code when
trying to read removed editors. It'll store the space type value of the removed
editor which we can then use on versioning.

For backwards compatibility, we store `butspacetype` with the value of
`spacetype`.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_250.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_screen.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7ca53e00d1b..19f260fb3a7 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6394,6 +6394,7 @@ static void direct_link_area(FileData *fd, ScrArea *area)
 
 	BLI_listbase_clear(&area->handlers);
 	area->type = NULL;	/* spacetype callbacks */
+	area->butspacetype = SPACE_EMPTY; /* Should always be unset so that rna_Area_type_get works correctly */
 	area->region_active_win = -1;
 
 	area->global = newdataadr(fd, area->global);
@@ -6420,9 +6421,6 @@ static void direct_link_area(FileData *fd, ScrArea *area)
 		blo_do_versions_view3d_split_250(area->spacedata.first, &area->regionbase);
 	}
 
-	/* incase we set above */
-	area->butspacetype = area->spacetype;
-
 	for (sl = area->spacedata.first; sl; sl = sl->next) {
 		link_list(fd, &(sl->regionbase));
 
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index 2610f57f124..780abb693a3 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -429,9 +429,6 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
 				sl->spacetype = SPACE_EMPTY;	/* spacedata then matches */
 		}
 
-		/* it seems to be possible in 2.5 to have this saved, filewindow probably */
-		sa->butspacetype = sa->spacetype;
-
 		/* pushed back spaces also need regions! */
 		if (sa->spacedata.first) {
 			sl = sa->spacedata.first;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index e78c32e9eda..60aa719c459 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2898,6 +2898,8 @@ static void write_area_map(WriteData *wd, ScrAreaMap *area_map)
 	writelist(wd, DATA, ScrVert, &area_map->vertbase);
 	writelist(wd, DATA, ScrEdge, &area_map->edgebase);
 	for (ScrArea *area = area_map->areabase.first; area; area = area->next) {
+		area->butspacetype = area->spacetype; /* Just for compatibility, will be reset below. */
+
 		writestruct(wd, DATA, ScrArea, 1, area);
 
 #ifdef WITH_TOPBAR_WRITING
@@ -2905,6 +2907,8 @@ static void write_area_map(WriteData *wd, ScrAreaMap *area_map)
 #endif
 
 		write_area_regions(wd, area);
+
+		area->butspacetype = SPACE_EMPTY; /* Unset again, was changed above. */
 	}
 }
 
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 5d999677ba8..588a2abec53 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1481,10 +1481,10 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
 	sa->type = BKE_spacetype_from_id(sa->spacetype);
 	
 	if (sa->type == NULL) {
-		sa->butspacetype = sa->spacetype = SPACE_VIEW3D;
+		sa->spacetype = SPACE_VIEW3D;
 		sa->type = BKE_spacetype_from_id(sa->spacetype);
 	}
-	
+
 	for (ar = sa->regionbase.first; ar; ar = ar->next)
 		ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
 
@@ -1607,7 +1607,6 @@ void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free)
 	sa_dst->headertype = sa_src->headertype;
 	sa_dst->spacetype = sa_src->spacetype;
 	sa_dst->type = sa_src->type;
-	sa_dst->butspacetype = sa_src->butspacetype;
 
 	sa_dst->flag = (sa_dst->flag & ~flag_copy) | (sa_src->flag & flag_copy);
 
@@ -1638,7 +1637,6 @@ void ED_area_data_swap(ScrArea *sa_dst, ScrArea *sa_src)
 	SWAP(short, sa_dst->headertype, sa_src->headertype);
 	SWAP(char, sa_dst->spacetype, sa_src->spacetype);
 	SWAP(SpaceType *, sa_dst->type, sa_src->type);
-	SWAP(char, sa_dst->butspacetype, sa_src->butspacetype);
 
 
 	SWAP(ListBase, sa_dst->spacedata, sa_src->spacedata);
@@ -1677,8 +1675,9 @@ void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
  */
 void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exit)
 {
+	wmWindow *win = CTX_wm_window(C);
+
 	if (sa->spacetype != type) {
-		wmWindow *win = CTX_wm_window(C);
 		SpaceType *st;
 		SpaceLink *slold;
 		SpaceLink *sl;
@@ -1702,7 +1701,6 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
 		slold = sa->spacedata.first;
 
 		sa->spacetype = type;
-		sa->butspacetype = type;
 		sa->type = st;
 
 		/* If st->new may be called, don't use context until then. The
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index dba44909189..8db92855de6 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -179,7 +179,7 @@ static ScrArea *screen_addarea_ex(
 	sa->v3 = top_right;
 	sa->v4 = bottom_right;
 	sa->headertype = headertype;
-	sa->spacetype = sa->butspacetype = spacetype;
+	sa->spacetype = spacetype;
 
 	BLI_addtail(&area_map->areabase, sa);
 
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 6d4494ca2d2..1d0fbf36912 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -251,7 +251,11 @@ typedef struct ScrArea {
 
 	rcti totrct;			/* rect bound by v1 v2 v3 v4 */
 
-	char spacetype, butspacetype;	/* SPACE_..., butspacetype is button arg  */
+	char spacetype;     /* eSpace_Type (SPACE_FOO) */
+	/* Temporarily used while switching area type, otherwise this should be
+	 * SPACE_EMPTY. It's been there for ages, name doesn't fit any more. */
+	char butspacetype;  /* eSpace_Type (SPACE_FOO) */
+
 	short winx, winy;				/* size */
 
 	short headertype;				/* OLD! 0=no header, 1= down, 2= up */
diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c
index cc711673c85..83d8e730e3e 100644
--- a/source/blender/makesrna/intern/rna_screen.c
+++ b/source/blender/makesrna/intern/rna_screen.c
@@ -159,8 +159,9 @@ static const EnumPropertyItem *rna_Area_type_itemf(bContext *UNUSED(C), PointerR
 static int rna_Area_type_get(PointerRNA *ptr)
 {
 	ScrArea *sa = (ScrArea *)ptr->data;
-	/* read from this instead of 'spacetype' for correct reporting: T41435 */
-	return sa->butspacetype;
+	/* Usually 'spacetype' is used. It lags behind a bit while switching area
+	 * type though, then we use 'butspacetype' instead (T41435). */
+	return (sa->butspacetype == SPACE_EMPTY) ? sa->spacetype : sa->butspacetype;
 }
 
 static void rna_Area_type_set(PointerRNA *ptr, int value)
@@ -197,6 +198,9 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
 			ED_area_newspace(C, sa, sa->butspacetype, true);
 			ED_area_tag_redraw(sa);
 
+			/* Unset so that rna_Area_type_get uses spacetype instead. */
+			sa->butspacetype = SPACE_EMPTY;
+
 			/* It is possible that new layers becomes visible. */
 			if (sa->spacetype == SPACE_VIEW3D) {
 				DEG_on_visible_update(CTX_data_main(C), false);



More information about the Bf-blender-cvs mailing list