diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-12-31 21:17:20 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-01-01 13:11:37 +0300 |
commit | d8bb30d87e5199c90a07ccc44d4e599179d12d35 (patch) | |
tree | 99d8c65bafc69da09b733eb5460e6f03394e8f39 /source/blender/editors/space_file/filelist.c | |
parent | 9de54da5a0f0e3fcec34a13b02574e603acb24bf (diff) |
SpaceFile: Filelist: reorder a bit things, also cleanup some unused and pure-private funcs.
Diffstat (limited to 'source/blender/editors/space_file/filelist.c')
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 476 |
1 files changed, 239 insertions, 237 deletions
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index ec57d08c21e..deececc6b98 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -45,9 +45,9 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" +#include "BLI_fileops_types.h" #include "BLI_linklist.h" #include "BLI_utildefines.h" -#include "BLI_fileops_types.h" #ifdef WIN32 # include "BLI_winstuff.h" @@ -64,8 +64,8 @@ #include "DNA_space_types.h" -#include "ED_fileselect.h" #include "ED_datafiles.h" +#include "ED_fileselect.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -80,6 +80,119 @@ #include "filelist.h" + +/* ----------------- FOLDERLIST (previous/next) -------------- */ + +typedef struct FolderList { + struct FolderList *next, *prev; + char *foldername; +} FolderList; + +ListBase *folderlist_new(void) +{ + ListBase *p = MEM_callocN(sizeof(ListBase), "folderlist"); + return p; +} + +void folderlist_popdir(struct ListBase *folderlist, char *dir) +{ + const char *prev_dir; + struct FolderList *folder; + folder = folderlist->last; + + if (folder) { + /* remove the current directory */ + MEM_freeN(folder->foldername); + BLI_freelinkN(folderlist, folder); + + folder = folderlist->last; + if (folder) { + prev_dir = folder->foldername; + BLI_strncpy(dir, prev_dir, FILE_MAXDIR); + } + } + /* delete the folder next or use setdir directly before PREVIOUS OP */ +} + +void folderlist_pushdir(ListBase *folderlist, const char *dir) +{ + struct FolderList *folder, *previous_folder; + previous_folder = folderlist->last; + + /* check if already exists */ + if (previous_folder && previous_folder->foldername) { + if (BLI_path_cmp(previous_folder->foldername, dir) == 0) { + return; + } + } + + /* create next folder element */ + folder = (FolderList *)MEM_mallocN(sizeof(FolderList), "FolderList"); + folder->foldername = BLI_strdup(dir); + + /* add it to the end of the list */ + BLI_addtail(folderlist, folder); +} + +const char *folderlist_peeklastdir(ListBase *folderlist) +{ + struct FolderList *folder; + + if (!folderlist->last) + return NULL; + + folder = folderlist->last; + return folder->foldername; +} + +int folderlist_clear_next(struct SpaceFile *sfile) +{ + struct FolderList *folder; + + /* if there is no folder_next there is nothing we can clear */ + if (!sfile->folders_next) + return 0; + + /* if previous_folder, next_folder or refresh_folder operators are executed it doesn't clear folder_next */ + folder = sfile->folders_prev->last; + if ((!folder) || (BLI_path_cmp(folder->foldername, sfile->params->dir) == 0)) + return 0; + + /* eventually clear flist->folders_next */ + return 1; +} + +/* not listbase itself */ +void folderlist_free(ListBase *folderlist) +{ + if (folderlist) { + FolderList *folder; + for (folder = folderlist->first; folder; folder = folder->next) + MEM_freeN(folder->foldername); + BLI_freelistN(folderlist); + } +} + +ListBase *folderlist_duplicate(ListBase *folderlist) +{ + + if (folderlist) { + ListBase *folderlistn = MEM_callocN(sizeof(ListBase), "copy folderlist"); + FolderList *folder; + + BLI_duplicatelist(folderlistn, folderlist); + + for (folder = folderlistn->first; folder; folder = folder->next) { + folder->foldername = MEM_dupallocN(folder->foldername); + } + return folderlistn; + } + return NULL; +} + + +/* ------------------FILELIST------------------------ */ + struct FileList; typedef struct FileImage { @@ -91,14 +204,6 @@ typedef struct FileImage { ImBuf *img; } FileImage; -typedef struct ThumbnailJob { - ListBase loadimages; - const short *stop; - const short *do_update; - struct FileList *filelist; - ReportList reports; -} ThumbnailJob; - typedef struct FileList { struct direntry *filelist; int *fidx; @@ -120,11 +225,6 @@ typedef struct FileList { } FileList; -typedef struct FolderList { - struct FolderList *next, *prev; - char *foldername; -} FolderList; - #define SPECIAL_IMG_SIZE 48 #define SPECIAL_IMG_ROWS 4 #define SPECIAL_IMG_COLS 4 @@ -146,7 +246,14 @@ typedef struct FolderList { static ImBuf *gSpecialFileImages[SPECIAL_IMG_MAX]; -/* ******************* SORT ******************* */ +static void filelist_from_main(struct FileList *filelist); +static void filelist_from_library(struct FileList *filelist); + +static void filelist_read_main(struct FileList *filelist); +static void filelist_read_library(struct FileList *filelist); +static void filelist_read_dir(struct FileList *filelist); + +/* ********** Sort helpers ********** */ static bool compare_is_directory(const struct direntry *entry) { @@ -292,6 +399,28 @@ static int compare_extension(const void *a1, const void *a2) return (BLI_strcasecmp(sufix1, sufix2)); } +void filelist_sort(struct FileList *filelist, short sort) +{ + switch (sort) { + case FILE_SORT_ALPHA: + qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_name); + break; + case FILE_SORT_TIME: + qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_date); + break; + case FILE_SORT_SIZE: + qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_size); + break; + case FILE_SORT_EXTENSION: + qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_extension); + break; + } + + filelist_filter(filelist); +} + +/* ********** Filter helpers ********** */ + static bool is_hidden_file(const char *filename, short hide_dot) { bool is_hidden = false; @@ -347,6 +476,7 @@ static bool is_filtered_lib(struct direntry *file, const char *dir, unsigned int else { is_filtered = is_filtered_file(file, dir, filter, hide_dot); } + return is_filtered; } @@ -386,6 +516,23 @@ void filelist_filter(FileList *filelist) } } +void filelist_hidedot(struct FileList *filelist, short hide) +{ + filelist->hide_dot = hide; +} + +void filelist_setfilter(struct FileList *filelist, unsigned int filter) +{ + filelist->filter = filter; +} + +void filelist_setfilter_types(struct FileList *filelist, const char *filter_glob) +{ + BLI_strncpy(filelist->filter_glob, filter_glob, sizeof(filelist->filter_glob)); +} + +/* ********** Icon/image helpers ********** */ + void filelist_init_icons(void) { short x, y, k; @@ -428,115 +575,86 @@ void filelist_free_icons(void) } } -/* -----------------FOLDERLIST (previous/next) -------------- */ -ListBase *folderlist_new(void) -{ - ListBase *p = MEM_callocN(sizeof(ListBase), "folderlist"); - return p; -} - -void folderlist_popdir(struct ListBase *folderlist, char *dir) +void filelist_imgsize(struct FileList *filelist, short w, short h) { - const char *prev_dir; - struct FolderList *folder; - folder = folderlist->last; - - if (folder) { - /* remove the current directory */ - MEM_freeN(folder->foldername); - BLI_freelinkN(folderlist, folder); - - folder = folderlist->last; - if (folder) { - prev_dir = folder->foldername; - BLI_strncpy(dir, prev_dir, FILE_MAXDIR); - } - } - /* delete the folder next or use setdir directly before PREVIOUS OP */ + filelist->prv_w = w; + filelist->prv_h = h; } -void folderlist_pushdir(ListBase *folderlist, const char *dir) +ImBuf *filelist_getimage(struct FileList *filelist, int index) { - struct FolderList *folder, *previous_folder; - previous_folder = folderlist->last; - - /* check if already exists */ - if (previous_folder && previous_folder->foldername) { - if (BLI_path_cmp(previous_folder->foldername, dir) == 0) { - return; - } - } - - /* create next folder element */ - folder = (FolderList *)MEM_mallocN(sizeof(FolderList), "FolderList"); - folder->foldername = BLI_strdup(dir); - - /* add it to the end of the list */ - BLI_addtail(folderlist, folder); -} + ImBuf *ibuf = NULL; + int fidx = 0; -const char *folderlist_peeklastdir(ListBase *folderlist) -{ - struct FolderList *folder; + BLI_assert(G.background == false); - if (!folderlist->last) + if ((index < 0) || (index >= filelist->numfiltered)) { return NULL; + } + fidx = filelist->fidx[index]; + ibuf = filelist->filelist[fidx].image; - folder = folderlist->last; - return folder->foldername; + return ibuf; } -int folderlist_clear_next(struct SpaceFile *sfile) +ImBuf *filelist_geticon(struct FileList *filelist, int index) { - struct FolderList *folder; - - /* if there is no folder_next there is nothing we can clear */ - if (!sfile->folders_next) - return 0; - - /* if previous_folder, next_folder or refresh_folder operators are executed it doesn't clear folder_next */ - folder = sfile->folders_prev->last; - if ((!folder) || (BLI_path_cmp(folder->foldername, sfile->params->dir) == 0)) - return 0; + ImBuf *ibuf = NULL; + struct direntry *file = NULL; + int fidx = 0; - /* eventually clear flist->folders_next */ - return 1; -} + BLI_assert(G.background == false); -/* not listbase itself */ -void folderlist_free(ListBase *folderlist) -{ - if (folderlist) { - FolderList *folder; - for (folder = folderlist->first; folder; folder = folder->next) - MEM_freeN(folder->foldername); - BLI_freelistN(folderlist); + if ((index < 0) || (index >= filelist->numfiltered)) { + return NULL; } -} - -ListBase *folderlist_duplicate(ListBase *folderlist) -{ - - if (folderlist) { - ListBase *folderlistn = MEM_callocN(sizeof(ListBase), "copy folderlist"); - FolderList *folder; - - BLI_duplicatelist(folderlistn, folderlist); - - for (folder = folderlistn->first; folder; folder = folder->next) { - folder->foldername = MEM_dupallocN(folder->foldername); + fidx = filelist->fidx[index]; + file = &filelist->filelist[fidx]; + if (file->type & S_IFDIR) { + if (strcmp(filelist->filelist[fidx].relname, "..") == 0) { + ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT]; + } + else if (strcmp(filelist->filelist[fidx].relname, ".") == 0) { + ibuf = gSpecialFileImages[SPECIAL_IMG_REFRESH]; + } + else { + ibuf = gSpecialFileImages[SPECIAL_IMG_FOLDER]; } - return folderlistn; } - return NULL; -} + else { + ibuf = gSpecialFileImages[SPECIAL_IMG_UNKNOWNFILE]; + } + + if (file->flags & BLENDERFILE) { + ibuf = gSpecialFileImages[SPECIAL_IMG_BLENDFILE]; + } + else if ((file->flags & MOVIEFILE) || (file->flags & MOVIEFILE_ICON)) { + ibuf = gSpecialFileImages[SPECIAL_IMG_MOVIEFILE]; + } + else if (file->flags & SOUNDFILE) { + ibuf = gSpecialFileImages[SPECIAL_IMG_SOUNDFILE]; + } + else if (file->flags & PYSCRIPTFILE) { + ibuf = gSpecialFileImages[SPECIAL_IMG_PYTHONFILE]; + } + else if (file->flags & FTFONTFILE) { + ibuf = gSpecialFileImages[SPECIAL_IMG_FONTFILE]; + } + else if (file->flags & TEXTFILE) { + ibuf = gSpecialFileImages[SPECIAL_IMG_TEXTFILE]; + } + else if (file->flags & IMAGEFILE) { + ibuf = gSpecialFileImages[SPECIAL_IMG_LOADING]; + } + else if (file->flags & BLENDERFILE_BACKUP) { + ibuf = gSpecialFileImages[SPECIAL_IMG_BACKUP]; + } + return ibuf; +} -static void filelist_read_main(struct FileList *filelist); -static void filelist_read_library(struct FileList *filelist); -static void filelist_read_dir(struct FileList *filelist); +/* ********** Main ********** */ -/* ------------------FILELIST------------------------ */ FileList *filelist_new(short type) { FileList *p = MEM_callocN(sizeof(FileList), "filelist"); @@ -558,7 +676,6 @@ FileList *filelist_new(short type) return p; } - void filelist_free(struct FileList *filelist) { if (!filelist) { @@ -607,89 +724,11 @@ void filelist_setdir(struct FileList *filelist, const char *dir) BLI_strncpy(filelist->dir, dir, sizeof(filelist->dir)); } -void filelist_imgsize(struct FileList *filelist, short w, short h) -{ - filelist->prv_w = w; - filelist->prv_h = h; -} - short filelist_changed(struct FileList *filelist) { return filelist->changed; } -ImBuf *filelist_getimage(struct FileList *filelist, int index) -{ - ImBuf *ibuf = NULL; - int fidx = 0; - - BLI_assert(G.background == false); - - if ((index < 0) || (index >= filelist->numfiltered)) { - return NULL; - } - fidx = filelist->fidx[index]; - ibuf = filelist->filelist[fidx].image; - - return ibuf; -} - -ImBuf *filelist_geticon(struct FileList *filelist, int index) -{ - ImBuf *ibuf = NULL; - struct direntry *file = NULL; - int fidx = 0; - - BLI_assert(G.background == false); - - if ((index < 0) || (index >= filelist->numfiltered)) { - return NULL; - } - fidx = filelist->fidx[index]; - file = &filelist->filelist[fidx]; - if (file->type & S_IFDIR) { - if (strcmp(filelist->filelist[fidx].relname, "..") == 0) { - ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT]; - } - else if (strcmp(filelist->filelist[fidx].relname, ".") == 0) { - ibuf = gSpecialFileImages[SPECIAL_IMG_REFRESH]; - } - else { - ibuf = gSpecialFileImages[SPECIAL_IMG_FOLDER]; - } - } - else { - ibuf = gSpecialFileImages[SPECIAL_IMG_UNKNOWNFILE]; - } - - if (file->flags & BLENDERFILE) { - ibuf = gSpecialFileImages[SPECIAL_IMG_BLENDFILE]; - } - else if ((file->flags & MOVIEFILE) || (file->flags & MOVIEFILE_ICON)) { - ibuf = gSpecialFileImages[SPECIAL_IMG_MOVIEFILE]; - } - else if (file->flags & SOUNDFILE) { - ibuf = gSpecialFileImages[SPECIAL_IMG_SOUNDFILE]; - } - else if (file->flags & PYSCRIPTFILE) { - ibuf = gSpecialFileImages[SPECIAL_IMG_PYTHONFILE]; - } - else if (file->flags & FTFONTFILE) { - ibuf = gSpecialFileImages[SPECIAL_IMG_FONTFILE]; - } - else if (file->flags & TEXTFILE) { - ibuf = gSpecialFileImages[SPECIAL_IMG_TEXTFILE]; - } - else if (file->flags & IMAGEFILE) { - ibuf = gSpecialFileImages[SPECIAL_IMG_LOADING]; - } - else if (file->flags & BLENDERFILE_BACKUP) { - ibuf = gSpecialFileImages[SPECIAL_IMG_BACKUP]; - } - - return ibuf; -} - struct direntry *filelist_file(struct FileList *filelist, int index) { int fidx = 0; @@ -728,21 +767,6 @@ int filelist_find(struct FileList *filelist, const char *filename) return fidx; } -void filelist_hidedot(struct FileList *filelist, short hide) -{ - filelist->hide_dot = hide; -} - -void filelist_setfilter(struct FileList *filelist, unsigned int filter) -{ - filelist->filter = filter; -} - -void filelist_setfilter_types(struct FileList *filelist, const char *filter_glob) -{ - BLI_strncpy(filelist->filter_glob, filter_glob, sizeof(filelist->filter_glob)); -} - /* would recognize .blend as well */ static bool file_is_blend_backup(const char *str) { @@ -874,7 +898,6 @@ static void filelist_setfiletypes(struct FileList *filelist) { file->flags = OPERATORFILE; } - } } @@ -932,15 +955,8 @@ void filelist_readdir(struct FileList *filelist) } int filelist_empty(struct FileList *filelist) -{ - return filelist->filelist == NULL; -} - -void filelist_parent(struct FileList *filelist) { - BLI_parent_dir(filelist->dir); - BLI_make_exist(filelist->dir); - filelist_readdir(filelist); + return filelist->filelist == NULL; } void filelist_select_file(struct FileList *filelist, int index, FileSelType select, unsigned int flag, FileCheckType check) @@ -1004,26 +1020,6 @@ bool filelist_is_selected(struct FileList *filelist, int index, FileCheckType ch } } -void filelist_sort(struct FileList *filelist, short sort) -{ - switch (sort) { - case FILE_SORT_ALPHA: - qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_name); - break; - case FILE_SORT_TIME: - qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_date); - break; - case FILE_SORT_SIZE: - qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_size); - break; - case FILE_SORT_EXTENSION: - qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_extension); - break; - } - - filelist_filter(filelist); -} - bool filelist_islibrary(struct FileList *filelist, char *dir, char *group) { @@ -1042,8 +1038,8 @@ static int groupname_to_code(const char *group) return buf[0] ? BKE_idcode_from_name(buf) : 0; } - -void filelist_from_library(struct FileList *filelist) + +static void filelist_from_library(struct FileList *filelist) { LinkNode *l, *names, *previews; struct ImBuf *ima; @@ -1141,12 +1137,7 @@ void filelist_from_library(struct FileList *filelist) filelist_filter(filelist); } -void filelist_hideparent(struct FileList *filelist, short hide) -{ - filelist->hide_parent = hide; -} - -void filelist_from_main(struct FileList *filelist) +static void filelist_from_main(struct FileList *filelist) { ID *id; struct direntry *files, *firstlib = NULL; @@ -1296,6 +1287,17 @@ void filelist_from_main(struct FileList *filelist) filelist_filter(filelist); } +/* ********** Thumbnails job ********** */ + +typedef struct ThumbnailJob { + ListBase loadimages; + ImBuf *static_icons_buffers[BIFICONID_LAST]; + const short *stop; + const short *do_update; + struct FileList *filelist; + ReportList reports; +} ThumbnailJob; + static void thumbnail_joblist_free(ThumbnailJob *tj) { FileImage *limg = tj->loadimages.first; |