2.5 file browser
authorAndrea Weikert <elubie@gmx.net>
Mon, 27 Jul 2009 19:06:33 +0000 (19:06 +0000)
committerAndrea Weikert <elubie@gmx.net>
Mon, 27 Jul 2009 19:06:33 +0000 (19:06 +0000)
New:
* added filter and display to some operator properties. Now file browser opens showing only .blend files and folders on file->open and on image->open changes to image display and only shows images and movies.
Fixes:
* fixed stupid removal of wrong prototype in last commit
* fixed a few warnings

source/blender/editors/include/ED_fileselect.h
source/blender/editors/space_file/file_panels.c
source/blender/editors/space_file/filelist.c
source/blender/editors/space_file/filelist.h
source/blender/editors/space_file/filesel.c
source/blender/editors/space_file/fsmenu.c
source/blender/editors/space_file/space_file.c
source/blender/editors/space_image/image_ops.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index 5cd789d4875610ad44a9e375c188951aa421e67e..c56807ad09abb5a8eb04a708bb2eadff185e3f80 100644 (file)
@@ -70,8 +70,7 @@ typedef struct FileLayout
 
 struct FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile);
 
-short ED_fileselect_set_params(struct SpaceFile *sfile, const char *title, const char *dir, const char *path, 
-                                                  short flag, short display, short filter, short sort);
+short ED_fileselect_set_params(struct SpaceFile *sfile);
 
 void ED_fileselect_reset_params(struct SpaceFile *sfile);
 
index 96366b9f82b4b6d5ca06375ff9013a5b87cecc89..351d1619508beff51204a7217eac9a4b4cd7e743 100644 (file)
@@ -121,7 +121,10 @@ static void file_panel_operator(const bContext *C, Panel *pa)
                                continue;
                        if(strcmp(RNA_property_identifier(prop), "filename") == 0)
                                continue;
-
+                       if(strcmp(RNA_property_identifier(prop), "display") == 0)
+                               continue;
+                       if(strncmp(RNA_property_identifier(prop), "filter", 6) == 0)
+                               continue;
                        uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0);
                }
                RNA_STRUCT_END;
index 60a37aac9bd7ee1cd2a2a4d1ff887978a570b423..7ebc8c4338faa0a14b88651ce32f72f84f639530 100644 (file)
@@ -903,9 +903,6 @@ void filelist_swapselect(struct FileList* filelist)
 
 void filelist_sort(struct FileList* filelist, short sort)
 {
-       struct direntry *file;
-       int num;/*  , act= 0; */
-
        switch(sort) {
        case FILE_SORT_ALPHA:
                qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_name);   
index 785e40d145ce1df7ad5dc04b590c71596f32c95d..dd3c2c766c181b4cbb424cb2716e180fb22af1c0 100644 (file)
@@ -54,7 +54,7 @@ void                          filelist_sort(struct FileList* filelist, short sort);
 int                                    filelist_numfiles(struct FileList* filelist);
 const char *           filelist_dir(struct FileList* filelist);
 void                           filelist_setdir(struct FileList* filelist, const char *dir);
-void                           filelist_end_edit(struct FileList* filelist, int index);
+struct direntry *      filelist_file(struct FileList* filelist, int index);
 void                           filelist_hidedot(struct FileList* filelist, short hide);
 void                           filelist_setfilter(struct FileList* filelist, unsigned int filter);
 void                           filelist_filter(struct FileList* filelist);
index bd271c6fb4bec9c72f4562f32afe9ffe16a34ffa..6263f9fe57f33ad3b930aab9455742b384660c8b 100644 (file)
@@ -73,6 +73,8 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "RNA_access.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 #include "UI_view2d.h"
@@ -95,41 +97,60 @@ static int fnmatch(const char *pattern, const char *string, int flags)
 FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
 {
        if (!sfile->params) {
-               ED_fileselect_set_params(sfile, "", NULL, "/", 0, FILE_SHORTDISPLAY, 0, FILE_SORT_ALPHA);
+               ED_fileselect_set_params(sfile);
        }
        return sfile->params;
 }
 
-short ED_fileselect_set_params(SpaceFile *sfile, const char *title, const char *last_dir, const char *path,
-                                                          short flag, short display, short filter, short sort)
+short ED_fileselect_set_params(SpaceFile *sfile)
 {
        char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
        FileSelectParams *params;
+       wmOperator *op = sfile->op;
 
+       /* create new parameters if necessary */
        if (!sfile->params) {
                sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
+               /* set path to most recently opened .blend */
+               BLI_strncpy(sfile->params->dir, G.sce, sizeof(sfile->params->dir));
+               BLI_split_dirfile(G.sce, dir, file);
+               BLI_strncpy(sfile->params->file, file, sizeof(sfile->params->file));
+               BLI_make_file_string(G.sce, sfile->params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
        }
 
        params = sfile->params;
 
-       params->flag = flag;
-       params->display = display;
-       params->filter = filter;
-       params->sort = sort;
-
-       BLI_strncpy(params->title, title, sizeof(params->title));
-
-       if(last_dir){
-               BLI_strncpy(params->dir, last_dir, sizeof(params->dir));
-       }
-       else {
-               BLI_strncpy(name, path, sizeof(name));
-               BLI_convertstringcode(name, G.sce);
-
-               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 */                        
+       /* set the parameters from the operator, if it exists */
+       if (op) {
+               BLI_strncpy(params->title, op->type->name, sizeof(params->title));
+               params->filter = 0;
+               params->filter |= RNA_boolean_get(op->ptr, "filter_folder") ? FOLDERFILE : 0;
+               params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0;
+               params->filter |= RNA_boolean_get(op->ptr, "filter_image") ? IMAGEFILE : 0;
+               params->filter |= RNA_boolean_get(op->ptr, "filter_movie") ? MOVIEFILE : 0;
+               if (params->filter != 0)
+                       params->flag |= FILE_FILTER;
+               
+               if (RNA_property_is_set(op->ptr, "display")) {
+                       params->display= RNA_int_get(op->ptr, "display");
+               } else {
+                       params->display = FILE_SHORTDISPLAY;
+               }
+               
+               /* if operator has path set, use it, otherwise keep the last */
+               if (RNA_property_is_set(op->ptr, "filename")) {
+                       RNA_string_get(op->ptr, "filename", name);
+                       BLI_convertstringcode(name, G.sce);
+                       BLI_split_dirfile(name, dir, file);
+                       BLI_strncpy(params->file, file, sizeof(params->file));
+                       BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */                
+               }
+       } else {
+               /* default values, if no operator */
+               params->flag = 0;
+               params->display = FILE_SHORTDISPLAY;
+               params->filter = 0;
+               params->sort = FILE_SORT_ALPHA;
        }
 
        return 1;
@@ -144,7 +165,6 @@ void ED_fileselect_reset_params(SpaceFile *sfile)
 int ED_fileselect_layout_numfiles(FileLayout* layout, struct ARegion *ar)
 {
        int numfiles;
-       short width, height;
 
        if (layout->flag & FILE_LAYOUT_HOR) {
                short width = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*layout->tile_border_x;
index a87ad4c4fd8091ce02bb56ac281d5ce560e1bfd7..c67a9e7a0d56974f4e61dee468845697049b514f 100644 (file)
@@ -310,7 +310,9 @@ void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename)
                                if (line[len-1] == '\n') {
                                        line[len-1] = '\0';
                                }
-                               fsmenu_insert_entry(fsmenu, category, line, 0, 1);
+                               if (BLI_exist(line)) {
+                                       fsmenu_insert_entry(fsmenu, category, line, 0, 1);
+                               }
                        }
                }
        }
index fdc3a927c5e6aaf3d4529c3847429a3932cfa4bd..a03026d018433c85546d3ef8ebf80b98cb7115cf 100644 (file)
@@ -195,11 +195,11 @@ static void file_refresh(const bContext *C, ScrArea *sa)
                params->active_file = -1; // added this so it opens nicer (ton)
        }
        filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT);
+       filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);      
        if (filelist_empty(sfile->files))
        {
                filelist_readdir(sfile->files);
        }
-       filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);      
        if(params->sort!=FILE_SORT_NONE) filelist_sort(sfile->files, params->sort);             
 
        if (sfile->layout) sfile->layout->dirty= 1;
index fd37020c3b4b6c6e7d6e26120f589e3069d1f709..a429de656102c3620de8613e630af14506bfaa86 100644 (file)
@@ -609,6 +609,10 @@ static const EnumPropertyItem image_file_type_items[] = {
 static void image_filesel(bContext *C, wmOperator *op, const char *path)
 {
        RNA_string_set(op->ptr, "filename", path);
+       RNA_boolean_set(op->ptr, "filter_image", 1);
+       RNA_boolean_set(op->ptr, "filter_movie", 1);
+       RNA_boolean_set(op->ptr, "filter_folder", 1);
+       RNA_enum_set(op->ptr, "display", FILE_IMGDISPLAY);
        WM_event_add_fileselect(C, op); 
 }
 
@@ -649,6 +653,14 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
 void IMAGE_OT_open(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
+
+       static EnumPropertyItem file_display_items[] = {
+               {FILE_SHORTDISPLAY, "FILE_SHORTDISPLAY", ICON_SHORTDISPLAY, "Short List", "Display files as short list"},
+               {FILE_LONGDISPLAY, "FILE_LONGDISPLAY", ICON_LONGDISPLAY, "Long List", "Display files as a detailed list"},
+               {FILE_IMGDISPLAY, "FILE_IMGDISPLAY", ICON_IMGDISPLAY, "Thumbnails", "Display files as thumbnails"},
+               {0, NULL, 0, NULL, NULL}};
+
        /* identifiers */
        ot->name= "Open";
        ot->idname= "IMAGE_OT_open";
@@ -663,6 +675,19 @@ void IMAGE_OT_open(wmOperatorType *ot)
 
        /* properties */
        RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "File path of image to open.");
+
+       prop= RNA_def_boolean(ot->srna, "filter_image", 0, "Show image files", "");
+       RNA_def_property_boolean_sdna(prop, NULL, "filter", IMAGEFILE);
+       prop= RNA_def_boolean(ot->srna, "filter_movie", 0, "Show movie files", "");
+       RNA_def_property_boolean_sdna(prop, NULL, "filter", MOVIEFILE);
+       prop= RNA_def_boolean(ot->srna, "filter_folder", 0, "Show folders", "");
+       RNA_def_property_boolean_sdna(prop, NULL, "filter", FOLDERFILE);
+
+       prop= RNA_def_property(ot->srna, "display", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "display");
+       RNA_def_property_enum_items(prop, file_display_items);
+       RNA_def_property_ui_text(prop, "Display Mode", "Display mode for the file list");
+       
 }
 
 /******************** replace image operator ********************/
index d8e904b7c54dd9e8864ed7d04df323b78aff370d..e707d096a6019d0945f31520bd3e17f246846bd8 100644 (file)
@@ -820,18 +820,8 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
                                /* settings for filebrowser, sfile is not operator owner but sends events */
                                sfile= (SpaceFile*)CTX_wm_space_data(C);
                                sfile->op= handler->op;
-                               
-                               /* XXX for now take the settings from the existing (previous) filebrowser 
-                                  should be stored in settings and passed via the operator */
-                               if (sfile->params) {
-                                       flag = sfile->params->flag;
-                                       filter = sfile->params->filter;
-                                       display = sfile->params->display;
-                                       sort = sfile->params->sort;
-                                       dir = sfile->params->dir;
-                               }
 
-                               ED_fileselect_set_params(sfile, handler->op->type->name, dir, path, flag, display, filter, sort);
+                               ED_fileselect_set_params(sfile);
                                dir = NULL;
                                MEM_freeN(path);
                                
index 39114dcfe13a4ea703a9eb0c477d2eaf348b1be0..1f1a34ee308ab2ab42ae1c2db84699ce8eac99b8 100644 (file)
@@ -672,6 +672,8 @@ static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
 
        RNA_string_set(op->ptr, "filename", G.sce);
+       RNA_boolean_set(op->ptr, "filter_blender", 1);
+       RNA_boolean_set(op->ptr, "filter_folder", 1);
        WM_event_add_fileselect(C, op);
 
        return OPERATOR_RUNNING_MODAL;
@@ -693,6 +695,7 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
 
 static void WM_OT_open_mainfile(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
        ot->name= "Open Blender File";
        ot->idname= "WM_OT_open_mainfile";
        
@@ -700,7 +703,13 @@ static void WM_OT_open_mainfile(wmOperatorType *ot)
        ot->exec= wm_open_mainfile_exec;
        ot->poll= WM_operator_winactive;
        
-       RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
+       RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "File path of blendfile to open.");
+
+       prop= RNA_def_boolean(ot->srna, "filter_blender", 0, "Filter Blendfiles", "");
+       RNA_def_property_boolean_sdna(prop, NULL, "filter", BLENDERFILE);
+       prop= RNA_def_boolean(ot->srna, "filter_folder", 0, "Filter Blendfiles", "");
+       RNA_def_property_boolean_sdna(prop, NULL, "filter", FOLDERFILE);
+       
 }
 
 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)