2.5 filebrowser
authorAndrea Weikert <elubie@gmx.net>
Thu, 8 Jan 2009 18:47:16 +0000 (18:47 +0000)
committerAndrea Weikert <elubie@gmx.net>
Thu, 8 Jan 2009 18:47:16 +0000 (18:47 +0000)
cleanup of space initialisation
fix for filebrowser opening with wrong parameters from window pupmenu after having been opened with F1.

source/blender/editors/include/ED_fileselect.h
source/blender/editors/space_file/file_draw.c
source/blender/editors/space_file/file_header.c
source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/filesel.c
source/blender/editors/space_file/space_file.c
source/blender/windowmanager/intern/wm_operators.c

index c62990a..c0efaab 100644 (file)
@@ -28,6 +28,8 @@
 #ifndef ED_FILES_H
 #define ED_FILES_H
 
+struct SpaceFile;
+
 typedef struct FileSelectParams {
        int type; /* the mode of the filebrowser, FILE_BLENDER, FILE_SPECIAL, FILE_MAIN or FILE_LOADLIB */
        char title[24]; /* title, also used for the text of the execute button */
@@ -53,10 +55,12 @@ typedef struct FileSelectParams {
        /* XXX --- end unused -- */
 } FileSelectParams;
 
-FileSelectParams* ED_fileselect_get_params(const struct bContext *C);
+FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile);
 
-short ED_fileselect_set_params(FileSelectParams *params, int type, const char *title, const char *path, 
+short ED_fileselect_set_params(struct SpaceFile *sfile, int type, const char *title, const char *path, 
                                                   short flag, short display, short filter);
 
+void ED_fileselect_reset_params(struct SpaceFile *sfile);
+
 #endif /* ED_FILES_H */
 
index 78e4116..c45993d 100644 (file)
@@ -128,7 +128,7 @@ static void do_file_buttons(bContext *C, void *arg, int event)
 void file_draw_buttons(const bContext *C, ARegion *ar)
 {
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params = sfile->params;
+       FileSelectParams* params = ED_fileselect_get_params(sfile);
        uiBlock *block;
        int loadbutton;
        char name[20];
@@ -277,7 +277,7 @@ static int file_view_columns(SpaceFile* sfile, View2D *v2d)
 void file_calc_previews(const bContext *C, ARegion *ar)
 {
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params = sfile->params;
+       FileSelectParams* params = ED_fileselect_get_params(sfile);
        View2D *v2d= &ar->v2d;
        int width=0, height=0;
        int rows, columns;
@@ -316,7 +316,7 @@ void file_calc_previews(const bContext *C, ARegion *ar)
 void file_draw_previews(const bContext *C, ARegion *ar)
 {
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params=sfile->params;
+       FileSelectParams* params= ED_fileselect_get_params(sfile);
        View2D *v2d= &ar->v2d;
        static double lasttime= 0;
        struct FileList* files = sfile->files;
@@ -471,7 +471,7 @@ void file_draw_previews(const bContext *C, ARegion *ar)
 void file_draw_list(const bContext *C, ARegion *ar)
 {
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params = sfile->params;
+       FileSelectParams* params = ED_fileselect_get_params(sfile);
        struct FileList* files = sfile->files;
        struct direntry *file;
        int numfiles;
@@ -558,7 +558,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
 void file_draw_fsmenu(const bContext *C, ARegion *ar)
 {
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params = sfile->params;
+       FileSelectParams* params = ED_fileselect_get_params(sfile);
        char bookmark[FILE_MAX];
        int nentries = fsmenu_get_nentries();
        int linestep = U.fontsize*3/2;
index 2aeb8ed..cbe36f2 100644 (file)
@@ -117,7 +117,7 @@ void file_header_buttons(const bContext *C, ARegion *ar)
 {
        ScrArea *sa= CTX_wm_area(C);
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
-       FileSelectParams* params = sfile->params;
+       FileSelectParams* params = ED_fileselect_get_params(sfile);
 
        uiBlock *block;
        int xco, yco= 3;
index d9e831c..49014a6 100644 (file)
@@ -116,7 +116,7 @@ static void set_active_file(SpaceFile *sfile, FileSelectParams* params, struct A
 }
 
 
-static void set_active_bookmark(SpaceFile *sfile, FileSelectParams* params, struct ARegion* ar, short y)
+static void set_active_bookmark(FileSelectParams* params, struct ARegion* ar, short y)
 {
        int nentries = fsmenu_get_nentries();
        short posy = ar->v2d.mask.ymax - TILE_BORDER_Y - y;
@@ -187,7 +187,7 @@ static void mouse_select_bookmark(SpaceFile* sfile, ARegion* ar, short *mval)
        if(mval[0]>ar->v2d.mask.xmin && mval[0]<ar->v2d.mask.xmax
        && mval[1]>ar->v2d.mask.ymin && mval[1]<ar->v2d.mask.ymax) {
                char *selected;
-               set_active_bookmark(sfile, sfile->params, ar, mval[1]);
+               set_active_bookmark(sfile->params, ar, mval[1]);
                selected= fsmenu_get_entry(sfile->params->active_bookmark);                     
                /* which string */
                if (selected) {
index d1cfdb0..f2eb7ad 100644 (file)
 #include "filelist.h"
 
 
-short ED_fileselect_set_params(FileSelectParams *params, int type, const char *title, const char *path,
+FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
+{
+       if (!sfile->params) {
+               ED_fileselect_set_params(sfile, FILE_UNIX, "", "/", 0, 0, 0);
+       }
+       return sfile->params;
+}
+
+short ED_fileselect_set_params(SpaceFile *sfile, int type, const char *title, const char *path,
                                                           short flag, short display, short filter)
 {
        char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
+       FileSelectParams *params;
 
-       if (!params) {
-               return 0;
+       if (!sfile->params) {
+               sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
        }
 
+       params = sfile->params;
+
        params->type = type;
        params->flag = flag;
        params->display = display;
@@ -115,3 +126,9 @@ short ED_fileselect_set_params(FileSelectParams *params, int type, const char *t
        return 1;
 }
 
+void ED_fileselect_reset_params(SpaceFile *sfile)
+{
+       sfile->params->type = FILE_UNIX;
+       sfile->params->flag = 0;
+       sfile->params->title[0] = '\0';
+}
index 703d351..aa364bf 100644 (file)
@@ -74,13 +74,7 @@ static SpaceLink *file_new(const bContext *C)
        SpaceFile *sfile;
        
        sfile= MEM_callocN(sizeof(SpaceFile), "initfile");
-       sfile->spacetype= SPACE_FILE;   
-       sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
-       sfile->files = filelist_new();
-       
-       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);
+       sfile->spacetype= SPACE_FILE;
 
        /* header */
        ar= MEM_callocN(sizeof(ARegion), "header for file");
@@ -122,14 +116,14 @@ static void file_free(SpaceLink *sl)
                filelist_free(sfile->files);
                filelist_freelib(sfile->files);
                MEM_freeN(sfile->files);
-               sfile->files = 0;
+               sfile->files= NULL;
        }
 
        if (sfile->params) {
                if(sfile->params->pupmenu)
                        MEM_freeN(sfile->params->pupmenu);
                MEM_freeN(sfile->params);
-               sfile->params = 0;
+               sfile->params= NULL;
        }
        
        if (sfile->op) {
@@ -142,16 +136,15 @@ static void file_free(SpaceLink *sl)
 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->params) {
+               ED_fileselect_reset_params(sfile);
        }
-       if (!sfile->files) {
-               sfile->files = filelist_new();
+       if (sfile->files) {
+               filelist_free(sfile->files);
+               filelist_freelib(sfile->files);
+               MEM_freeN(sfile->files);
+               sfile->files= NULL;
        }
-       
-       filelist_setdir(sfile->files, sfile->params->dir);
-       filelist_settype(sfile->files, sfile->params->type);
 }
 
 static SpaceLink *file_duplicate(SpaceLink *sl)
@@ -165,9 +158,10 @@ static SpaceLink *file_duplicate(SpaceLink *sl)
        sfilen->params= MEM_dupallocN(sfileo->params);
        if (!sfilen->params) {
                sfilen->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
-               ED_fileselect_set_params(sfilen->params, FILE_UNIX, "", "/", 0, 0, 0);
+               ED_fileselect_set_params(sfilen, 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);
index afd6665..92a233d 100644 (file)
@@ -335,12 +335,10 @@ static int wm_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
        /* settings for filebrowser */
        sfile= (SpaceFile*)CTX_wm_space_data(C);
        sfile->op = op;
+       ED_fileselect_set_params(sfile, FILE_BLENDER, "Load", "C:\\", 0, 0, 0);
 
-       ED_fileselect_set_params(sfile->params, FILE_BLENDER, "Load", "C:\\", 0, 0, 0);
+       /* screen and area have been reset already in ED_screen_full_newspace */
 
-       /* screen, areas init */
-       WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
-       
        return OPERATOR_RUNNING_MODAL;
 }