2.5 filebrowser
[blender-staging.git] / source / blender / editors / space_file / filesel.c
index 8ee7d3515b507fe036702f6c9c908acd601a32f4..e9e09d8f60b2cce3c1ce512bf49cb887c8b6d453 100644 (file)
@@ -123,6 +123,22 @@ short ED_fileselect_set_params(SpaceFile *sfile)
        /* set the parameters from the operator, if it exists */
        if (op) {
                BLI_strncpy(params->title, op->type->name, sizeof(params->title));
        /* set the parameters from the operator, if it exists */
        if (op) {
                BLI_strncpy(params->title, op->type->name, sizeof(params->title));
+
+               params->type = RNA_int_get(op->ptr, "filemode");
+
+               if (RNA_property_is_set(op->ptr, "path")) {
+                       RNA_string_get(op->ptr, "path", name);
+                       if (params->type == FILE_LOADLIB) {
+                               BLI_strncpy(params->dir, name, sizeof(params->dir));
+                               BLI_cleanup_dir(G.sce, params->dir);    
+                       } else { 
+                               /* if operator has path set, use it, otherwise keep the last */
+                               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 */
+                       }
+               }
                params->filter = 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 = 0;
                params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0;
                params->filter |= RNA_boolean_get(op->ptr, "filter_image") ? IMAGEFILE : 0;
@@ -137,36 +153,33 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                        params->flag |= FILE_FILTER;
 
                params->flag |= FILE_HIDE_DOT;
                        params->flag |= FILE_FILTER;
 
                params->flag |= FILE_HIDE_DOT;
-               
+
+               if (params->type == FILE_LOADLIB) {
+                       params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0;
+                       params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0;
+                       params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
+               }
+
                if(params->filter & (IMAGEFILE|MOVIEFILE))
                        params->display= FILE_IMGDISPLAY;
                else
                        params->display= FILE_SHORTDISPLAY;
                
                if(params->filter & (IMAGEFILE|MOVIEFILE))
                        params->display= FILE_IMGDISPLAY;
                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 */
        } else {
                /* default values, if no operator */
+               params->type = FILE_UNIX;
                params->flag |= FILE_HIDE_DOT;
                params->display = FILE_SHORTDISPLAY;
                params->filter = 0;
                params->sort = FILE_SORT_ALPHA;
        }
 
                params->flag |= FILE_HIDE_DOT;
                params->display = FILE_SHORTDISPLAY;
                params->filter = 0;
                params->sort = FILE_SORT_ALPHA;
        }
 
-       /* new params, refresh file list */
-       if(sfile->files) filelist_free(sfile->files);
-
        return 1;
 }
 
 void ED_fileselect_reset_params(SpaceFile *sfile)
 {
        return 1;
 }
 
 void ED_fileselect_reset_params(SpaceFile *sfile)
 {
+       sfile->params->type = FILE_UNIX;
        sfile->params->flag = 0;
        sfile->params->title[0] = '\0';
 }
        sfile->params->flag = 0;
        sfile->params->title[0] = '\0';
 }
@@ -287,6 +300,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
        numfiles = filelist_numfiles(sfile->files);
        textheight = file_font_pointsize();
        layout = sfile->layout;
        numfiles = filelist_numfiles(sfile->files);
        textheight = file_font_pointsize();
        layout = sfile->layout;
+       layout->textheight = textheight;
 
        if (params->display == FILE_IMGDISPLAY) {
                layout->prv_w = 96;
 
        if (params->display == FILE_IMGDISPLAY) {
                layout->prv_w = 96;
@@ -356,19 +370,15 @@ FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar
 void file_change_dir(struct SpaceFile *sfile)
 {
        if (sfile->params) { 
 void file_change_dir(struct SpaceFile *sfile)
 {
        if (sfile->params) { 
-               if (BLI_exists(sfile->params->dir)) {
-                       filelist_setdir(sfile->files, sfile->params->dir);
+               filelist_setdir(sfile->files, sfile->params->dir);
 
 
-                       if(folderlist_clear_next(sfile))
-                               folderlist_free(sfile->folders_next);
+               if(folderlist_clear_next(sfile))
+                       folderlist_free(sfile->folders_next);
 
 
-                       folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
+               folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
 
 
-                       filelist_free(sfile->files);
-                       sfile->params->active_file = -1;
-               } else {
-                       BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), FILE_MAX);
-               }
+               filelist_free(sfile->files);
+               sfile->params->active_file = -1;
        }
 }
 
        }
 }