2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-18 19:21:30 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-18 19:21:30 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2007 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_file/filelist.c
|
|
|
|
* \ingroup spfile
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
/* global includes */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#else
|
|
|
|
#include <io.h>
|
|
|
|
#include <direct.h>
|
|
|
|
#endif
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_linklist.h"
|
2009-01-18 18:24:11 +00:00
|
|
|
#include "BLI_threads.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2013-03-05 03:44:47 +00:00
|
|
|
#include "BLI_fileops_types.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-04-15 07:54:07 +00:00
|
|
|
# include "BLI_winstuff.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
#endif
|
|
|
|
|
2010-03-10 19:30:20 +00:00
|
|
|
#include "BKE_context.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_library.h"
|
2011-05-18 19:42:30 +00:00
|
|
|
#include "BKE_icons.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
#include "BKE_main.h"
|
2009-09-12 19:54:39 +00:00
|
|
|
#include "BKE_report.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
#include "BLO_readfile.h"
|
2010-08-10 15:14:19 +00:00
|
|
|
#include "BKE_idcode.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
#include "ED_fileselect.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "ED_datafiles.h"
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "IMB_thumbs.h"
|
|
|
|
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
2010-03-10 19:30:20 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2010-12-17 19:05:34 +00:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
#include "filelist.h"
|
|
|
|
|
|
|
|
/* max length of library group name within filesel */
|
|
|
|
#define GROUP_MAX 32
|
|
|
|
|
2009-01-18 18:24:11 +00:00
|
|
|
struct FileList;
|
|
|
|
|
|
|
|
typedef struct FileImage {
|
|
|
|
struct FileImage *next, *prev;
|
2010-03-10 19:30:20 +00:00
|
|
|
char path[FILE_MAX];
|
|
|
|
unsigned int flags;
|
2009-01-18 18:24:11 +00:00
|
|
|
int index;
|
|
|
|
short done;
|
2010-03-10 19:30:20 +00:00
|
|
|
ImBuf *img;
|
2009-01-18 18:24:11 +00:00
|
|
|
} FileImage;
|
|
|
|
|
2010-03-10 19:30:20 +00:00
|
|
|
typedef struct ThumbnailJob {
|
|
|
|
ListBase loadimages;
|
|
|
|
short *stop;
|
|
|
|
short *do_update;
|
2012-06-18 13:01:24 +00:00
|
|
|
struct FileList *filelist;
|
2010-03-10 19:30:20 +00:00
|
|
|
ReportList reports;
|
|
|
|
} ThumbnailJob;
|
|
|
|
|
2012-06-06 22:38:39 +00:00
|
|
|
typedef struct FileList {
|
2008-12-18 19:21:30 +00:00
|
|
|
struct direntry *filelist;
|
|
|
|
int *fidx;
|
|
|
|
int numfiles;
|
|
|
|
int numfiltered;
|
|
|
|
char dir[FILE_MAX];
|
|
|
|
short prv_w;
|
|
|
|
short prv_h;
|
|
|
|
short hide_dot;
|
|
|
|
unsigned int filter;
|
2010-09-24 07:05:43 +00:00
|
|
|
char filter_glob[64];
|
2009-01-18 18:24:11 +00:00
|
|
|
short changed;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
struct BlendHandle *libfiledata;
|
|
|
|
short hide_parent;
|
|
|
|
|
2010-03-20 14:23:56 +00:00
|
|
|
void (*readf)(struct FileList *);
|
2012-06-18 13:01:24 +00:00
|
|
|
int (*filterf)(struct direntry *file, const char *dir, unsigned int filter, short hide_dot);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
} FileList;
|
|
|
|
|
2012-06-06 22:38:39 +00:00
|
|
|
typedef struct FolderList {
|
2009-07-07 07:25:44 +00:00
|
|
|
struct FolderList *next, *prev;
|
|
|
|
char *foldername;
|
|
|
|
} FolderList;
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
#define SPECIAL_IMG_SIZE 48
|
|
|
|
#define SPECIAL_IMG_ROWS 4
|
|
|
|
#define SPECIAL_IMG_COLS 4
|
|
|
|
|
|
|
|
#define SPECIAL_IMG_FOLDER 0
|
|
|
|
#define SPECIAL_IMG_PARENT 1
|
|
|
|
#define SPECIAL_IMG_REFRESH 2
|
|
|
|
#define SPECIAL_IMG_BLENDFILE 3
|
|
|
|
#define SPECIAL_IMG_SOUNDFILE 4
|
|
|
|
#define SPECIAL_IMG_MOVIEFILE 5
|
|
|
|
#define SPECIAL_IMG_PYTHONFILE 6
|
|
|
|
#define SPECIAL_IMG_TEXTFILE 7
|
|
|
|
#define SPECIAL_IMG_FONTFILE 8
|
|
|
|
#define SPECIAL_IMG_UNKNOWNFILE 9
|
2009-03-11 23:22:07 +00:00
|
|
|
#define SPECIAL_IMG_LOADING 10
|
2012-10-27 18:31:52 +00:00
|
|
|
#define SPECIAL_IMG_BACKUP 11
|
|
|
|
#define SPECIAL_IMG_MAX SPECIAL_IMG_BACKUP + 1
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static ImBuf *gSpecialFileImages[SPECIAL_IMG_MAX];
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ******************* SORT ******************* */
|
|
|
|
|
2013-08-28 21:50:13 +00:00
|
|
|
static bool compare_is_directory(const struct direntry *entry)
|
|
|
|
{
|
|
|
|
/* for library browse .blend files may be treated as directories, but
|
|
|
|
* for sorting purposes they should be considered regular files */
|
|
|
|
if (S_ISDIR(entry->type))
|
2013-08-28 23:49:22 +00:00
|
|
|
return !(entry->flags & (BLENDERFILE | BLENDERFILE_BACKUP));
|
2013-08-28 21:50:13 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
static int compare_name(const void *a1, const void *a2)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
const struct direntry *entry1 = a1, *entry2 = a2;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2010-04-25 15:24:18 +00:00
|
|
|
/* type is equal to stat.st_mode */
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry1)) {
|
|
|
|
if (compare_is_directory(entry2) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry2)) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (S_ISREG(entry1->type)) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (S_ISREG(entry2->type) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-12-18 19:21:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* make sure "." and ".." are always first */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (strcmp(entry1->relname, ".") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, ".") == 0) return (1);
|
|
|
|
if (strcmp(entry1->relname, "..") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, "..") == 0) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
return (BLI_natstrcmp(entry1->relname, entry2->relname));
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_date(const void *a1, const void *a2)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
const struct direntry *entry1 = a1, *entry2 = a2;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
/* type is equal to stat.st_mode */
|
|
|
|
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry1)) {
|
|
|
|
if (compare_is_directory(entry2) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry2)) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (S_ISREG(entry1->type)) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (S_ISREG(entry2->type) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-12-18 19:21:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* make sure "." and ".." are always first */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (strcmp(entry1->relname, ".") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, ".") == 0) return (1);
|
|
|
|
if (strcmp(entry1->relname, "..") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, "..") == 0) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (entry1->s.st_mtime < entry2->s.st_mtime) return 1;
|
|
|
|
if (entry1->s.st_mtime > entry2->s.st_mtime) return -1;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
else return BLI_natstrcmp(entry1->relname, entry2->relname);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_size(const void *a1, const void *a2)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
const struct direntry *entry1 = a1, *entry2 = a2;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
/* type is equal to stat.st_mode */
|
|
|
|
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry1)) {
|
|
|
|
if (compare_is_directory(entry2) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry2)) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (S_ISREG(entry1->type)) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (S_ISREG(entry2->type) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-12-18 19:21:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* make sure "." and ".." are always first */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (strcmp(entry1->relname, ".") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, ".") == 0) return (1);
|
|
|
|
if (strcmp(entry1->relname, "..") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, "..") == 0) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (entry1->s.st_size < entry2->s.st_size) return 1;
|
|
|
|
if (entry1->s.st_size > entry2->s.st_size) return -1;
|
2012-04-29 15:47:02 +00:00
|
|
|
else return BLI_natstrcmp(entry1->relname, entry2->relname);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
static int compare_extension(const void *a1, const void *a2)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
const struct direntry *entry1 = a1, *entry2 = a2;
|
2010-12-03 17:05:21 +00:00
|
|
|
const char *sufix1, *sufix2;
|
2012-06-18 13:01:24 +00:00
|
|
|
const char *nil = "";
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (!(sufix1 = strstr(entry1->relname, ".blend.gz")))
|
|
|
|
sufix1 = strrchr(entry1->relname, '.');
|
|
|
|
if (!(sufix2 = strstr(entry2->relname, ".blend.gz")))
|
|
|
|
sufix2 = strrchr(entry2->relname, '.');
|
|
|
|
if (!sufix1) sufix1 = nil;
|
|
|
|
if (!sufix2) sufix2 = nil;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2010-04-25 15:24:18 +00:00
|
|
|
/* type is equal to stat.st_mode */
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry1)) {
|
|
|
|
if (compare_is_directory(entry2) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-28 21:50:13 +00:00
|
|
|
if (compare_is_directory(entry2)) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (S_ISREG(entry1->type)) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (S_ISREG(entry2->type) == 0) return (-1);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-12-18 19:21:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* make sure "." and ".." are always first */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (strcmp(entry1->relname, ".") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, ".") == 0) return (1);
|
|
|
|
if (strcmp(entry1->relname, "..") == 0) return (-1);
|
|
|
|
if (strcmp(entry2->relname, "..") == 0) return (1);
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
return (BLI_strcasecmp(sufix1, sufix2));
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static int is_hidden_file(const char *filename, short hide_dot)
|
2010-03-20 14:23:56 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
int is_hidden = 0;
|
2010-03-20 14:23:56 +00:00
|
|
|
|
|
|
|
if (hide_dot) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (filename[0] == '.' && filename[1] != '.' && filename[1] != 0) {
|
|
|
|
is_hidden = 1; /* ignore .file */
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (((filename[0] == '.') && (filename[1] == 0) )) {
|
2012-06-18 13:01:24 +00:00
|
|
|
is_hidden = 1; /* ignore . */
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-18 13:01:24 +00:00
|
|
|
int len = strlen(filename);
|
|
|
|
if ( (len > 0) && (filename[len - 1] == '~') ) {
|
|
|
|
is_hidden = 1; /* ignore file~ */
|
2010-03-20 14:23:56 +00:00
|
|
|
}
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-03-20 14:23:56 +00:00
|
|
|
if (((filename[0] == '.') && (filename[1] == 0) )) {
|
2012-06-18 13:01:24 +00:00
|
|
|
is_hidden = 1; /* ignore . */
|
2010-03-20 14:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return is_hidden;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static int is_filtered_file(struct direntry *file, const char *UNUSED(dir), unsigned int filter, short hide_dot)
|
2010-03-20 14:23:56 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
int is_filtered = 0;
|
2010-03-20 14:23:56 +00:00
|
|
|
if (filter) {
|
|
|
|
if (file->flags & filter) {
|
2012-06-18 13:01:24 +00:00
|
|
|
is_filtered = 1;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (file->type & S_IFDIR) {
|
2010-03-20 14:23:56 +00:00
|
|
|
if (filter & FOLDERFILE) {
|
|
|
|
is_filtered = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-03-20 14:23:56 +00:00
|
|
|
is_filtered = 1;
|
|
|
|
}
|
|
|
|
return is_filtered && !is_hidden_file(file->relname, hide_dot);
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static int is_filtered_lib(struct direntry *file, const char *dir, unsigned int filter, short hide_dot)
|
2010-03-20 14:23:56 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
int is_filtered = 0;
|
2010-03-20 14:23:56 +00:00
|
|
|
char tdir[FILE_MAX], tgroup[GROUP_MAX];
|
|
|
|
if (BLO_is_a_library(dir, tdir, tgroup)) {
|
|
|
|
is_filtered = !is_hidden_file(file->relname, hide_dot);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-03-20 14:23:56 +00:00
|
|
|
is_filtered = is_filtered_file(file, dir, filter, hide_dot);
|
|
|
|
}
|
|
|
|
return is_filtered;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static int is_filtered_main(struct direntry *file, const char *UNUSED(dir), unsigned int UNUSED(filter), short hide_dot)
|
2010-03-20 14:23:56 +00:00
|
|
|
{
|
|
|
|
return !is_hidden_file(file->relname, hide_dot);
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_filter(FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
int num_filtered = 0;
|
|
|
|
int i, j;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
if (!filelist->filelist)
|
|
|
|
return;
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* How many files are left after filter ? */
|
2008-12-18 19:21:30 +00:00
|
|
|
for (i = 0; i < filelist->numfiles; ++i) {
|
2010-03-20 14:23:56 +00:00
|
|
|
struct direntry *file = &filelist->filelist[i];
|
2012-06-18 13:01:24 +00:00
|
|
|
if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
|
2008-12-18 19:21:30 +00:00
|
|
|
num_filtered++;
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (filelist->fidx) {
|
2010-03-20 14:23:56 +00:00
|
|
|
MEM_freeN(filelist->fidx);
|
|
|
|
filelist->fidx = NULL;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->fidx = (int *)MEM_callocN(num_filtered * sizeof(int), "filteridx");
|
2008-12-18 19:21:30 +00:00
|
|
|
filelist->numfiltered = num_filtered;
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0, j = 0; i < filelist->numfiles; ++i) {
|
2010-03-20 14:23:56 +00:00
|
|
|
struct direntry *file = &filelist->filelist[i];
|
2012-06-18 13:01:24 +00:00
|
|
|
if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
|
2008-12-18 19:21:30 +00:00
|
|
|
filelist->fidx[j++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-17 19:05:34 +00:00
|
|
|
void filelist_init_icons(void)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
short x, y, k;
|
|
|
|
ImBuf *bbuf;
|
|
|
|
ImBuf *ibuf;
|
2012-08-08 08:25:20 +00:00
|
|
|
|
|
|
|
BLI_assert(G.background == FALSE);
|
|
|
|
|
2011-06-05 07:55:18 +00:00
|
|
|
#ifdef WITH_HEADLESS
|
|
|
|
bbuf = NULL;
|
|
|
|
#else
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_prvicons_png, datatoc_prvicons_png_size, IB_rect, NULL, "<splash>");
|
2011-06-05 07:55:18 +00:00
|
|
|
#endif
|
2008-12-18 19:21:30 +00:00
|
|
|
if (bbuf) {
|
2012-06-18 13:01:24 +00:00
|
|
|
for (y = 0; y < SPECIAL_IMG_ROWS; y++) {
|
|
|
|
for (x = 0; x < SPECIAL_IMG_COLS; x++) {
|
|
|
|
int tile = SPECIAL_IMG_COLS * y + x;
|
2008-12-18 19:21:30 +00:00
|
|
|
if (tile < SPECIAL_IMG_MAX) {
|
2010-10-16 14:32:17 +00:00
|
|
|
ibuf = IMB_allocImBuf(SPECIAL_IMG_SIZE, SPECIAL_IMG_SIZE, 32, IB_rect);
|
2012-06-18 13:01:24 +00:00
|
|
|
for (k = 0; k < SPECIAL_IMG_SIZE; k++) {
|
|
|
|
memcpy(&ibuf->rect[k * SPECIAL_IMG_SIZE], &bbuf->rect[(k + y * SPECIAL_IMG_SIZE) * SPECIAL_IMG_SIZE * SPECIAL_IMG_COLS + x * SPECIAL_IMG_SIZE], SPECIAL_IMG_SIZE * sizeof(int));
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
gSpecialFileImages[tile] = ibuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IMB_freeImBuf(bbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-17 19:05:34 +00:00
|
|
|
void filelist_free_icons(void)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
int i;
|
2012-08-08 08:25:20 +00:00
|
|
|
|
|
|
|
BLI_assert(G.background == FALSE);
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0; i < SPECIAL_IMG_MAX; ++i) {
|
2008-12-18 19:21:30 +00:00
|
|
|
IMB_freeImBuf(gSpecialFileImages[i]);
|
|
|
|
gSpecialFileImages[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* -----------------FOLDERLIST (previous/next) -------------- */
|
2012-06-18 13:01:24 +00:00
|
|
|
ListBase *folderlist_new(void)
|
2009-07-07 07:25:44 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ListBase *p = MEM_callocN(sizeof(ListBase), "folderlist");
|
2009-07-07 07:25:44 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void folderlist_popdir(struct ListBase *folderlist, char *dir)
|
2009-07-07 07:25:44 +00:00
|
|
|
{
|
|
|
|
const char *prev_dir;
|
|
|
|
struct FolderList *folder;
|
|
|
|
folder = folderlist->last;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (folder) {
|
2012-07-06 23:56:59 +00:00
|
|
|
/* remove the current directory */
|
2009-07-07 07:25:44 +00:00
|
|
|
MEM_freeN(folder->foldername);
|
|
|
|
BLI_freelinkN(folderlist, folder);
|
|
|
|
|
|
|
|
folder = folderlist->last;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (folder) {
|
2009-07-07 07:25:44 +00:00
|
|
|
prev_dir = folder->foldername;
|
|
|
|
BLI_strncpy(dir, prev_dir, FILE_MAXDIR);
|
|
|
|
}
|
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
/* delete the folder next or use setdir directly before PREVIOUS OP */
|
2009-07-07 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void folderlist_pushdir(ListBase *folderlist, const char *dir)
|
2009-07-07 07:25:44 +00:00
|
|
|
{
|
|
|
|
struct FolderList *folder, *previous_folder;
|
|
|
|
previous_folder = folderlist->last;
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* check if already exists */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (previous_folder && previous_folder->foldername) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (BLI_path_cmp(previous_folder->foldername, dir) == 0) {
|
2009-07-07 07:25:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* create next folder element */
|
2012-06-18 13:01:24 +00:00
|
|
|
folder = (FolderList *)MEM_mallocN(sizeof(FolderList), "FolderList");
|
2013-07-15 05:11:14 +00:00
|
|
|
folder->foldername = BLI_strdup(dir);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* add it to the end of the list */
|
2009-07-07 07:25:44 +00:00
|
|
|
BLI_addtail(folderlist, folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
int folderlist_clear_next(struct SpaceFile *sfile)
|
|
|
|
{
|
|
|
|
struct FolderList *folder;
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* if there is no folder_next there is nothing we can clear */
|
2009-07-07 07:25:44 +00:00
|
|
|
if (!sfile->folders_next)
|
|
|
|
return 0;
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* if previous_folder, next_folder or refresh_folder operators are executed it doesn't clear folder_next */
|
2009-07-07 07:25:44 +00:00
|
|
|
folder = sfile->folders_prev->last;
|
2012-06-18 13:01:24 +00:00
|
|
|
if ((!folder) || (BLI_path_cmp(folder->foldername, sfile->params->dir) == 0))
|
2009-07-07 07:25:44 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* eventually clear flist->folders_next */
|
2009-07-07 07:25:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
/* not listbase itself */
|
2012-06-18 13:01:24 +00:00
|
|
|
void folderlist_free(ListBase *folderlist)
|
2009-07-07 07:25:44 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (folderlist) {
|
2011-04-25 09:28:52 +00:00
|
|
|
FolderList *folder;
|
2012-06-18 13:01:24 +00:00
|
|
|
for (folder = folderlist->first; folder; folder = folder->next)
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
MEM_freeN(folder->foldername);
|
|
|
|
BLI_freelistN(folderlist);
|
2009-07-07 07:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
ListBase *folderlist_duplicate(ListBase *folderlist)
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (folderlist) {
|
2012-06-18 13:01:24 +00:00
|
|
|
ListBase *folderlistn = MEM_callocN(sizeof(ListBase), "copy folderlist");
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
FolderList *folder;
|
|
|
|
|
|
|
|
BLI_duplicatelist(folderlistn, folderlist);
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
for (folder = folderlistn->first; folder; folder = folder->next) {
|
|
|
|
folder->foldername = MEM_dupallocN(folder->foldername);
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
}
|
|
|
|
return folderlistn;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void filelist_read_main(struct FileList *filelist);
|
|
|
|
static void filelist_read_library(struct FileList *filelist);
|
|
|
|
static void filelist_read_dir(struct FileList *filelist);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* ------------------FILELIST------------------------ */
|
2012-06-18 13:01:24 +00:00
|
|
|
FileList *filelist_new(short type)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
FileList *p = MEM_callocN(sizeof(FileList), "filelist");
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (type) {
|
2009-09-12 19:54:39 +00:00
|
|
|
case FILE_MAIN:
|
2010-03-20 14:23:56 +00:00
|
|
|
p->readf = filelist_read_main;
|
|
|
|
p->filterf = is_filtered_main;
|
2009-09-12 19:54:39 +00:00
|
|
|
break;
|
|
|
|
case FILE_LOADLIB:
|
2010-03-20 14:23:56 +00:00
|
|
|
p->readf = filelist_read_library;
|
|
|
|
p->filterf = is_filtered_lib;
|
2009-09-12 19:54:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-03-20 14:23:56 +00:00
|
|
|
p->readf = filelist_read_dir;
|
|
|
|
p->filterf = is_filtered_file;
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
2008-12-18 19:21:30 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_free(struct FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
if (!filelist) {
|
2009-07-07 07:25:44 +00:00
|
|
|
printf("Attempting to delete empty filelist.\n");
|
2008-12-18 19:21:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-18 18:24:11 +00:00
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
if (filelist->fidx) {
|
|
|
|
MEM_freeN(filelist->fidx);
|
|
|
|
filelist->fidx = NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-05 03:44:47 +00:00
|
|
|
BLI_free_filelist(filelist->filelist, filelist->numfiles);
|
2008-12-18 19:21:30 +00:00
|
|
|
filelist->numfiles = 0;
|
2012-10-21 05:46:41 +00:00
|
|
|
filelist->filelist = NULL;
|
2008-12-18 19:21:30 +00:00
|
|
|
filelist->filter = 0;
|
2010-09-24 07:05:43 +00:00
|
|
|
filelist->filter_glob[0] = '\0';
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->numfiltered = 0;
|
|
|
|
filelist->hide_dot = 0;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_freelib(struct FileList *filelist)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (filelist->libfiledata)
|
2009-09-12 19:54:39 +00:00
|
|
|
BLO_blendhandle_close(filelist->libfiledata);
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->libfiledata = NULL;
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
BlendHandle *filelist_lib(struct FileList *filelist)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
return filelist->libfiledata;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
int filelist_numfiles(struct FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
return filelist->numfiltered;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
const char *filelist_dir(struct FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
return filelist->dir;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_setdir(struct FileList *filelist, const char *dir)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2012-01-21 14:48:07 +00:00
|
|
|
BLI_strncpy(filelist->dir, dir, sizeof(filelist->dir));
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_imgsize(struct FileList *filelist, short w, short h)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
filelist->prv_w = w;
|
|
|
|
filelist->prv_h = h;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
short filelist_changed(struct FileList *filelist)
|
2009-01-18 18:24:11 +00:00
|
|
|
{
|
|
|
|
return filelist->changed;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
ImBuf *filelist_getimage(struct FileList *filelist, int index)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ImBuf *ibuf = NULL;
|
2012-08-08 08:25:20 +00:00
|
|
|
int fidx = 0;
|
|
|
|
|
|
|
|
BLI_assert(G.background == FALSE);
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
if ( (index < 0) || (index >= filelist->numfiltered) ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fidx = filelist->fidx[index];
|
|
|
|
ibuf = filelist->filelist[fidx].image;
|
|
|
|
|
2009-03-11 23:22:07 +00:00
|
|
|
return ibuf;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
ImBuf *filelist_geticon(struct FileList *filelist, int index)
|
2009-03-11 23:22:07 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
struct direntry *file = NULL;
|
2012-08-08 08:25:20 +00:00
|
|
|
int fidx = 0;
|
|
|
|
|
|
|
|
BLI_assert(G.background == FALSE);
|
|
|
|
|
2009-03-11 23:22:07 +00:00
|
|
|
if ( (index < 0) || (index >= filelist->numfiltered) ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fidx = filelist->fidx[index];
|
|
|
|
file = &filelist->filelist[fidx];
|
|
|
|
if (file->type & S_IFDIR) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (strcmp(filelist->filelist[fidx].relname, "..") == 0) {
|
2010-03-15 20:28:13 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2012-04-21 12:51:47 +00:00
|
|
|
else if (strcmp(filelist->filelist[fidx].relname, ".") == 0) {
|
2010-03-15 20:28:13 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_REFRESH];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-03-15 20:28:13 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_FOLDER];
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_UNKNOWNFILE];
|
|
|
|
}
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-03-11 23:22:07 +00:00
|
|
|
if (file->flags & BLENDERFILE) {
|
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_BLENDFILE];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if ( (file->flags & MOVIEFILE) || (file->flags & MOVIEFILE_ICON) ) {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_MOVIEFILE];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (file->flags & SOUNDFILE) {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_SOUNDFILE];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (file->flags & PYSCRIPTFILE) {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_PYTHONFILE];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (file->flags & FTFONTFILE) {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_FONTFILE];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (file->flags & TEXTFILE) {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_TEXTFILE];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (file->flags & IMAGEFILE) {
|
2009-03-11 23:22:07 +00:00
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_LOADING];
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2012-10-27 18:31:52 +00:00
|
|
|
else if (file->flags & BLENDERFILE_BACKUP) {
|
|
|
|
ibuf = gSpecialFileImages[SPECIAL_IMG_BACKUP];
|
|
|
|
}
|
2009-03-11 23:22:07 +00:00
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
return ibuf;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
struct direntry *filelist_file(struct FileList *filelist, int index)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
int fidx = 0;
|
|
|
|
|
|
|
|
if ( (index < 0) || (index >= filelist->numfiltered) ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fidx = filelist->fidx[index];
|
|
|
|
|
|
|
|
return &filelist->filelist[fidx];
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
int filelist_find(struct FileList *filelist, const char *filename)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
int i;
|
|
|
|
int fidx = -1;
|
|
|
|
|
|
|
|
if (!filelist->fidx)
|
|
|
|
return fidx;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < filelist->numfiles; ++i) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (strcmp(filelist->filelist[i].relname, filename) == 0) { /* not dealing with user input so don't need BLI_path_cmp */
|
2008-12-18 19:21:30 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < filelist->numfiltered; ++i) {
|
|
|
|
if (filelist->fidx[i] == index) {
|
|
|
|
fidx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fidx;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_hidedot(struct FileList *filelist, short hide)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
filelist->hide_dot = hide;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_setfilter(struct FileList *filelist, unsigned int filter)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
filelist->filter = filter;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_setfilter_types(struct FileList *filelist, const char *filter_glob)
|
2010-09-24 07:05:43 +00:00
|
|
|
{
|
|
|
|
BLI_strncpy(filelist->filter_glob, filter_glob, sizeof(filelist->filter_glob));
|
|
|
|
}
|
|
|
|
|
2012-11-06 20:29:14 +00:00
|
|
|
/* would recognize .blend as well */
|
2011-01-30 13:12:03 +00:00
|
|
|
static int file_is_blend_backup(const char *str)
|
|
|
|
{
|
|
|
|
short a, b;
|
2012-06-18 13:01:24 +00:00
|
|
|
int retval = 0;
|
2011-01-30 13:12:03 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
a = strlen(str);
|
|
|
|
b = 7;
|
2011-01-30 13:12:03 +00:00
|
|
|
|
2012-10-07 09:48:59 +00:00
|
|
|
if (a == 0 || b >= a) {
|
|
|
|
/* pass */
|
|
|
|
}
|
2011-01-30 13:12:03 +00:00
|
|
|
else {
|
|
|
|
char *loc;
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (a > b + 1)
|
2011-01-30 13:12:03 +00:00
|
|
|
b++;
|
|
|
|
|
|
|
|
/* allow .blend1 .blend2 .blend32 */
|
2012-06-18 13:01:24 +00:00
|
|
|
loc = BLI_strcasestr(str + a - b, ".blend");
|
2011-01-30 13:12:03 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (loc)
|
2012-06-18 13:01:24 +00:00
|
|
|
retval = 1;
|
2011-01-30 13:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:00:55 +00:00
|
|
|
static int path_extension_type(const char *path)
|
2010-12-17 19:05:34 +00:00
|
|
|
{
|
2013-10-31 21:00:55 +00:00
|
|
|
if (BLO_has_bfile_extension(path)) {
|
2010-12-17 19:05:34 +00:00
|
|
|
return BLENDERFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (file_is_blend_backup(path)) {
|
2011-01-30 13:12:03 +00:00
|
|
|
return BLENDERFILE_BACKUP;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie(path, ".py")) {
|
2010-12-17 19:05:34 +00:00
|
|
|
return PYSCRIPTFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie(path, ".txt") ||
|
|
|
|
BLI_testextensie(path, ".glsl") ||
|
|
|
|
BLI_testextensie(path, ".osl") ||
|
|
|
|
BLI_testextensie(path, ".data"))
|
2012-04-21 15:11:03 +00:00
|
|
|
{
|
2010-12-17 19:05:34 +00:00
|
|
|
return TEXTFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie(path, ".ttf") ||
|
|
|
|
BLI_testextensie(path, ".ttc") ||
|
|
|
|
BLI_testextensie(path, ".pfb") ||
|
|
|
|
BLI_testextensie(path, ".otf") ||
|
|
|
|
BLI_testextensie(path, ".otc"))
|
2012-04-21 15:11:03 +00:00
|
|
|
{
|
2012-10-21 05:46:41 +00:00
|
|
|
return FTFONTFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie(path, ".btx")) {
|
2010-12-17 19:05:34 +00:00
|
|
|
return BTXFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie(path, ".dae")) {
|
2010-12-17 19:05:34 +00:00
|
|
|
return COLLADAFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie_array(path, imb_ext_image) ||
|
|
|
|
(G.have_quicktime && BLI_testextensie_array(path, imb_ext_image_qt)))
|
2012-04-21 15:11:03 +00:00
|
|
|
{
|
2012-10-21 05:46:41 +00:00
|
|
|
return IMAGEFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie(path, ".ogg")) {
|
|
|
|
if (IMB_isanim(path)) {
|
|
|
|
return MOVIEFILE;
|
2013-10-31 23:52:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-10-31 21:00:55 +00:00
|
|
|
return SOUNDFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (BLI_testextensie_array(path, imb_ext_movie)) {
|
2012-10-21 05:46:41 +00:00
|
|
|
return MOVIEFILE;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
else if (BLI_testextensie_array(path, imb_ext_audio)) {
|
2010-12-17 19:05:34 +00:00
|
|
|
return SOUNDFILE;
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2010-12-17 19:05:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:00:55 +00:00
|
|
|
static int file_extension_type(const char *dir, const char *relname)
|
|
|
|
{
|
|
|
|
char path[FILE_MAX];
|
|
|
|
BLI_join_dirfile(path, sizeof(path), dir, relname);
|
|
|
|
return path_extension_type(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ED_file_extension_icon(const char *path)
|
2010-12-17 19:05:34 +00:00
|
|
|
{
|
2013-10-31 21:00:55 +00:00
|
|
|
int type = path_extension_type(path);
|
2010-12-17 19:05:34 +00:00
|
|
|
|
2012-10-27 18:31:52 +00:00
|
|
|
if (type == BLENDERFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_BLEND;
|
2012-10-27 18:31:52 +00:00
|
|
|
else if (type == BLENDERFILE_BACKUP)
|
|
|
|
return ICON_FILE_BACKUP;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == IMAGEFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_IMAGE;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == MOVIEFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_MOVIE;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == PYSCRIPTFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_SCRIPT;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == SOUNDFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_SOUND;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == FTFONTFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_FONT;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == BTXFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_BLANK;
|
2012-06-23 23:22:19 +00:00
|
|
|
else if (type == COLLADAFILE)
|
2010-12-17 19:05:34 +00:00
|
|
|
return ICON_FILE_BLANK;
|
2012-10-27 17:47:58 +00:00
|
|
|
else if (type == TEXTFILE)
|
|
|
|
return ICON_FILE_TEXT;
|
2010-12-17 19:05:34 +00:00
|
|
|
|
|
|
|
return ICON_FILE_BLANK;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void filelist_setfiletypes(struct FileList *filelist)
|
2010-12-17 19:05:34 +00:00
|
|
|
{
|
|
|
|
struct direntry *file;
|
|
|
|
int num;
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
file = filelist->filelist;
|
2010-12-17 19:05:34 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
for (num = 0; num < filelist->numfiles; num++, file++) {
|
2012-06-23 23:22:19 +00:00
|
|
|
file->type = file->s.st_mode; /* restore the mess below */
|
2010-12-17 19:05:34 +00:00
|
|
|
|
|
|
|
/* Don't check extensions for directories */
|
|
|
|
if (file->type & S_IFDIR) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-31 21:00:55 +00:00
|
|
|
file->flags = file_extension_type(filelist->dir, file->relname);
|
2010-12-17 19:05:34 +00:00
|
|
|
|
2013-07-13 14:16:59 +00:00
|
|
|
if (filelist->filter_glob[0] &&
|
2012-04-21 15:11:03 +00:00
|
|
|
BLI_testextensie_glob(file->relname, filelist->filter_glob))
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
file->flags = OPERATORFILE;
|
2010-12-17 19:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void filelist_read_dir(struct FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
if (!filelist) return;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2011-03-05 10:29:10 +00:00
|
|
|
filelist->fidx = NULL;
|
|
|
|
filelist->filelist = NULL;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_cleanup_dir(G.main->name, filelist->dir);
|
2011-10-22 15:35:49 +00:00
|
|
|
filelist->numfiles = BLI_dir_contents(filelist->dir, &(filelist->filelist));
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2010-12-17 19:05:34 +00:00
|
|
|
filelist_setfiletypes(filelist);
|
2009-03-11 23:22:07 +00:00
|
|
|
filelist_filter(filelist);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void filelist_read_main(struct FileList *filelist)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
if (!filelist) return;
|
|
|
|
filelist_from_main(filelist);
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void filelist_read_library(struct FileList *filelist)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
if (!filelist) return;
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_cleanup_dir(G.main->name, filelist->dir);
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist_from_library(filelist);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!filelist->libfiledata) {
|
2009-09-12 19:54:39 +00:00
|
|
|
int num;
|
|
|
|
struct direntry *file;
|
2009-09-20 18:26:02 +00:00
|
|
|
|
|
|
|
BLI_make_exist(filelist->dir);
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist_read_dir(filelist);
|
|
|
|
file = filelist->filelist;
|
2012-06-18 13:01:24 +00:00
|
|
|
for (num = 0; num < filelist->numfiles; num++, file++) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (BLO_has_bfile_extension(file->relname)) {
|
2011-11-26 13:11:55 +00:00
|
|
|
char name[FILE_MAX];
|
2012-01-21 14:48:07 +00:00
|
|
|
|
|
|
|
BLI_join_dirfile(name, sizeof(name), filelist->dir, file->relname);
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
/* prevent current file being used as acceptable dir */
|
2011-04-06 06:03:48 +00:00
|
|
|
if (BLI_path_cmp(G.main->name, name) != 0) {
|
2009-09-12 19:54:39 +00:00
|
|
|
file->type &= ~S_IFMT;
|
|
|
|
file->type |= S_IFDIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_readdir(struct FileList *filelist)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
2010-03-20 14:23:56 +00:00
|
|
|
filelist->readf(filelist);
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
int filelist_empty(struct FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2011-03-05 10:29:10 +00:00
|
|
|
return filelist->filelist == NULL;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_parent(struct FileList *filelist)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
BLI_parent_dir(filelist->dir);
|
|
|
|
BLI_make_exist(filelist->dir);
|
|
|
|
filelist_readdir(filelist);
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_select_file(struct FileList *filelist, int index, FileSelType select, unsigned int flag, FileCheckType check)
|
2011-03-20 15:15:05 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
struct direntry *file = filelist_file(filelist, index);
|
2012-10-21 05:46:41 +00:00
|
|
|
if (file != NULL) {
|
2011-03-20 15:15:05 +00:00
|
|
|
int check_ok = 0;
|
|
|
|
switch (check) {
|
|
|
|
case CHECK_DIRS:
|
2011-06-16 15:01:22 +00:00
|
|
|
check_ok = S_ISDIR(file->type);
|
|
|
|
break;
|
2011-03-20 15:15:05 +00:00
|
|
|
case CHECK_ALL:
|
|
|
|
check_ok = 1;
|
|
|
|
break;
|
|
|
|
case CHECK_FILES:
|
|
|
|
default:
|
|
|
|
check_ok = !S_ISDIR(file->type);
|
|
|
|
break;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2011-03-20 15:15:05 +00:00
|
|
|
if (check_ok) {
|
2011-03-20 10:22:51 +00:00
|
|
|
switch (select) {
|
|
|
|
case FILE_SEL_REMOVE:
|
2011-03-20 11:16:59 +00:00
|
|
|
file->selflag &= ~flag;
|
2011-03-20 10:22:51 +00:00
|
|
|
break;
|
|
|
|
case FILE_SEL_ADD:
|
2011-03-20 11:16:59 +00:00
|
|
|
file->selflag |= flag;
|
2011-03-20 10:22:51 +00:00
|
|
|
break;
|
|
|
|
case FILE_SEL_TOGGLE:
|
2011-03-20 11:16:59 +00:00
|
|
|
file->selflag ^= flag;
|
2011-03-20 10:22:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-03-14 19:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_select(struct FileList *filelist, FileSelection *sel, FileSelType select, unsigned int flag, FileCheckType check)
|
2011-03-20 15:15:05 +00:00
|
|
|
{
|
|
|
|
/* select all valid files between first and last indicated */
|
|
|
|
if ( (sel->first >= 0) && (sel->first < filelist->numfiltered) && (sel->last >= 0) && (sel->last < filelist->numfiltered) ) {
|
|
|
|
int current_file;
|
2012-10-21 05:46:41 +00:00
|
|
|
for (current_file = sel->first; current_file <= sel->last; current_file++) {
|
2011-03-20 15:15:05 +00:00
|
|
|
filelist_select_file(filelist, current_file, select, flag, check);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
int filelist_is_selected(struct FileList *filelist, int index, FileCheckType check)
|
2011-03-20 15:15:05 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
struct direntry *file = filelist_file(filelist, index);
|
2011-03-20 15:15:05 +00:00
|
|
|
if (!file) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (check) {
|
|
|
|
case CHECK_DIRS:
|
|
|
|
return S_ISDIR(file->type) && (file->selflag & SELECTED_FILE);
|
|
|
|
case CHECK_FILES:
|
|
|
|
return S_ISREG(file->type) && (file->selflag & SELECTED_FILE);
|
|
|
|
case CHECK_ALL:
|
|
|
|
default:
|
|
|
|
return (file->selflag & SELECTED_FILE);
|
|
|
|
}
|
|
|
|
}
|
2011-03-14 19:56:13 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_sort(struct FileList *filelist, short sort)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (sort) {
|
2012-06-18 13:01:24 +00:00
|
|
|
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);
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filelist_filter(filelist);
|
|
|
|
}
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
int filelist_islibrary(struct FileList *filelist, char *dir, char *group)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
return BLO_is_a_library(filelist->dir, dir, group);
|
|
|
|
}
|
|
|
|
|
2012-01-11 09:33:44 +00:00
|
|
|
static int groupname_to_code(const char *group)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
char *lslash;
|
|
|
|
|
2010-11-05 07:35:21 +00:00
|
|
|
BLI_strncpy(buf, group, sizeof(buf));
|
2013-03-04 19:27:51 +00:00
|
|
|
lslash = (char *)BLI_last_slash(buf);
|
2009-09-12 19:54:39 +00:00
|
|
|
if (lslash)
|
2012-06-18 13:01:24 +00:00
|
|
|
lslash[0] = '\0';
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2010-08-10 15:14:19 +00:00
|
|
|
return BKE_idcode_from_name(buf);
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
2011-05-18 19:42:30 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_from_library(struct FileList *filelist)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
LinkNode *l, *names, *previews;
|
2012-06-18 13:01:24 +00:00
|
|
|
struct ImBuf *ima;
|
2011-04-24 14:45:49 +00:00
|
|
|
int ok, i, nprevs, nnames, idcode;
|
2011-11-26 13:11:55 +00:00
|
|
|
char filename[FILE_MAX];
|
2012-10-21 05:46:41 +00:00
|
|
|
char dir[FILE_MAX], group[GROUP_MAX];
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
/* name test */
|
2012-06-18 13:01:24 +00:00
|
|
|
ok = filelist_islibrary(filelist, dir, group);
|
2009-09-12 19:54:39 +00:00
|
|
|
if (!ok) {
|
|
|
|
/* free */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (filelist->libfiledata) BLO_blendhandle_close(filelist->libfiledata);
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->libfiledata = NULL;
|
2009-09-12 19:54:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_strncpy(filename, G.main->name, sizeof(filename));
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
/* there we go */
|
|
|
|
/* for the time being only read filedata when libfiledata==0 */
|
2011-03-05 10:29:10 +00:00
|
|
|
if (filelist->libfiledata == NULL) {
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->libfiledata = BLO_blendhandle_from_file(dir, NULL);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (filelist->libfiledata == NULL) return;
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
idcode = groupname_to_code(group);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2011-04-24 14:45:49 +00:00
|
|
|
/* memory for strings is passed into filelist[i].relname
|
2012-03-09 00:41:09 +00:00
|
|
|
* and freed in freefilelist */
|
2009-09-12 19:54:39 +00:00
|
|
|
if (idcode) {
|
2012-06-18 13:01:24 +00:00
|
|
|
previews = BLO_blendhandle_get_previews(filelist->libfiledata, idcode, &nprevs);
|
|
|
|
names = BLO_blendhandle_get_datablock_names(filelist->libfiledata, idcode, &nnames);
|
2009-09-12 19:54:39 +00:00
|
|
|
/* ugh, no rewind, need to reopen */
|
|
|
|
BLO_blendhandle_close(filelist->libfiledata);
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->libfiledata = BLO_blendhandle_from_file(dir, NULL);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-18 13:01:24 +00:00
|
|
|
previews = NULL;
|
|
|
|
nprevs = 0;
|
|
|
|
names = BLO_blendhandle_get_linkable_groups(filelist->libfiledata);
|
|
|
|
nnames = BLI_linklist_length(names);
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->numfiles = nnames + 1;
|
|
|
|
filelist->filelist = malloc(filelist->numfiles * sizeof(*filelist->filelist));
|
2009-09-12 19:54:39 +00:00
|
|
|
memset(filelist->filelist, 0, filelist->numfiles * sizeof(*filelist->filelist));
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->filelist[0].relname = BLI_strdup("..");
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist->filelist[0].type |= S_IFDIR;
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0, l = names; i < nnames; i++, l = l->next) {
|
|
|
|
char *blockname = l->link;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->filelist[i + 1].relname = BLI_strdup(blockname);
|
2011-03-23 18:51:31 +00:00
|
|
|
if (idcode) {
|
|
|
|
filelist->filelist[i + 1].type |= S_IFREG;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist->filelist[i + 1].type |= S_IFDIR;
|
2011-03-23 18:51:31 +00:00
|
|
|
}
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (previews && (nnames != nprevs)) {
|
2011-04-24 14:45:49 +00:00
|
|
|
printf("filelist_from_library: error, found %d items, %d previews\n", nnames, nprevs);
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (previews) {
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0, l = previews; i < nnames; i++, l = l->next) {
|
|
|
|
PreviewImage *img = l->link;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
if (img) {
|
2011-05-16 18:37:54 +00:00
|
|
|
unsigned int w = img->w[ICON_SIZE_PREVIEW];
|
|
|
|
unsigned int h = img->h[ICON_SIZE_PREVIEW];
|
|
|
|
unsigned int *rect = img->rect[ICON_SIZE_PREVIEW];
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
/* first allocate imbuf for copying preview into it */
|
|
|
|
if (w > 0 && h > 0 && rect) {
|
2010-10-16 14:32:17 +00:00
|
|
|
ima = IMB_allocImBuf(w, h, 32, IB_rect);
|
2012-06-18 13:01:24 +00:00
|
|
|
memcpy(ima->rect, rect, w * h * sizeof(unsigned int));
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist->filelist[i + 1].image = ima;
|
|
|
|
filelist->filelist[i + 1].flags = IMAGEFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_linklist_free(names, free);
|
2011-05-18 19:42:30 +00:00
|
|
|
if (previews) BLI_linklist_free(previews, BKE_previewimg_freefunc);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
filelist_sort(filelist, FILE_SORT_ALPHA);
|
|
|
|
|
2012-06-23 23:22:19 +00:00
|
|
|
BLI_strncpy(G.main->name, filename, sizeof(filename)); /* prevent G.main->name to change */
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
filelist->filter = 0;
|
|
|
|
filelist_filter(filelist);
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
void filelist_hideparent(struct FileList *filelist, short hide)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
|
|
|
filelist->hide_parent = hide;
|
|
|
|
}
|
|
|
|
|
|
|
|
void filelist_from_main(struct FileList *filelist)
|
|
|
|
{
|
|
|
|
ID *id;
|
|
|
|
struct direntry *files, *firstlib = NULL;
|
|
|
|
ListBase *lb;
|
|
|
|
int a, fake, idcode, ok, totlib, totbl;
|
|
|
|
|
|
|
|
// filelist->type = FILE_MAIN; // XXXXX TODO: add modes to filebrowser
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (filelist->dir[0] == '/') filelist->dir[0] = 0;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (filelist->dir[0]) {
|
2012-06-18 13:01:24 +00:00
|
|
|
idcode = groupname_to_code(filelist->dir);
|
|
|
|
if (idcode == 0) filelist->dir[0] = 0;
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (filelist->dir[0] == 0) {
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
/* make directories */
|
2012-12-20 07:57:26 +00:00
|
|
|
#ifdef WITH_FREESTYLE
|
2012-06-24 10:29:26 +00:00
|
|
|
filelist->numfiles = 25;
|
2012-12-20 07:57:26 +00:00
|
|
|
#else
|
|
|
|
filelist->numfiles = 24;
|
|
|
|
#endif
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->filelist = (struct direntry *)malloc(filelist->numfiles * sizeof(struct direntry));
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
for (a = 0; a < filelist->numfiles; a++) {
|
2012-04-29 17:11:40 +00:00
|
|
|
memset(&(filelist->filelist[a]), 0, sizeof(struct direntry));
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist->filelist[a].type |= S_IFDIR;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->filelist[0].relname = BLI_strdup("..");
|
|
|
|
filelist->filelist[2].relname = BLI_strdup("Scene");
|
|
|
|
filelist->filelist[3].relname = BLI_strdup("Object");
|
|
|
|
filelist->filelist[4].relname = BLI_strdup("Mesh");
|
|
|
|
filelist->filelist[5].relname = BLI_strdup("Curve");
|
|
|
|
filelist->filelist[6].relname = BLI_strdup("Metaball");
|
|
|
|
filelist->filelist[7].relname = BLI_strdup("Material");
|
|
|
|
filelist->filelist[8].relname = BLI_strdup("Texture");
|
|
|
|
filelist->filelist[9].relname = BLI_strdup("Image");
|
|
|
|
filelist->filelist[10].relname = BLI_strdup("Ika");
|
|
|
|
filelist->filelist[11].relname = BLI_strdup("Wave");
|
|
|
|
filelist->filelist[12].relname = BLI_strdup("Lattice");
|
|
|
|
filelist->filelist[13].relname = BLI_strdup("Lamp");
|
|
|
|
filelist->filelist[14].relname = BLI_strdup("Camera");
|
|
|
|
filelist->filelist[15].relname = BLI_strdup("Ipo");
|
|
|
|
filelist->filelist[16].relname = BLI_strdup("World");
|
|
|
|
filelist->filelist[17].relname = BLI_strdup("Screen");
|
|
|
|
filelist->filelist[18].relname = BLI_strdup("VFont");
|
|
|
|
filelist->filelist[19].relname = BLI_strdup("Text");
|
|
|
|
filelist->filelist[20].relname = BLI_strdup("Armature");
|
|
|
|
filelist->filelist[21].relname = BLI_strdup("Action");
|
|
|
|
filelist->filelist[22].relname = BLI_strdup("NodeTree");
|
|
|
|
filelist->filelist[23].relname = BLI_strdup("Speaker");
|
2012-12-20 07:57:26 +00:00
|
|
|
#ifdef WITH_FREESTYLE
|
2012-12-11 22:00:22 +00:00
|
|
|
filelist->filelist[24].relname = BLI_strdup("FreestyleLineStyle");
|
2012-12-20 07:57:26 +00:00
|
|
|
#endif
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist_sort(filelist, FILE_SORT_ALPHA);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* make files */
|
2012-06-18 13:01:24 +00:00
|
|
|
idcode = groupname_to_code(filelist->dir);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
lb = which_libbase(G.main, idcode);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (lb == NULL) return;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
id = lb->first;
|
|
|
|
filelist->numfiles = 0;
|
2012-03-24 07:52:14 +00:00
|
|
|
while (id) {
|
2009-09-12 19:54:39 +00:00
|
|
|
if (!filelist->hide_dot || id->name[2] != '.') {
|
|
|
|
filelist->numfiles++;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
id = id->next;
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXXXX TODO: if databrowse F4 or append/link filelist->hide_parent has to be set */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (!filelist->hide_parent) filelist->numfiles += 1;
|
|
|
|
filelist->filelist = filelist->numfiles > 0 ? (struct direntry *)malloc(filelist->numfiles * sizeof(struct direntry)) : NULL;
|
2011-09-12 00:00:21 +00:00
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
files = filelist->filelist;
|
|
|
|
|
|
|
|
if (!filelist->hide_parent) {
|
2012-04-29 17:11:40 +00:00
|
|
|
memset(&(filelist->filelist[0]), 0, sizeof(struct direntry));
|
2012-06-18 13:01:24 +00:00
|
|
|
filelist->filelist[0].relname = BLI_strdup("..");
|
2009-09-12 19:54:39 +00:00
|
|
|
filelist->filelist[0].type |= S_IFDIR;
|
|
|
|
|
|
|
|
files++;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
id = lb->first;
|
|
|
|
totlib = totbl = 0;
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (id) {
|
2009-09-12 19:54:39 +00:00
|
|
|
ok = 1;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ok) {
|
2009-09-12 19:54:39 +00:00
|
|
|
if (!filelist->hide_dot || id->name[2] != '.') {
|
2012-04-29 15:47:02 +00:00
|
|
|
memset(files, 0, sizeof(struct direntry));
|
2012-10-14 03:56:47 +00:00
|
|
|
if (id->lib == NULL) {
|
2012-06-18 13:01:24 +00:00
|
|
|
files->relname = BLI_strdup(id->name + 2);
|
2012-10-14 03:56:47 +00:00
|
|
|
}
|
2009-09-12 19:54:39 +00:00
|
|
|
else {
|
2012-10-14 03:56:47 +00:00
|
|
|
files->relname = MEM_mallocN(FILE_MAX + (MAX_ID_NAME - 2), "filename for lib");
|
|
|
|
BLI_snprintf(files->relname, FILE_MAX + (MAX_ID_NAME - 2) + 3, "%s | %s", id->lib->name, id->name + 2);
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
2011-03-23 18:51:31 +00:00
|
|
|
files->type |= S_IFREG;
|
2012-10-20 20:20:02 +00:00
|
|
|
#if 0 /* XXXXX TODO show the selection status of the objects */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!filelist->has_func) { /* F4 DATA BROWSE */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (idcode == ID_OB) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if ( ((Object *)id)->flag & SELECT) files->selflag |= SELECTED_FILE;
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
2012-06-18 13:01:24 +00:00
|
|
|
else if (idcode == ID_SCE) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if ( ((Scene *)id)->r.scemode & R_BG_RENDER) files->selflag |= SELECTED_FILE;
|
2012-10-14 03:56:47 +00:00
|
|
|
}
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-06-18 13:01:24 +00:00
|
|
|
files->nr = totbl + 1;
|
|
|
|
files->poin = id;
|
|
|
|
fake = id->flag & LIB_FAKEUSER;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) {
|
2009-09-12 19:54:39 +00:00
|
|
|
files->flags |= IMAGEFILE;
|
|
|
|
}
|
2012-10-14 03:56:47 +00:00
|
|
|
if (id->lib && fake) BLI_snprintf(files->extra, sizeof(files->extra), "LF %d", id->us);
|
|
|
|
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);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (id->lib) {
|
2012-06-18 13:01:24 +00:00
|
|
|
if (totlib == 0) firstlib = files;
|
2009-09-12 19:54:39 +00:00
|
|
|
totlib++;
|
|
|
|
}
|
|
|
|
|
|
|
|
files++;
|
|
|
|
}
|
|
|
|
totbl++;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
id = id->next;
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* only qsort of library blocks */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (totlib > 1) {
|
2009-09-12 19:54:39 +00:00
|
|
|
qsort(firstlib, totlib, sizeof(struct direntry), compare_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filelist->filter = 0;
|
|
|
|
filelist_filter(filelist);
|
|
|
|
}
|
|
|
|
|
2010-03-10 19:30:20 +00:00
|
|
|
static void thumbnail_joblist_free(ThumbnailJob *tj)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
FileImage *limg = tj->loadimages.first;
|
2010-03-10 19:30:20 +00:00
|
|
|
|
|
|
|
/* free the images not yet copied to the filelist -> these will get freed with the filelist */
|
2012-06-18 13:01:24 +00:00
|
|
|
for (; limg; limg = limg->next) {
|
2010-03-10 19:30:20 +00:00
|
|
|
if ((limg->img) && (!limg->done)) {
|
|
|
|
IMB_freeImBuf(limg->img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_freelistN(&tj->loadimages);
|
|
|
|
}
|
|
|
|
|
2010-10-16 08:03:28 +00:00
|
|
|
static void thumbnails_startjob(void *tjv, short *stop, short *do_update, float *UNUSED(progress))
|
2010-03-10 19:30:20 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ThumbnailJob *tj = tjv;
|
|
|
|
FileImage *limg = tj->loadimages.first;
|
2010-03-10 19:30:20 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
tj->stop = stop;
|
|
|
|
tj->do_update = do_update;
|
2010-03-10 19:30:20 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
while ( (*stop == 0) && (limg) ) {
|
|
|
|
if (limg->flags & IMAGEFILE) {
|
2010-05-14 10:50:43 +00:00
|
|
|
limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_IMAGE);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2012-10-27 18:31:52 +00:00
|
|
|
else if (limg->flags & (BLENDERFILE | BLENDERFILE_BACKUP)) {
|
2010-05-24 21:52:18 +00:00
|
|
|
limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_BLEND);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2012-06-18 13:01:24 +00:00
|
|
|
else if (limg->flags & MOVIEFILE) {
|
2010-05-14 10:50:43 +00:00
|
|
|
limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_MOVIE);
|
|
|
|
if (!limg->img) {
|
2012-06-18 13:01:24 +00:00
|
|
|
/* remember that file can't be loaded via IMB_open_anim */
|
|
|
|
limg->flags &= ~MOVIEFILE;
|
|
|
|
limg->flags |= MOVIEFILE_ICON;
|
|
|
|
}
|
2010-03-10 19:30:20 +00:00
|
|
|
}
|
2012-05-19 13:28:19 +00:00
|
|
|
*do_update = TRUE;
|
2010-05-14 10:50:43 +00:00
|
|
|
PIL_sleep_ms(10);
|
|
|
|
limg = limg->next;
|
2010-03-10 19:30:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thumbnails_update(void *tjv)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ThumbnailJob *tj = tjv;
|
2010-03-10 19:30:20 +00:00
|
|
|
|
|
|
|
if (tj->filelist && tj->filelist->filelist) {
|
2012-06-18 13:01:24 +00:00
|
|
|
FileImage *limg = tj->loadimages.first;
|
2010-03-10 19:30:20 +00:00
|
|
|
while (limg) {
|
|
|
|
if (!limg->done && limg->img) {
|
|
|
|
tj->filelist->filelist[limg->index].image = limg->img;
|
2010-03-23 18:46:21 +00:00
|
|
|
/* update flag for movie files where thumbnail can't be created */
|
|
|
|
if (limg->flags & MOVIEFILE_ICON) {
|
|
|
|
tj->filelist->filelist[limg->index].flags &= ~MOVIEFILE;
|
|
|
|
tj->filelist->filelist[limg->index].flags |= MOVIEFILE_ICON;
|
|
|
|
}
|
2012-05-19 13:28:19 +00:00
|
|
|
limg->done = TRUE;
|
2010-03-10 19:30:20 +00:00
|
|
|
}
|
|
|
|
limg = limg->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thumbnails_free(void *tjv)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ThumbnailJob *tj = tjv;
|
2010-03-10 19:30:20 +00:00
|
|
|
thumbnail_joblist_free(tj);
|
|
|
|
MEM_freeN(tj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-15 19:56:29 +00:00
|
|
|
void thumbnails_start(FileList *filelist, const bContext *C)
|
2010-03-10 19:30:20 +00:00
|
|
|
{
|
2012-08-15 10:03:29 +00:00
|
|
|
wmJob *wm_job;
|
2010-03-10 19:30:20 +00:00
|
|
|
ThumbnailJob *tj;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/* prepare job data */
|
2012-06-18 13:01:24 +00:00
|
|
|
tj = MEM_callocN(sizeof(ThumbnailJob), "thumbnails\n");
|
2010-03-10 19:30:20 +00:00
|
|
|
tj->filelist = filelist;
|
2012-06-18 13:01:24 +00:00
|
|
|
for (idx = 0; idx < filelist->numfiles; idx++) {
|
2010-03-10 19:30:20 +00:00
|
|
|
if (!filelist->filelist[idx].image) {
|
2012-10-27 18:31:52 +00:00
|
|
|
if ( (filelist->filelist[idx].flags & (IMAGEFILE | MOVIEFILE | BLENDERFILE | BLENDERFILE_BACKUP)) ) {
|
2013-03-15 19:56:29 +00:00
|
|
|
FileImage *limg = MEM_callocN(sizeof(FileImage), "loadimage");
|
2010-04-29 18:53:01 +00:00
|
|
|
BLI_strncpy(limg->path, filelist->filelist[idx].path, FILE_MAX);
|
2012-06-18 13:01:24 +00:00
|
|
|
limg->index = idx;
|
|
|
|
limg->flags = filelist->filelist[idx].flags;
|
2010-03-10 19:30:20 +00:00
|
|
|
BLI_addtail(&tj->loadimages, limg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_reports_init(&tj->reports, RPT_PRINT);
|
|
|
|
|
|
|
|
/* setup job */
|
2012-08-15 10:03:29 +00:00
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), filelist, "Thumbnails",
|
|
|
|
0, WM_JOB_TYPE_FILESEL_THUMBNAIL);
|
|
|
|
WM_jobs_customdata_set(wm_job, tj, thumbnails_free);
|
|
|
|
WM_jobs_timer(wm_job, 0.5, NC_WINDOW, NC_WINDOW);
|
|
|
|
WM_jobs_callbacks(wm_job, thumbnails_startjob, NULL, thumbnails_update, NULL);
|
2010-03-10 19:30:20 +00:00
|
|
|
|
|
|
|
/* start the job */
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2010-03-10 19:30:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 19:56:29 +00:00
|
|
|
void thumbnails_stop(wmWindowManager *wm, FileList *filelist)
|
2010-03-10 19:30:20 +00:00
|
|
|
{
|
2013-03-15 19:56:29 +00:00
|
|
|
WM_jobs_kill(wm, filelist, NULL);
|
2010-03-30 11:38:06 +00:00
|
|
|
}
|
2010-05-14 10:50:43 +00:00
|
|
|
|
2013-03-15 19:56:29 +00:00
|
|
|
int thumbnails_running(wmWindowManager *wm, FileList *filelist)
|
2010-05-14 10:50:43 +00:00
|
|
|
{
|
2013-03-15 19:56:29 +00:00
|
|
|
return WM_jobs_test(wm, filelist, WM_JOB_TYPE_FILESEL_THUMBNAIL);
|
2010-05-24 21:52:18 +00:00
|
|
|
}
|