svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22717:22875
[blender.git] / source / blender / windowmanager / intern / wm_files.c
index 4c16a8572511bf17da57ce0a7d0a2cc7f39f6495..9c30c99bbdd29ede1a74e805030f170e72eb0302 100644 (file)
@@ -49,7 +49,8 @@
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
 
-#include "DNA_ipo_types.h"
+#include "DNA_anim_types.h"
+#include "DNA_ipo_types.h" // XXX old animation system
 #include "DNA_object_types.h"
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
 #include "BKE_main.h"
 #include "BKE_packedFile.h"
 #include "BKE_report.h"
+#include "BKE_sound.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
 
-#ifdef WITH_VERSE
-#include "BKE_verse.h"
-#endif
-
 #include "BLO_readfile.h"
 #include "BLO_writefile.h"
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
 #include "ED_datafiles.h"
+#include "ED_object.h"
 #include "ED_screen.h"
+#include "ED_util.h"
+
+#include "GHOST_C-api.h"
 
 #include "UI_interface.h"
 
+#include "GPU_draw.h"
+
 // XXX #include "BPY_extern.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 #include "wm.h"
+#include "wm_window.h"
 
-/***/
-
-/* define for setting colors in theme below */
-#define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
-
-/* patching UserDef struct and Themes */
-static void init_userdef_themes(void)
-{
-       // sets themes, fonts, .. from userdef
-       UI_init_userdef();
-       
-//     countall();
-       
-       /* the UserDef struct is not corrected with do_versions() .... ugh! */
-       if(U.wheellinescroll == 0) U.wheellinescroll = 3;
-       if(U.menuthreshold1==0) {
-               U.menuthreshold1= 5;
-               U.menuthreshold2= 2;
-       }
-       if(U.tb_leftmouse==0) {
-               U.tb_leftmouse= 5;
-               U.tb_rightmouse= 5;
-       }
-       if(U.mixbufsize==0) U.mixbufsize= 2048;
-       if (BLI_streq(U.tempdir, "/")) {
-               char *tmp= getenv("TEMP");
-               
-               strcpy(U.tempdir, tmp?tmp:"/tmp/");
-       }
-       if (U.savetime <= 0) {
-               U.savetime = 1;
-// XXX         error(".B.blend is buggy, please consider removing it.\n");
-       }
-       /* transform widget settings */
-       if(U.tw_hotspot==0) {
-               U.tw_hotspot= 14;
-               U.tw_size= 20;                  // percentage of window size
-               U.tw_handlesize= 16;    // percentage of widget radius
-       }
-       if(U.pad_rot_angle==0)
-               U.pad_rot_angle= 15;
-       
-       if(U.flag & USER_CUSTOM_RANGE) 
-               vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
-       
-       if (G.main->versionfile <= 191) {
-               strcpy(U.plugtexdir, U.textudir);
-               strcpy(U.sounddir, "/");
-       }
-       
-       /* patch to set Dupli Armature */
-       if (G.main->versionfile < 220) {
-               U.dupflag |= USER_DUP_ARM;
-       }
-       
-       /* userdef new option */
-       if (G.main->versionfile <= 222) {
-               U.vrmlflag= USER_VRML_LAYERS;
-       }
-       
-       /* added seam, normal color, undo */
-       if (G.main->versionfile <= 234) {
-               bTheme *btheme;
-               
-               U.uiflag |= USER_GLOBALUNDO;
-               if (U.undosteps==0) U.undosteps=32;
-               
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* check for alpha==0 is safe, then color was never set */
-                       if(btheme->tv3d.edge_seam[3]==0) {
-                               SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
-                       }
-                       if(btheme->tv3d.normal[3]==0) {
-                               SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
-                       }
-                       if(btheme->tv3d.face_dot[3]==0) {
-                               SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
-                               btheme->tv3d.facedot_size= 4;
-                       }
-               }
-       }
-       if (G.main->versionfile <= 235) {
-               /* illegal combo... */
-               if (U.flag & USER_LMOUSESELECT) 
-                       U.flag &= ~USER_TWOBUTTONMOUSE;
-       }
-       if (G.main->versionfile <= 236) {
-               bTheme *btheme;
-               /* new space type */
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* check for alpha==0 is safe, then color was never set */
-                       if(btheme->ttime.back[3]==0) {
-                               btheme->ttime = btheme->tsnd;   // copy from sound
-                       }
-                       if(btheme->text.syntaxn[3]==0) {
-                               SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
-                               SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
-                               SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
-                               SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
-                               SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
-                       }
-               }
-       }
-       if (G.main->versionfile <= 237) {
-               bTheme *btheme;
-               /* bone colors */
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* check for alpha==0 is safe, then color was never set */
-                       if(btheme->tv3d.bone_solid[3]==0) {
-                               SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
-                               SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
-                       }
-               }
-       }
-       if (G.main->versionfile <= 238) {
-               bTheme *btheme;
-               /* bone colors */
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* check for alpha==0 is safe, then color was never set */
-                       if(btheme->tnla.strip[3]==0) {
-                               SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
-                               SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
-                       }
-               }
-       }
-       if (G.main->versionfile <= 239) {
-               bTheme *btheme;
-               
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* Lamp theme, check for alpha==0 is safe, then color was never set */
-                       if(btheme->tv3d.lamp[3]==0) {
-                               SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
-/* TEMPORAL, remove me! (ton) */                               
-                               U.uiflag |= USER_PLAINMENUS;
-                       }
-                       
-                       /* check for text field selection highlight, set it to text editor highlight by default */
-                       if(btheme->tui.textfield_hi[3]==0) {
-                               SETCOL(btheme->tui.textfield_hi,        
-                                       btheme->text.shade2[0], 
-                                       btheme->text.shade2[1], 
-                                       btheme->text.shade2[2],
-                                       255);
-                       }
-               }
-               if(U.obcenter_dia==0) U.obcenter_dia= 6;
-       }
-       if (G.main->versionfile <= 241) {
-               bTheme *btheme;
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* Node editor theme, check for alpha==0 is safe, then color was never set */
-                       if(btheme->tnode.syntaxn[3]==0) {
-                               /* re-uses syntax color storage */
-                               btheme->tnode= btheme->tv3d;
-                               SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
-                               SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
-                               SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
-                               SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
-                               SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
-                               SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
-                       }
-                       /* Group theme colors */
-                       if(btheme->tv3d.group[3]==0) {
-                               SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
-                               SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
-                       }
-                       /* Sequence editor theme*/
-                       if(btheme->tseq.movie[3]==0) {
-                               SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
-                               SETCOL(btheme->tseq.image,      109, 88, 129, 255);
-                               SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
-                               SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
-                               SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
-                               SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
-                               SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
-                               SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
-                       }
-                       if(!(btheme->tui.iconfile)) {
-                               BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
-                       }
-               }
-               
-               /* set defaults for 3D View rotating axis indicator */ 
-               /* since size can't be set to 0, this indicates it's not saved in .B.blend */
-               if (U.rvisize == 0) {
-                       U.rvisize = 15;
-                       U.rvibright = 8;
-                       U.uiflag |= USER_SHOW_ROTVIEWICON;
-               }
-               
-       }
-       if (G.main->versionfile <= 242) {
-               bTheme *btheme;
-               
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* long keyframe color */
-                       /* check for alpha==0 is safe, then color was never set */
-                       if(btheme->tact.strip[3]==0) {
-                               SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
-                               SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 204);
-                               SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
-                       }
-                       
-                       /* IPO-Editor - Vertex Size*/
-                       if(btheme->tipo.vertex_size == 0) {
-                               btheme->tipo.vertex_size= 3;
-                       }
-               }
-       }
-       if (G.main->versionfile <= 243) {
-               /* set default number of recently-used files (if not set) */
-               if (U.recent_files == 0) U.recent_files = 10;
-       }
-       if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
-               bTheme *btheme;
-               for(btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
-               }
-               if(U.coba_weight.tot==0)
-                       init_colorband(&U.coba_weight, 1);
-       }
-       if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
-               bTheme *btheme;
-               for (btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* these should all use the same colour */
-                       SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
-                       SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
-                       SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
-                       SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
-                       SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
-                       SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
-                       SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
-               }
-       }
-       if ((G.main->versionfile < 248) || (G.main->versionfile == 248 && G.main->subversionfile < 3)) {
-               bTheme *btheme;
-               
-               /* adjust themes */
-               for (btheme= U.themes.first; btheme; btheme= btheme->next) {
-                       /* DopeSheet - (Object) Channel color */
-                       SETCOL(btheme->tact.ds_channel, 0x36, 0x13, 0xca, 255);
-                       SETCOL(btheme->tact.ds_subchannel, 0x60, 0x43, 0xd2, 255);
-               }
-               
-               /* adjust grease-pencil distances */
-               U.gp_manhattendist= 1;
-               U.gp_euclideandist= 2;
-               
-               /* adjust default interpolation for new IPO-curves */
-               U.ipo_new= IPO_BEZ;
-       }
-       
-       /* GL Texture Garbage Collection (variable abused above!) */
-       if (U.textimeout == 0) {
-               U.texcollectrate = 60;
-               U.textimeout = 120;
-       }
-       if (U.memcachelimit <= 0) {
-               U.memcachelimit = 32;
-       }
-       if (U.frameserverport == 0) {
-               U.frameserverport = 8080;
-       }
-
-       MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
-       
-       /* funny name, but it is GE stuff, moves userdef stuff to engine */
-// XXX space_set_commmandline_options();
-       /* this timer uses U */
-// XXX reset_autosave();
-
-#ifdef WITH_VERSE
-       if(strlen(U.versemaster)<1) {
-               strcpy(U.versemaster, "master.uni-verse.org");
-       }
-       if(strlen(U.verseuser)<1) {
-// XXX         char *name = verse_client_name();
-// XXX         strcpy(U.verseuser, name);
-// XXX         MEM_freeN(name);
-       }
-#endif
-
-}
 
 /* To be able to read files without windows closing, opening, moving 
    we try to prepare for worst case:
@@ -389,6 +114,9 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
        /* first wrap up running stuff */
        /* code copied from wm_init_exit.c */
        for(wm= wmlist->first; wm; wm= wm->id.next) {
+               
+               WM_jobs_stop_all(wm);
+               
                for(win= wm->windows.first; win; win= win->next) {
                
                        CTX_wm_window_set(C, win);      /* needed by operator close callbacks */
@@ -396,6 +124,8 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
                }
        }
        
+       ED_editors_exit(C);
+       
 return;        
        if(wm==NULL) return;
        if(G.fileflags & G_FILE_NO_UI) return;
@@ -415,8 +145,8 @@ return;
   2- no current wm, but read wm: that's OK, do nothing
   3- current wm, but not in file: try match screen names
   4- current wm, and wm in file: try match ghostwin 
-
 */
+
 static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
 {
        wmWindowManager *oldwm, *wm;
@@ -431,37 +161,57 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
        else {
                /* cases 3 and 4 */
                
-               /* we've read file without wm... */
+               /* we've read file without wm..., keep current one entirely alive */
                if(G.main->wm.first==NULL) {
+                       bScreen *screen= CTX_wm_screen(C);
+                       
                        /* match oldwm to new dbase, only old files */
                        
                        for(wm= oldwmlist->first; wm; wm= wm->id.next) {
+                               
                                for(win= wm->windows.first; win; win= win->next) {
-                                       win->screen= (bScreen *)find_id("SR", win->screenname);
-
-                                       if(win->screen==NULL)
-                                               win->screen= ED_screen_duplicate(win, CTX_wm_screen(C)); /* active screen */
-                                                       
-                                       if(win->screen->winid==0)
-                                               win->screen->winid= win->winid;
+                                       /* all windows get active screen from file */
+                                       if(screen->winid==0)
+                                               win->screen= screen;
+                                       else 
+                                               win->screen= ED_screen_duplicate(win, screen);
+                                       
+                                       BLI_strncpy(win->screenname, win->screen->id.name+2, 21);
+                                       win->screen->winid= win->winid;
                                }
                        }
-                       /* XXX still solve, case where multiple windows open */
                        
                        G.main->wm= *oldwmlist;
+                       
+                       /* screens were read from file! */
+                       ED_screens_initialize(G.main->wm.first);
                }
                else {
                        /* what if old was 3, and loaded 1? */
                        /* this code could move to setup_appdata */
                        oldwm= oldwmlist->first;
                        wm= G.main->wm.first;
+
+                       /* ensure making new keymaps and set space types */
+                       wm->initialized= 0;
+                       
                        /* only first wm in list has ghostwins */
                        for(win= wm->windows.first; win; win= win->next) {
                                for(oldwin= oldwm->windows.first; oldwin; oldwin= oldwin->next) {
                                        
                                        if(oldwin->winid == win->winid ) {
                                                win->ghostwin= oldwin->ghostwin;
+                                               GHOST_SetWindowUserData(win->ghostwin, win);    /* pointer back */
                                                oldwin->ghostwin= NULL;
+                                               
+                                               win->eventstate= oldwin->eventstate;
+                                               oldwin->eventstate= NULL;
+                                               
+                                               /* ensure proper screen rescaling */
+                                               win->sizex= oldwin->sizex;
+                                               win->sizey= oldwin->sizey;
+                                               win->posx= oldwin->posx;
+                                               win->posy= oldwin->posy;
                                        }
                                }
                        }
@@ -470,67 +220,41 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
        }
 }
 
-#ifdef WITH_VERSE
-static void verse_unsub(void)
+/* in case UserDef was read, we re-initialize all, and do versioning */
+static void wm_init_userdef()
 {
-       extern ListBase session_list;
-       struct VerseSession *session;
-       struct VNode *vnode;
-       
-       session = session_list.first;
-       while(session) {
-               vnode = session->nodes.lb.first;
-               while(vnode) {
-                       switch(vnode->type) {
-                               case V_NT_OBJECT:
-//XXX                                  unsubscribe_from_obj_node(vnode);
-                                       break;
-                               case V_NT_GEOMETRY:
-//XXX                                  unsubscribe_from_geom_node(vnode);
-                                       break;
-                               case V_NT_BITMAP:
-//XXX                                  unsubscribe_from_bitmap_node(vnode);
-                                       break;
-                       }
-                       vnode = vnode->next;
-               }
-               session = session->next;
-       }
+       UI_init_userdef();
+       MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
+       sound_init();
 }
-#endif
 
 void WM_read_file(bContext *C, char *name, ReportList *reports)
 {
        int retval;
 
-#ifdef WITH_VERSE
-       verse_unsub();          /* bad call here (ton) */
-#endif
-       
        /* first try to append data from exotic file formats... */
        /* it throws error box when file doesnt exist and returns -1 */
        /* note; it should set some error message somewhere... (ton) */
-       retval= BKE_read_exotic(name);
+       retval= BKE_read_exotic(CTX_data_scene(C), name);
        
        /* we didn't succeed, now try to read Blender file */
        if (retval== 0) {
                ListBase wmbase;
 
                /* put aside screens to match with persistant windows later */
+               /* also exit screens and editors */
                wm_window_match_init(C, &wmbase); 
                
                retval= BKE_read_file(C, name, NULL, reports);
+               G.save_over = 1;
 
                /* match the read WM with current WM */
                wm_window_match_do(C, &wmbase); 
+               wm_check(C); /* opens window(s), checks keymaps */
                
 // XXX         mainwindow_set_filename_to_title(G.main->name);
-//             countall(); <-- will be listener
-// XXX         sound_initialize_sounds();
 
-//             winqueue_break= 1;      /* leave queues everywhere */
-
-// XXX         if(retval==2) init_userdef_themes();    // in case a userdef is read from regular .blend
+               if(retval==2) wm_init_userdef();        // in case a userdef is read from regular .blend
                
                if (retval!=0) G.relbase_valid = 1;
 
@@ -538,52 +262,39 @@ void WM_read_file(bContext *C, char *name, ReportList *reports)
                BKE_reset_undo();
                BKE_write_undo(C, "original");  /* save current state */
 
+               WM_event_add_notifier(C, NC_WM|ND_FILEREAD, NULL);
 //             refresh_interface_font();
+                                          
+               CTX_wm_window_set(C, NULL); /* exits queues */
        }
-//     else if(retval==1)
-// XXX         BIF_undo_push("Import file");
+       else if(retval==1)
+               BKE_write_undo(C, "Import file");
        else if(retval == -1) {
                if(reports && reports->list.first == NULL)
                        BKE_report(reports, RPT_ERROR, "Cannot read file.");
        }
 }
 
-static void outliner_242_patch(void)
-{
-       ScrArea *sa;
-       
-// XXX 
-       if(G.curscreen==NULL) return;
-       for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceLink *sl= sa->spacedata.first;
-               for(; sl; sl= sl->next) {
-                       if(sl->spacetype==SPACE_OOPS) {
-                               SpaceOops *soops= (SpaceOops *)sl;
-                               if(soops->type!=SO_OUTLINER) {
-                                       soops->type= SO_OUTLINER;
-// XXX                                 init_v2d_oops(sa, soops);
-                               }
-                       }
-               }
-       }
-       G.fileflags |= G_FILE_GAME_MAT;
-}
 
 /* called on startup,  (context entirely filled with NULLs) */
 /* or called for 'Erase All' */
-int WM_read_homefile(bContext *C, int from_memory)
+/* op can be NULL */
+int WM_read_homefile(bContext *C, wmOperator *op)
 {
        ListBase wmbase;
        char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR];
        char *home= BLI_gethome();
+       int from_memory= op?RNA_boolean_get(op->ptr, "factory"):0;
        int success;
-       
+               
        BLI_clean(home);
        
        free_ttfont(); /* still weird... what does it here? */
                
        G.relbase_valid = 0;
-       if (!from_memory) BLI_make_file_string(G.sce, tstr, home, ".B.blend");
+       if (!from_memory) {
+               BLI_make_file_string(G.sce, tstr, home, ".B25.blend");
+       }
        strcpy(scestr, G.sce);  /* temporary store */
        
        /* prevent loading no UI */
@@ -596,25 +307,24 @@ int WM_read_homefile(bContext *C, int from_memory)
                success = BKE_read_file(C, tstr, NULL, NULL);
        } else {
                success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL, NULL);
-               /* outliner patch for 2.42 .b.blend */
-               outliner_242_patch();
+               if (wmbase.first == NULL) wm_clear_default_size(C);
        }
        
        /* match the read WM with current WM */
        wm_window_match_do(C, &wmbase); 
-       
-       strcpy(G.sce, scestr); /* restore */
+       wm_check(C); /* opens window(s), checks keymaps */
 
-       init_userdef_themes();
+       strcpy(G.sce, scestr); /* restore */
+       
+       wm_init_userdef();
+       
+       /* When loading factory settings, the reset solid OpenGL lights need to be applied. */
+       GPU_default_lights();
        
        /* XXX */
        G.save_over = 0;        // start with save preference untitled.blend
        G.fileflags &= ~G_FILE_AUTOPLAY;        /*  disable autoplay in .B.blend... */
 //     mainwindow_set_filename_to_title("");   // empty string re-initializes title to "Blender"
-
-#ifdef INTERNATIONAL
-// XXX read_languagefile();
-#endif
        
 //     refresh_interface_font();
        
@@ -622,7 +332,10 @@ int WM_read_homefile(bContext *C, int from_memory)
        BKE_reset_undo();
        BKE_write_undo(C, "original");  /* save current state */
        
-       return success;
+       WM_event_add_notifier(C, NC_WM|ND_FILEREAD, NULL);
+       CTX_wm_window_set(C, NULL); /* exits queues */
+
+       return OPERATOR_FINISHED;
 }
 
 
@@ -826,7 +539,7 @@ static void do_history(char *name, ReportList *reports)
                BKE_report(reports, RPT_ERROR, "Unable to make version backup");
 }
 
-void WM_write_file(bContext *C, char *target, ReportList *reports)
+void WM_write_file(bContext *C, char *target, int compress, ReportList *reports)
 {
        Library *li;
        int writeflags, len;
@@ -841,8 +554,6 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
        }
  
        /* send the OnSave event */
-// XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&CTX_data_scene(C)->id, SCRIPT_ONSAVE);
-
        for (li= G.main->library.first; li; li= li->id.next) {
                if (BLI_streq(li->name, target)) {
                        BKE_report(reports, RPT_ERROR, "Cannot overwrite used library");
@@ -856,36 +567,35 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
                strcpy(di, target);
        }
 
-       if (BLI_exists(di)) {
+//     if (BLI_exists(di)) {
 // XXX         if(!saveover(di))
 // XXX                 return; 
-       }
+//     }
        
-       if(G.obedit) {
-// XXX         exit_editmode(0);       /* 0 = no free data */
-       }
        if (G.fileflags & G_AUTOPACK) {
-               packAll();
+               packAll(G.main, reports);
        }
        
-// XXX waitcursor(1);  // exit_editmode sets cursor too
+       ED_object_exit_editmode(C, 0);
 
        do_history(di, reports);
        
-       /* we use the UserDef to define compression flag */
-       writeflags= G.fileflags & ~G_FILE_COMPRESS;
-       if(U.flag & USER_FILECOMPRESS)
-               writeflags |= G_FILE_COMPRESS;
+       writeflags= G.fileflags;
+
+       /* set compression flag */
+       if(compress) writeflags |= G_FILE_COMPRESS;
+       else writeflags &= ~G_FILE_COMPRESS;
        
        if (BLO_write_file(CTX_data_main(C), di, writeflags, reports)) {
                strcpy(G.sce, di);
                G.relbase_valid = 1;
                strcpy(G.main->name, di);       /* is guaranteed current file */
 
-// XXX         mainwindow_set_filename_to_title(G.main->name);
-
-               G.save_over = 1;
+               G.save_over = 1; /* disable untitled.blend convention */
 
+               if(compress) G.fileflags |= G_FILE_COMPRESS;
+               else G.fileflags &= ~G_FILE_COMPRESS;
+               
                writeBlog();
        }
 
@@ -895,16 +605,24 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
 /* operator entry */
 int WM_write_homefile(bContext *C, wmOperator *op)
 {
+       wmWindow *win= CTX_wm_window(C);
        char tstr[FILE_MAXDIR+FILE_MAXFILE];
        int write_flags;
        
-       BLI_make_file_string("/", tstr, "/", ".B.blend");
-               
+       /* check current window and close it if temp */
+       if(win->screen->full == SCREENTEMP) {
+               wm_window_close(C, win);
+       }
+       
+       BLI_make_file_string("/", tstr, BLI_gethome(), ".B25.blend");
+       
        /*  force save as regular blend file */
        write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
 
        BLO_write_file(CTX_data_main(C), tstr, write_flags, op->reports);
        
+       G.save_over= 0;
+       
        return OPERATOR_FINISHED;
 }