2.5 filebrowser
authorAndrea Weikert <elubie@gmx.net>
Tue, 6 Jan 2009 22:48:58 +0000 (22:48 +0000)
committerAndrea Weikert <elubie@gmx.net>
Tue, 6 Jan 2009 22:48:58 +0000 (22:48 +0000)
fixes for crashes that seem to have been introduced by changes in context handling.
TODO: initialization for windowtype pupmenu if a previous SpaceFile was there.

source/blender/blenloader/intern/readfile.c
source/blender/editors/include/ED_fileselect.h
source/blender/editors/space_file/filelist.c
source/blender/editors/space_file/filesel.c
source/blender/editors/space_file/space_file.c
source/blender/windowmanager/intern/wm_operators.c

index d5d86f72ab55228aa3ed8e1864d74ec36e818fca..24dc69c50bf53ffd93226babc227cc6970f208b2 100644 (file)
@@ -3956,7 +3956,7 @@ static void lib_link_screen(FileData *fd, Main *main)
                                        }
                                        else if(sl->spacetype==SPACE_FILE) {
                                                SpaceFile *sfile= (SpaceFile *)sl;
-
+                                               sfile->files= NULL;
                                                sfile->params= NULL;
                                                sfile->op= NULL;
                                                /* sfile->returnfunc= NULL; 
@@ -4160,8 +4160,9 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                else if(sl->spacetype==SPACE_FILE) {
                                        
                                        SpaceFile *sfile= (SpaceFile *)sl;
-                                       sfile->params = NULL;
-                                       sfile->op = NULL;
+                                       sfile->files= NULL;
+                                       sfile->params= NULL;
+                                       sfile->op= NULL;
                                        /* XXX needs checking - best solve in filesel itself 
                                        if(sfile->libfiledata)  
                                                BLO_blendhandle_close(sfile->libfiledata);
@@ -5212,11 +5213,17 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
                                break;
                        case SPACE_FILE:
+                               /* channel (bookmarks/directories) region */
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                                BLI_addtail(lb, ar);
                                ar->regiontype= RGN_TYPE_CHANNELS;
                                ar->alignment= RGN_ALIGN_LEFT;
                                ar->v2d.scroll= V2D_SCROLL_RIGHT;
+                               /* button UI region */
+                               ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_UI;
+                               ar->alignment= RGN_ALIGN_TOP;
                                break;
                }
        }
index 05307848088e7efc69d708b3b6ea6d135623552e..c62990a69d9c84512074b628af5987fafc5f89fc 100644 (file)
@@ -55,7 +55,7 @@ typedef struct FileSelectParams {
 
 FileSelectParams* ED_fileselect_get_params(const struct bContext *C);
 
-short ED_fileselect_set_params(const struct bContext *C, int type, const char *title, const char *path, 
+short ED_fileselect_set_params(FileSelectParams *params, int type, const char *title, const char *path, 
                                                   short flag, short display, short filter);
 
 #endif /* ED_FILES_H */
index f03ea8d9456b49d5d78f585824f3a19c0cfeedfe..e0603a4e038bcf8b045f6cccbeb02c3b0a2e77de 100644 (file)
@@ -49,6 +49,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
 #include "BLI_storage_types.h"
+#include "BLI_threads.h"
 
 #ifdef WIN32
 #include "BLI_winstuff.h"
@@ -106,8 +107,16 @@ typedef struct FileList
        short prv_h;
        short hide_dot;
        unsigned int filter;
+       struct ThreadedWorker *worker;
+       LinkNode *worklist;
 } FileList;
 
+typedef struct WorkItem
+{
+       FileList* files;
+       int item;
+} WorkItem;
+
 int BIF_groupname_to_code(char *group)
 {
        char buf[32];
@@ -367,6 +376,7 @@ struct FileList*    filelist_new()
        p->type = 0;
        p->has_func = 0;
        p->filter = 0;
+       p->worker = 0; // BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep_time);
        return p;
 }
 
index 404fddd9d4853ae0bdf0aa3460034bfc193e2831..d1cfdb07c39fa6bb893ebd1226e0db16449c9981 100644 (file)
 #include "filelist.h"
 
 
-FileSelectParams* ED_fileselect_get_params(const struct bContext *C)
-{
-       SpaceLink *sl= CTX_wm_space_data(C);
-       SpaceFile *sfile;
-       FileSelectParams *params = 0;
-
-       if (sl->spacetype == SPACE_FILE) {
-               sfile= (SpaceFile*)sl;
-               params = sfile->params;
-       }
-       return params;
-}
-
-short ED_fileselect_set_params(const struct bContext *C, int type, const char *title, const char *path,
+short ED_fileselect_set_params(FileSelectParams *params, int type, const char *title, const char *path,
                                                           short flag, short display, short filter)
 {
        char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
-       SpaceLink *sl= CTX_wm_space_data(C);
-       SpaceFile *sfile;
-       FileSelectParams *params;
 
-       if (sl->spacetype != SPACE_FILE) {
+       if (!params) {
                return 0;
        }
-       sfile= (SpaceFile*)sl;
-
-       if (!sfile->params) {
-               sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams");
-       }
-       params = sfile->params;
 
        params->type = type;
        params->flag = flag;
@@ -129,17 +107,7 @@ short ED_fileselect_set_params(const struct bContext *C, int type, const char *t
                                BLI_split_dirfile(name, dir, file);
                                BLI_strncpy(params->file, file, sizeof(params->file));
                                BLI_strncpy(params->dir, dir, sizeof(params->dir));
-                               BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
-                               
-                               filelist_settype(sfile->files, type);
-                               filelist_setdir(sfile->files, params->dir);
-                               BLI_cleanup_dir(G.sce, params->dir); /* XXX solve G.sce */
-
-                               /* free: filelist and libfiledata became incorrect */
-                               if (sfile->files) {
-                                       filelist_free(sfile->files);
-                                       filelist_freelib(sfile->files);
-                               }                               
+                               BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */                        
                        }
                        break;
        }
index ab3554261d335014584eccffc7f3ae232bef4a2b..703d351af2b6a00b87497f48b39cd0f0267958f4 100644 (file)
@@ -78,7 +78,7 @@ static SpaceLink *file_new(const bContext *C)
        sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
        sfile->files = filelist_new();
        
-       ED_fileselect_set_params(C, FILE_UNIX, "", "/", 0, 0, 0);
+       ED_fileselect_set_params(sfile->params, FILE_UNIX, "", "/", 0, 0, 0);
        filelist_setdir(sfile->files, sfile->params->dir);
        filelist_settype(sfile->files, sfile->params->type);
 
@@ -141,6 +141,17 @@ static void file_free(SpaceLink *sl)
 /* spacetype; init callback */
 static void file_init(struct wmWindowManager *wm, ScrArea *sa)
 {
+       SpaceFile *sfile= sa->spacedata.first;  /* XXX get through context? */
+       if (!sfile->params) {
+               sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
+               ED_fileselect_set_params(sfile->params, FILE_UNIX, "", "/", 0, 0, 0);
+       }
+       if (!sfile->files) {
+               sfile->files = filelist_new();
+       }
+       
+       filelist_setdir(sfile->files, sfile->params->dir);
+       filelist_settype(sfile->files, sfile->params->type);
 }
 
 static SpaceLink *file_duplicate(SpaceLink *sl)
@@ -152,7 +163,11 @@ static SpaceLink *file_duplicate(SpaceLink *sl)
        sfilen->op = NULL; // XXX check if operator can be duplicated
 
        sfilen->params= MEM_dupallocN(sfileo->params);
-       sfilen->params->pupmenu = NULL;
+       if (!sfilen->params) {
+               sfilen->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
+               ED_fileselect_set_params(sfilen->params, FILE_UNIX, "", "/", 0, 0, 0);
+               sfilen->params->pupmenu = NULL;
+       }
        sfilen->files = filelist_new();
        filelist_setdir(sfilen->files, sfilen->params->dir);
        filelist_settype(sfilen->files, sfilen->params->type);
@@ -177,7 +192,7 @@ static void file_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params = ED_fileselect_get_params(C);
+       FileSelectParams* params = sfile->params;
        View2D *v2d= &ar->v2d;
        View2DScrollers *scrollers;
        float col[3];
index 84b2a399392316f9328a5d6dc9712f47d0b136d7..f79b5a2955d3ac83cdd221c87725e45968ecf15a 100644 (file)
@@ -336,7 +336,7 @@ static int wm_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
        sfile= (SpaceFile*)CTX_wm_space_data(C);
        sfile->op = op;
 
-       ED_fileselect_set_params(C, FILE_BLENDER, "Load", "C:\\", 0, 0, 0);
+       ED_fileselect_set_params(sfile->params, FILE_BLENDER, "Load", "C:\\", 0, 0, 0);
 
        /* screen, areas init */
        WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);