rename RNA_property_is_set() --> RNA_struct_property_is_set() in preperation to add...
[blender.git] / source / blender / editors / space_file / filesel.c
index 6773dfb6b2db1f899f8fb79e6c09b057648e49e3..bf31775a349d8e0c864739a644fa8240b1fe2cc8 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -64,8 +62,6 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
-#include "BLI_path_util.h"
-#include "BLI_storage_types.h"
 #include "BLI_dynstr.h"
 #include "BLI_utildefines.h"
 
@@ -113,7 +109,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
        if (!sfile->params) {
                sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
                /* set path to most recently opened .blend */
-               BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file);
+               BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
                sfile->params->filter_glob[0] = '\0';
        }
 
@@ -125,6 +121,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                const short is_filepath= (RNA_struct_find_property(op->ptr, "filepath") != NULL);
                const short is_filename= (RNA_struct_find_property(op->ptr, "filename") != NULL);
                const short is_directory= (RNA_struct_find_property(op->ptr, "directory") != NULL);
+               const short is_relative_path= (RNA_struct_find_property(op->ptr, "relative_path") != NULL);
 
                BLI_strncpy(params->title, op->type->name, sizeof(params->title));
 
@@ -133,7 +130,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                else
                        params->type = FILE_SPECIAL;
 
-               if (is_filepath && RNA_property_is_set(op->ptr, "filepath")) {
+               if (is_filepath && RNA_struct_property_is_set(op->ptr, "filepath")) {
                        char name[FILE_MAX];
                        RNA_string_get(op->ptr, "filepath", name);
                        if (params->type == FILE_LOADLIB) {
@@ -141,16 +138,16 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                                sfile->params->file[0]= '\0';
                        }
                        else {
-                               BLI_split_dirfile(name, sfile->params->dir, sfile->params->file);
+                               BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
                        }
                }
                else {
-                       if (is_directory && RNA_property_is_set(op->ptr, "directory")) {
+                       if (is_directory && RNA_struct_property_is_set(op->ptr, "directory")) {
                                RNA_string_get(op->ptr, "directory", params->dir);
                                sfile->params->file[0]= '\0';
                        }
 
-                       if (is_filename && RNA_property_is_set(op->ptr, "filename")) {
+                       if (is_filename && RNA_struct_property_is_set(op->ptr, "filename")) {
                                RNA_string_get(op->ptr, "filename", params->file);
                        }
                }
@@ -228,6 +225,11 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                        params->display= FILE_SHORTDISPLAY;
                }
 
+               if (is_relative_path) {
+                       if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
+                               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+                       }
+               }
        }
        else {
                /* default values, if no operator */
@@ -246,6 +248,11 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                sfile->folders_prev = folderlist_new();
        folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
 
+       /* switching thumbnails needs to recalc layout [#28809] */
+       if (sfile->layout) {
+               sfile->layout->dirty= TRUE;
+       }
+
        return 1;
 }
 
@@ -376,7 +383,7 @@ float file_shorten_string(char* string, float w, int front)
                        shortened = 1;
                }
                if (shortened) {
-                       int slen = strlen(s);                   
+                       int slen = strlen(s);
                        BLI_strncpy(temp+3, s, slen+1);
                        temp[slen+4] = '\0';
                        BLI_strncpy(string, temp, slen+4);
@@ -393,7 +400,7 @@ float file_shorten_string(char* string, float w, int front)
                if (shortened) {
                        int slen = strlen(string);
                        if (slen > 3) {
-                               BLI_strncpy(string+slen-3, "...", 4);                           
+                               BLI_strncpy(string+slen-3, "...", 4);
                        }
                }
        }
@@ -403,7 +410,7 @@ float file_shorten_string(char* string, float w, int front)
 
 float file_string_width(const char* str)
 {
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        uiStyleFontSet(&style->widget);
        return BLF_width(style->widget.uifont_id, str);
 }
@@ -413,12 +420,12 @@ float file_font_pointsize(void)
 #if 0
        float s;
        char tmp[2] = "X";
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        uiStyleFontSet(&style->widget);
        s = BLF_height(style->widget.uifont_id, tmp);
        return style->widget.points;
 #else
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        uiStyleFontSet(&style->widget);
        return style->widget.points * UI_DPI_FAC;
 #endif
@@ -466,12 +473,13 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
        int maxlen = 0;
        int numfiles;
        int textheight;
+
        if (sfile->layout == NULL) {
                sfile->layout = MEM_callocN(sizeof(struct FileLayout), "file_layout");
-               sfile->layout->dirty = 1;
-       } 
-
-       if (!sfile->layout->dirty) return;
+               sfile->layout->dirty = TRUE;
+       } else if (sfile->layout->dirty == FALSE) {
+               return;
+       }
 
        numfiles = filelist_numfiles(sfile->files);
        textheight = (int)file_font_pointsize();
@@ -538,7 +546,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
                layout->width = sfile->layout->columns * (layout->tile_w + 2*layout->tile_border_x) + layout->tile_border_x*2;
                layout->flag = FILE_LAYOUT_HOR;
        }
-       layout->dirty= 0;
+       layout->dirty= FALSE;
 }
 
 FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar)
@@ -601,7 +609,7 @@ void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
                DIR *dir;
                struct dirent *de;
                
-               BLI_split_dirfile(str, dirname, NULL);
+               BLI_split_dir_part(str, dirname, sizeof(dirname));
 
                dir = opendir(dirname);
 
@@ -659,9 +667,13 @@ void autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v))
 
 void ED_fileselect_clear(struct bContext *C, struct SpaceFile *sfile)
 {
-       thumbnails_stop(sfile->files, C);
-       filelist_freelib(sfile->files);
-       filelist_free(sfile->files);
+       /* only NULL in rare cases - [#29734] */
+       if (sfile->files) {
+               thumbnails_stop(sfile->files, C);
+               filelist_freelib(sfile->files);
+               filelist_free(sfile->files);
+       }
+
        sfile->params->active_file = -1;
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 }