2.5
[blender.git] / source / blender / editors / screen / space.c
index 85e41c1c1c26b2d248dc80d3492410e98f7d0a51..e9287c9976fa426085db6b4614549b8dc66f8726 100644 (file)
@@ -38,7 +38,7 @@
 #include "BLI_arithb.h"
 
 #include "BKE_global.h"
-#include "BKE_colortools.h"
+#include "BKE_screen.h"
 
 #include "BLO_readfile.h"
 
 #include "ED_area.h"
 #include "ED_screen.h"
 
+/* */
+
+void ED_newspace(ScrArea *sa, int type)
+{
+       if(sa->spacetype != type) {
+               SpaceType *st= BKE_spacetype_from_id(type);
+               SpaceLink *slold= sa->spacedata.first;
+               SpaceLink *sl;
+               
+               sa->spacetype= type;
+               sa->butspacetype= type;
+               
+               /* check previously stored space */
+               for (sl= sa->spacedata.first; sl; sl= sl->next)
+                       if(sl->spacetype==type)
+                               break;
+               
+               /* old spacedata... happened during work on 2.50, remove */
+               if(sl && sl->regionbase.first==NULL) {
+                       st->free(sl);
+                       MEM_freeN(sl);
+                       sl= NULL;
+               }
+               
+               if (sl) {
+                       
+                       /* swap regions */
+                       slold->regionbase= sa->regionbase;
+                       sa->regionbase= sl->regionbase;
+                       sl->regionbase.first= sl->regionbase.last= NULL;
+                       
+                       /* put in front of list */
+                       BLI_remlink(&sa->spacedata, sl);
+                       BLI_addhead(&sa->spacedata, sl);
+               } 
+               else {
+                       /* new space */
+                       if(st) {
+                               sl= st->new();
+                               BLI_addhead(&sa->spacedata, sl);
+                               
+                               /* swap regions */
+                               slold->regionbase= sa->regionbase;
+                               sa->regionbase= sl->regionbase;
+                               sl->regionbase.first= sl->regionbase.last= NULL;
+                       }
+               }
+       }
+       
+}
+
+