Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-02-15 18:26:41 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-02-15 18:35:42 +0300
commit1c64543aefd5c78540dc3de5254c0dd54649ca81 (patch)
tree4619f9f49f62a08d565e24baf87ef6e5150ffc5b /source/blender/editors
parentf1ee11fcca20ce1fb7db97a71e7e345c6faad69a (diff)
Cleanup of SpaceFile, from asset-experiments branch mostly.
Helps keeping diff with branch relevant and clean...
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/space_file/file_draw.c123
-rw-r--r--source/blender/editors/space_file/file_ops.c6
-rw-r--r--source/blender/editors/space_file/filelist.c143
3 files changed, 140 insertions, 132 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 9fe6ed73205..a00799c360d 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -287,8 +287,9 @@ static void file_draw_icon(uiBlock *block, char *path, int sx, int sy, int icon,
but = uiDefIconBut(block, UI_BTYPE_LABEL, 0, icon, x, y, width, height, NULL, 0.0f, 0.0f, 0.0f, 0.0f, "");
- if (drag)
+ if (drag) {
UI_but_drag_set_path(but, path);
+ }
}
@@ -324,70 +325,70 @@ void file_calc_previews(const bContext *C, ARegion *ar)
static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int sy, ImBuf *imb, FileLayout *layout, bool dropshadow, bool drag)
{
- if (imb) {
- uiBut *but;
- float fx, fy;
- float dx, dy;
- int xco, yco;
- float scaledx, scaledy;
- float scale;
- int ex, ey;
-
- if ((imb->x * UI_DPI_FAC > layout->prv_w) ||
- (imb->y * UI_DPI_FAC > layout->prv_h))
- {
- if (imb->x > imb->y) {
- scaledx = (float)layout->prv_w;
- scaledy = ( (float)imb->y / (float)imb->x) * layout->prv_w;
- scale = scaledx / imb->x;
- }
- else {
- scaledy = (float)layout->prv_h;
- scaledx = ( (float)imb->x / (float)imb->y) * layout->prv_h;
- scale = scaledy / imb->y;
- }
+ uiBut *but;
+ float fx, fy;
+ float dx, dy;
+ int xco, yco;
+ float scaledx, scaledy;
+ float scale;
+ int ex, ey;
+
+ BLI_assert(imb != NULL);
+
+ if ((imb->x * UI_DPI_FAC > layout->prv_w) ||
+ (imb->y * UI_DPI_FAC > layout->prv_h))
+ {
+ if (imb->x > imb->y) {
+ scaledx = (float)layout->prv_w;
+ scaledy = ( (float)imb->y / (float)imb->x) * layout->prv_w;
+ scale = scaledx / imb->x;
}
else {
- scaledx = (float)imb->x * UI_DPI_FAC;
- scaledy = (float)imb->y * UI_DPI_FAC;
- scale = UI_DPI_FAC;
+ scaledy = (float)layout->prv_h;
+ scaledx = ( (float)imb->x / (float)imb->y) * layout->prv_h;
+ scale = scaledy / imb->y;
}
+ }
+ else {
+ scaledx = (float)imb->x * UI_DPI_FAC;
+ scaledy = (float)imb->y * UI_DPI_FAC;
+ scale = UI_DPI_FAC;
+ }
- ex = (int)scaledx;
- ey = (int)scaledy;
- fx = ((float)layout->prv_w - (float)ex) / 2.0f;
- fy = ((float)layout->prv_h - (float)ey) / 2.0f;
- dx = (fx + 0.5f + layout->prv_border_x);
- dy = (fy + 0.5f - layout->prv_border_y);
- xco = sx + (int)dx;
- yco = sy - layout->prv_h + (int)dy;
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- /* shadow */
- if (dropshadow)
- UI_draw_box_shadow(220, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
+ ex = (int)scaledx;
+ ey = (int)scaledy;
+ fx = ((float)layout->prv_w - (float)ex) / 2.0f;
+ fy = ((float)layout->prv_h - (float)ey) / 2.0f;
+ dx = (fx + 0.5f + layout->prv_border_x);
+ dy = (fy + 0.5f - layout->prv_border_y);
+ xco = sx + (int)dx;
+ yco = sy - layout->prv_h + (int)dy;
- glEnable(GL_BLEND);
-
- /* the image */
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect, scale, scale);
-
- /* border */
- if (dropshadow) {
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
- fdrawbox((float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
- }
-
- /* dragregion */
- if (drag) {
- but = uiDefBut(block, UI_BTYPE_LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, "");
- UI_but_drag_set_image(but, file->path, get_file_icon(file), imb, scale);
- }
-
- glDisable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ /* shadow */
+ if (dropshadow)
+ UI_draw_box_shadow(220, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
+
+ glEnable(GL_BLEND);
+
+ /* the image */
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect, scale, scale);
+
+ /* border */
+ if (dropshadow) {
+ glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+ fdrawbox((float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
}
+
+ /* dragregion */
+ if (drag) {
+ but = uiDefBut(block, UI_BTYPE_LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, "");
+ UI_but_drag_set_image(but, file->path, get_file_icon(file), imb, scale);
+ }
+
+ glDisable(GL_BLEND);
}
static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
@@ -519,7 +520,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
sy = (int)(v2d->tot.ymax - sy);
file = filelist_file(files, i);
-
+
UI_ThemeColor4(TH_TEXT);
@@ -547,7 +548,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
imb = filelist_geticon(files, i);
is_icon = 1;
}
-
+
file_draw_preview(block, file, sx, sy, imb, layout, !is_icon && (file->flags & FILE_TYPE_IMAGE), do_drag);
}
else {
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index ddf9545289e..6cc4446274a 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -179,16 +179,18 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
params->active_file = selected_idx;
if (S_ISDIR(file->type)) {
+ const bool is_parent_dir = FILENAME_IS_PARENT(file->relname);
+
if (do_diropen == false) {
params->file[0] = '\0';
retval = FILE_SELECT_DIR;
}
/* the path is too long and we are not going up! */
- else if (!FILENAME_IS_PARENT(file->relname) && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) {
+ else if (!is_parent_dir && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) {
// XXX error("Path too long, cannot enter this directory");
}
else {
- if (FILENAME_IS_PARENT(file->relname)) {
+ if (is_parent_dir) {
/* avoids /../../ */
BLI_parent_dir(params->dir);
}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index f6175bea1f4..66acd7d05e3 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -37,10 +37,10 @@
#include <string.h>
#ifndef WIN32
-#include <unistd.h>
+# include <unistd.h>
#else
-#include <io.h>
-#include <direct.h>
+# include <io.h>
+# include <direct.h>
#endif
#include "MEM_guardedalloc.h"
@@ -58,10 +58,10 @@
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_icons.h"
+#include "BKE_idcode.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BLO_readfile.h"
-#include "BKE_idcode.h"
#include "DNA_space_types.h"
@@ -91,7 +91,7 @@ typedef struct FolderList {
ListBase *folderlist_new(void)
{
- ListBase *p = MEM_callocN(sizeof(ListBase), "folderlist");
+ ListBase *p = MEM_callocN(sizeof(*p), __func__);
return p;
}
@@ -128,7 +128,7 @@ void folderlist_pushdir(ListBase *folderlist, const char *dir)
}
/* create next folder element */
- folder = (FolderList *)MEM_mallocN(sizeof(FolderList), "FolderList");
+ folder = MEM_mallocN(sizeof(*folder), __func__);
folder->foldername = BLI_strdup(dir);
/* add it to the end of the list */
@@ -178,7 +178,7 @@ ListBase *folderlist_duplicate(ListBase *folderlist)
{
if (folderlist) {
- ListBase *folderlistn = MEM_callocN(sizeof(ListBase), "copy folderlist");
+ ListBase *folderlistn = MEM_callocN(sizeof(*folderlistn), __func__);
FolderList *folder;
BLI_duplicatelist(folderlistn, folderlist);
@@ -286,25 +286,30 @@ static int compare_direntry_generic(const struct direntry *entry1, const struct
/* type is equal to stat.st_mode */
if (compare_is_directory(entry1)) {
- if (compare_is_directory(entry2) == 0) return (-1);
+ if (compare_is_directory(entry2) == 0) {
+ return -1;
+ }
}
- else {
- if (compare_is_directory(entry2)) return (1);
+ else if (compare_is_directory(entry2)) {
+ return 1;
}
+
if (S_ISREG(entry1->type)) {
- if (S_ISREG(entry2->type) == 0) return (-1);
+ if (!S_ISREG(entry2->type)) {
+ return -1;
+ }
}
- else {
- if (S_ISREG(entry2->type)) return (1);
+ else if (S_ISREG(entry2->type)) {
+ return 1;
}
- if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
- if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
+ if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return -1;
+ if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return 1;
/* make sure "." and ".." are always first */
- if (FILENAME_IS_CURRENT(entry1->relname)) return (-1);
- if (FILENAME_IS_CURRENT(entry2->relname)) return (1);
- if (FILENAME_IS_PARENT(entry1->relname)) return (-1);
- if (FILENAME_IS_PARENT(entry2->relname)) return (1);
+ if (FILENAME_IS_CURRENT(entry1->relname)) return -1;
+ if (FILENAME_IS_CURRENT(entry2->relname)) return 1;
+ if (FILENAME_IS_PARENT(entry1->relname)) return -1;
+ if (FILENAME_IS_PARENT(entry2->relname)) return 1;
return 0;
}
@@ -325,15 +330,15 @@ static int compare_date(const void *a1, const void *a2)
{
const struct direntry *entry1 = a1, *entry2 = a2;
int ret;
-
+
if ((ret = compare_direntry_generic(entry1, entry2))) {
return ret;
}
if (entry1->s.st_mtime < entry2->s.st_mtime) return 1;
if (entry1->s.st_mtime > entry2->s.st_mtime) return -1;
-
- else return BLI_natstrcmp(entry1->relname, entry2->relname);
+
+ return BLI_natstrcmp(entry1->relname, entry2->relname);
}
static int compare_size(const void *a1, const void *a2)
@@ -347,7 +352,8 @@ static int compare_size(const void *a1, const void *a2)
if (entry1->s.st_size < entry2->s.st_size) return 1;
if (entry1->s.st_size > entry2->s.st_size) return -1;
- else return BLI_natstrcmp(entry1->relname, entry2->relname);
+
+ return BLI_natstrcmp(entry1->relname, entry2->relname);
}
static int compare_extension(const void *a1, const void *a2)
@@ -368,7 +374,7 @@ static int compare_extension(const void *a1, const void *a2)
if (!sufix1) sufix1 = nil;
if (!sufix2) sufix2 = nil;
- return (BLI_strcasecmp(sufix1, sufix2));
+ return BLI_strcasecmp(sufix1, sufix2);
}
bool filelist_need_sorting(struct FileList *filelist)
@@ -521,7 +527,7 @@ void filelist_filter(FileList *filelist)
}
/* Note: maybe we could even accept filelist->fidx to be filelist->numfiles -len allocated? */
- filelist->fidx = (int *)MEM_mallocN(sizeof(*filelist->fidx) * (size_t)num_filtered, __func__);
+ filelist->fidx = MEM_mallocN(sizeof(*filelist->fidx) * (size_t)num_filtered, __func__);
memcpy(filelist->fidx, fidx_tmp, sizeof(*filelist->fidx) * (size_t)num_filtered);
filelist->numfiltered = num_filtered;
@@ -677,7 +683,8 @@ ImBuf *filelist_geticon(struct FileList *filelist, const int index)
FileList *filelist_new(short type)
{
- FileList *p = MEM_callocN(sizeof(FileList), "filelist");
+ FileList *p = MEM_callocN(sizeof(*p), __func__);
+
switch (type) {
case FILE_MAIN:
p->readf = filelist_read_main;
@@ -691,7 +698,6 @@ FileList *filelist_new(short type)
p->readf = filelist_read_dir;
p->filterf = is_filtered_file;
break;
-
}
return p;
}
@@ -890,9 +896,9 @@ static void filelist_setfiletypes(struct FileList *filelist)
{
struct direntry *file;
int num;
-
+
file = filelist->filelist;
-
+
for (num = 0; num < filelist->numfiles; num++, file++) {
file->type = file->s.st_mode; /* restore the mess below */
#ifndef __APPLE__
@@ -901,13 +907,14 @@ static void filelist_setfiletypes(struct FileList *filelist)
continue;
}
#endif
- file->flags = file_extension_type(filelist->dir, file->relname);
-
if (filelist->filter_data.filter_glob[0] &&
BLI_testextensie_glob(file->relname, filelist->filter_data.filter_glob))
{
file->flags = FILE_TYPE_OPERATOR;
}
+ else {
+ file->flags = file_extension_type(filelist->dir, file->relname);
+ }
}
}
@@ -1047,7 +1054,7 @@ static int groupname_to_code(const char *group)
{
char buf[BLO_GROUP_MAX];
char *lslash;
-
+
BLI_strncpy(buf, group, sizeof(buf));
lslash = (char *)BLI_last_slash(buf);
if (lslash)
@@ -1063,7 +1070,7 @@ static void filelist_from_library(struct FileList *filelist)
int ok, i, nprevs, nnames, idcode;
char filename[FILE_MAX];
char dir[FILE_MAX], group[BLO_GROUP_MAX];
-
+
/* name test */
ok = filelist_islibrary(filelist, dir, group);
if (!ok) {
@@ -1119,14 +1126,14 @@ static void filelist_from_library(struct FileList *filelist)
filelist->filelist[i + 1].type |= S_IFDIR;
}
}
-
+
if (previews && (nnames != nprevs)) {
printf("filelist_from_library: error, found %d items, %d previews\n", nnames, nprevs);
}
else if (previews) {
for (i = 0, l = previews; i < nnames; i++, l = l->next) {
PreviewImage *img = l->link;
-
+
if (img) {
unsigned int w = img->w[ICON_SIZE_PREVIEW];
unsigned int h = img->h[ICON_SIZE_PREVIEW];
@@ -1144,7 +1151,9 @@ static void filelist_from_library(struct FileList *filelist)
}
BLI_linklist_free(names, free);
- if (previews) BLI_linklist_free(previews, BKE_previewimg_freefunc);
+ if (previews) {
+ BLI_linklist_free(previews, BKE_previewimg_freefunc);
+ }
BLI_strncpy(G.main->name, filename, sizeof(filename)); /* prevent G.main->name to change */
}
@@ -1155,31 +1164,30 @@ static void filelist_from_main(struct FileList *filelist)
struct direntry *files, *firstlib = NULL;
ListBase *lb;
int a, fake, idcode, ok, totlib, totbl;
-
+
// filelist->type = FILE_MAIN; // XXXXX TODO: add modes to filebrowser
if (filelist->dir[0] == '/') filelist->dir[0] = 0;
-
+
if (filelist->dir[0]) {
idcode = groupname_to_code(filelist->dir);
if (idcode == 0) filelist->dir[0] = 0;
}
-
+
if (filelist->dir[0] == 0) {
-
/* make directories */
#ifdef WITH_FREESTYLE
filelist->numfiles = 24;
#else
filelist->numfiles = 23;
#endif
- filelist->filelist = (struct direntry *)MEM_mallocN(filelist->numfiles * sizeof(struct direntry), __func__);
-
+ filelist->filelist = MEM_mallocN(sizeof(*filelist->filelist) * filelist->numfiles, __func__);
+
for (a = 0; a < filelist->numfiles; a++) {
memset(&(filelist->filelist[a]), 0, sizeof(struct direntry));
filelist->filelist[a].type |= S_IFDIR;
}
-
+
filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
filelist->filelist[1].relname = BLI_strdup("Scene");
filelist->filelist[2].relname = BLI_strdup("Object");
@@ -1208,41 +1216,35 @@ static void filelist_from_main(struct FileList *filelist)
#endif
}
else {
-
/* make files */
idcode = groupname_to_code(filelist->dir);
-
+
lb = which_libbase(G.main, idcode);
if (lb == NULL) return;
-
- id = lb->first;
+
filelist->numfiles = 0;
- while (id) {
+ for (id = lb->first; id; id = id->next) {
if (!filelist->filter_data.hide_dot || id->name[2] != '.') {
filelist->numfiles++;
}
-
- id = id->next;
}
-
+
/* XXXXX TODO: if databrowse F4 or append/link filelist->hide_parent has to be set */
if (!filelist->filter_data.hide_parent) filelist->numfiles += 1;
- filelist->filelist = filelist->numfiles > 0 ? (struct direntry *)MEM_mallocN(filelist->numfiles * sizeof(struct direntry), __func__) : NULL;
+ filelist->filelist = filelist->numfiles > 0 ? MEM_mallocN(sizeof(*filelist->filelist) * filelist->numfiles, __func__) : NULL;
files = filelist->filelist;
-
+
if (!filelist->filter_data.hide_parent) {
memset(&(filelist->filelist[0]), 0, sizeof(struct direntry));
filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
filelist->filelist[0].type |= S_IFDIR;
-
+
files++;
}
-
- id = lb->first;
+
totlib = totbl = 0;
-
- while (id) {
+ for (id = lb->first; id; id = id->next) {
ok = 1;
if (ok) {
if (!filelist->filter_data.hide_dot || id->name[2] != '.') {
@@ -1251,7 +1253,7 @@ static void filelist_from_main(struct FileList *filelist)
files->relname = BLI_strdup(id->name + 2);
}
else {
- files->relname = MEM_mallocN(FILE_MAX + (MAX_ID_NAME - 2), "filename for lib");
+ files->relname = MEM_mallocN(sizeof(*files->relname) * (FILE_MAX + (MAX_ID_NAME - 2)), __func__);
BLI_snprintf(files->relname, FILE_MAX + (MAX_ID_NAME - 2) + 3, "%s | %s", id->lib->name, id->name + 2);
}
files->type |= S_IFREG;
@@ -1275,20 +1277,18 @@ static void filelist_from_main(struct FileList *filelist)
else if (id->lib) BLI_snprintf(files->extra, sizeof(files->extra), "L %d", id->us);
else if (fake) BLI_snprintf(files->extra, sizeof(files->extra), "F %d", id->us);
else BLI_snprintf(files->extra, sizeof(files->extra), " %d", id->us);
-
+
if (id->lib) {
if (totlib == 0) firstlib = files;
totlib++;
}
-
+
files++;
}
totbl++;
}
-
- id = id->next;
}
-
+
/* only qsort of library blocks */
if (totlib > 1) {
qsort(firstlib, totlib, sizeof(struct direntry), compare_name);
@@ -1362,13 +1362,15 @@ static void thumbnails_update(void *tjv)
FileImage *limg = tj->loadimages.first;
while (limg) {
if (!limg->done && limg->img) {
- tj->filelist->filelist[limg->index].image = limg->img;
+ tj->filelist->filelist[limg->index].image = IMB_dupImBuf(limg->img);
/* update flag for movie files where thumbnail can't be created */
if (limg->flags & FILE_TYPE_MOVIE_ICON) {
tj->filelist->filelist[limg->index].flags &= ~FILE_TYPE_MOVIE;
tj->filelist->filelist[limg->index].flags |= FILE_TYPE_MOVIE_ICON;
}
limg->done = true;
+ IMB_freeImBuf(limg->img);
+ limg->img = NULL;
}
limg = limg->next;
}
@@ -1397,17 +1399,20 @@ void thumbnails_start(FileList *filelist, const bContext *C)
wmJob *wm_job;
ThumbnailJob *tj;
int idx;
-
+
/* prepare job data */
- tj = MEM_callocN(sizeof(ThumbnailJob), "thumbnails\n");
+ tj = MEM_callocN(sizeof(*tj), __func__);
tj->filelist = filelist;
for (idx = 0; idx < filelist->numfiles; idx++) {
+ if (!filelist->filelist[idx].path) {
+ continue;
+ }
if (!filelist->filelist[idx].image) {
if (filelist->filelist[idx].flags & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE |
FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP))
{
- FileImage *limg = MEM_callocN(sizeof(FileImage), "loadimage");
- BLI_strncpy(limg->path, filelist->filelist[idx].path, FILE_MAX);
+ FileImage *limg = MEM_callocN(sizeof(*limg), __func__);
+ BLI_strncpy(limg->path, filelist->filelist[idx].path, sizeof(limg->path));
limg->index = idx;
limg->flags = filelist->filelist[idx].flags;
BLI_addtail(&tj->loadimages, limg);