Added a NULL check that was needed.
[blender.git] / source / blender / src / filesel.c
index b4c090dd7fbc618b2d5ff8b8ab749b9594d7030d..1bdca25a88d0fc149074c0db16140b15d0cc5ac8 100644 (file)
@@ -86,6 +86,7 @@
 #include "BKE_utildefines.h"
 
 #include "BIF_editview.h"
+#include "BIF_filelist.h"
 #include "BIF_gl.h"
 #include "BIF_interface.h"
 #include "BIF_language.h"
 
 #include "BIF_fsmenu.h"  /* include ourselves */
 
+#ifdef INTERNATIONAL
+#include "FTF_Api.h"
+#endif
+
 #if defined WIN32 || defined __BeOS
-int fnmatch(const char *pattern, const char *string, int flags)
+static int fnmatch(const char *pattern, const char *string, int flags)
 {
        return 0;
 }
@@ -166,155 +171,6 @@ static float pixels_to_ofs;
 static char otherdir[FILE_MAX];
 static ScrArea *otherarea;
 
-/* FSMENU HANDLING */
-
-       /* FSMenuEntry's without paths indicate seperators */
-typedef struct _FSMenuEntry FSMenuEntry;
-struct _FSMenuEntry {
-       FSMenuEntry *next;
-
-       char *path;
-};
-
-static FSMenuEntry *fsmenu= 0;
-
-int fsmenu_get_nentries(void)
-{
-       FSMenuEntry *fsme;
-       int count= 0;
-
-       for (fsme= fsmenu; fsme; fsme= fsme->next) 
-               count++;
-
-       return count;
-}
-int fsmenu_is_entry_a_seperator(int idx)
-{
-       FSMenuEntry *fsme;
-
-       for (fsme= fsmenu; fsme && idx; fsme= fsme->next)
-               idx--;
-
-       return (fsme && !fsme->path)?1:0;
-}
-char *fsmenu_get_entry(int idx)
-{
-       FSMenuEntry *fsme;
-
-       for (fsme= fsmenu; fsme && idx; fsme= fsme->next)
-               idx--;
-
-       return fsme?fsme->path:NULL;
-}
-char *fsmenu_build_menu(void)
-{
-       DynStr *ds= BLI_dynstr_new();
-       FSMenuEntry *fsme;
-       char *menustr;
-
-       for (fsme= fsmenu; fsme; fsme= fsme->next) {
-               if (!fsme->path) {
-                               /* clean consecutive seperators and ignore trailing ones */
-                       if (fsme->next) {
-                               if (fsme->next->path) {
-                                       BLI_dynstr_append(ds, "%l|");
-                               } else {
-                                       FSMenuEntry *next= fsme->next;
-                                       fsme->next= next->next;
-                                       MEM_freeN(next);
-                               }
-                       }
-               } else {
-                       BLI_dynstr_append(ds, fsme->path);
-                       if (fsme->next) BLI_dynstr_append(ds, "|");
-               }
-       }
-
-       menustr= BLI_dynstr_get_cstring(ds);
-       BLI_dynstr_free(ds);
-       return menustr;
-}
-static FSMenuEntry *fsmenu_get_last_separator(void) 
-{
-       FSMenuEntry *fsme, *lsep=NULL;
-
-       for (fsme= fsmenu; fsme; fsme= fsme->next)
-               if (!fsme->path)
-                       lsep= fsme;
-
-       return lsep;
-}
-void fsmenu_insert_entry(char *path, int sorted)
-{
-       FSMenuEntry *prev= fsmenu_get_last_separator();
-       FSMenuEntry *fsme= prev?prev->next:fsmenu;
-
-       for (; fsme; prev= fsme, fsme= fsme->next) {
-               if (fsme->path) {
-                       if (BLI_streq(path, fsme->path)) {
-                               return;
-                       } else if (sorted && strcmp(path, fsme->path)<0) {
-                               break;
-                       }
-               }
-       }
-       
-       fsme= MEM_mallocN(sizeof(*fsme), "fsme");
-       fsme->path= BLI_strdup(path);
-
-       if (prev) {
-               fsme->next= prev->next;
-               prev->next= fsme;
-       } else {
-               fsme->next= fsmenu;
-               fsmenu= fsme;
-       }
-}
-void fsmenu_append_seperator(void)
-{
-       if (fsmenu) {
-               FSMenuEntry *fsme= fsmenu;
-
-               while (fsme->next) fsme= fsme->next;
-
-               fsme->next= MEM_mallocN(sizeof(*fsme), "fsme");
-               fsme->next->next= NULL;
-               fsme->next->path= NULL;
-       }
-}
-void fsmenu_remove_entry(int idx)
-{
-       FSMenuEntry *prev= NULL, *fsme= fsmenu;
-
-       for (fsme= fsmenu; fsme && idx; prev= fsme, fsme= fsme->next)
-               if (fsme->path)
-                       idx--;
-
-       if (fsme) {
-               if (prev) {
-                       prev->next= fsme->next;
-               } else {
-                       fsmenu= fsme->next;
-               }
-
-               MEM_freeN(fsme->path);
-               MEM_freeN(fsme);
-       }
-}
-void fsmenu_free(void)
-{
-       FSMenuEntry *fsme= fsmenu;
-
-       while (fsme) {
-               FSMenuEntry *n= fsme->next;
-
-               if (fsme->path) MEM_freeN(fsme->path);
-               MEM_freeN(fsme);
-
-               fsme= n;
-       }
-}
-
 /* ******************* SORT ******************* */
 
 static int compare_name(const void *a1, const void *a2)
@@ -507,7 +363,7 @@ void test_flags_file(SpaceFile *sfile)
                                        }
                                }
                        }
-               } else if (sfile->type==FILE_SPECIAL){
+               } else if (sfile->type==FILE_SPECIAL || sfile->type==FILE_LOADFONT){
                        if(BLI_testextensie(file->relname, ".py")) {
                                file->flags |= PYSCRIPTFILE;                    
                        } else if( BLI_testextensie(file->relname, ".ttf")
@@ -950,8 +806,8 @@ static void print_line(SpaceFile *sfile, struct direntry *files, int x, int y)
                        struct LANGMenuEntry *lme;
                        lme = find_language(U.language);
 
-                       if (!strcmp(lme->code, "ja_JP") || 
-                               !strcmp(lme->code, "zh_CN"))
+                       if ((lme !=NULL) && (!strcmp(lme->code, "ja_JP") || 
+                               !strcmp(lme->code, "zh_CN")))
                        {
                                BIF_RasterPos((float)x, (float)y);
 #ifdef WIN32
@@ -1333,8 +1189,10 @@ static void activate_fileselect_(int type, char *title, char *file, short *menup
        /* sfile->act is used for databrowse: double names of library objects */
        sfile->act= -1;
 
-       if(BLI_convertstringcode(name, G.sce, G.scene->r.cfra)) sfile->flag |= FILE_STRINGCODE;
-       else sfile->flag &= ~FILE_STRINGCODE;
+       if(G.relbase_valid && BLI_convertstringcode(name, G.sce, G.scene->r.cfra))
+               sfile->flag |= FILE_STRINGCODE;
+       else
+               sfile->flag &= ~FILE_STRINGCODE;
 
        if (U.uiflag & USER_HIDE_DOT)
                sfile->flag |= FILE_HIDE_DOT;
@@ -1368,7 +1226,7 @@ static void activate_fileselect_(int type, char *title, char *file, short *menup
                        sfile->libfiledata= NULL;
                }
        }
-       else {  /* FILE_BLENDER */
+       else {  /* FILE_BLENDER or FILE_LOADFONT */
                split_sfile(sfile, name);       /* test filelist too */
                BLI_cleanup_dir(G.sce, sfile->dir);
 
@@ -1395,41 +1253,6 @@ void activate_fileselect_args(int type, char *title, char *file, void (*func)(ch
        activate_fileselect_(type, title, file, NULL, NULL, NULL, NULL, func, arg1, arg2);
 }
 
-
-void activate_imageselect(int type, char *title, char *file, void (*func)(char *))
-{
-       SpaceImaSel *simasel;
-       char dir[FILE_MAX], name[FILE_MAX];
-       
-       if(curarea==NULL) return;
-       if(curarea->win==0) return;
-       
-       newspace(curarea, SPACE_IMASEL);
-       
-       /* sometimes double, when area is already SPACE_FILE with a different file name */
-       addqueue(curarea->headwin, CHANGED, 1);
-       addqueue(curarea->win, CHANGED, 1);
-
-       name[2]= 0;
-       BLI_strncpy(name, file, sizeof(name));
-
-       simasel= curarea->spacedata.first;
-       simasel->returnfunc= func;
-
-       if(BLI_convertstringcode(name, G.sce, G.scene->r.cfra)) simasel->mode |= IMS_STRINGCODE;
-       else simasel->mode &= ~IMS_STRINGCODE;
-       
-       BLI_split_dirfile(name, dir, simasel->file);
-       BLI_cleanup_dir(G.sce, simasel->dir);
-       if(strcmp(dir, simasel->dir)!=0) simasel->fase= 0;
-
-       BLI_strncpy(simasel->dir, dir, sizeof(simasel->dir));
-       BLI_strncpy(simasel->title, title, sizeof(simasel->title));
-       
-       /* filetoname= 1; */
-}
-
-
 void activate_databrowse(ID *id, int idcode, int fromcode, int retval, short *menup, void (*func)(unsigned short))
 {
        ListBase *lb;
@@ -1599,7 +1422,7 @@ static void filesel_execute(SpaceFile *sfile)
                allqueue(REDRAWALL, 1);
        }
        else if(filesel_has_func(sfile)) {
-               fsmenu_insert_entry(sfile->dir, 1);
+               fsmenu_insert_entry(sfile->dir, 1, 0);
        
                if(sfile->type==FILE_MAIN) { /* DATABROWSE */
                        if (sfile->menup) {     /* with value pointing to ID block index */
@@ -2013,14 +1836,23 @@ void winqreadfilespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                strcat(sfile->dir, sfile->filelist[act].relname);
                                                strcat(sfile->dir,"/");
                                                BLI_cleanup_dir(G.sce, sfile->dir);
-                                               freefilelist(sfile);
+                                               freefilelist(sfile);                                            
                                                sfile->ofs= 0;
                                                do_draw= 1;
                                        }
                                        else {
                                                if( strcmp(sfile->file, sfile->filelist[act].relname)) {
+                                                       char tmpstr[240];
                                                        do_draw= 1;
                                                        BLI_strncpy(sfile->file, sfile->filelist[act].relname, sizeof(sfile->file));
+                                                       if (sfile->f_fp) {
+                                                               sprintf (tmpstr, "%s%s", sfile->dir, sfile->file);
+                                                               /* printf ("%s\n", tmpstr); */
+                                                               #ifdef INTERNATIONAL
+                                                               if (!FTF_GetNewFont ((const unsigned char *)tmpstr, 0, U.fontsize))
+                                                                       error ("No font file");
+                                                               #endif
+                                                       }
                                                }
                                                if(event==MIDDLEMOUSE && sfile->type) filesel_execute(sfile);
                                        }