[Bf-blender-cvs] [5fbd899] asset-experiments: Merge branch 'master' into asset-experiments
Bastien Montagne
noreply at git.blender.org
Fri Jun 12 10:43:00 CEST 2015
Commit: 5fbd8997c2486ff0ce4d188a8bb699a334448d1b
Author: Bastien Montagne
Date: Fri Jun 12 10:42:44 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rB5fbd8997c2486ff0ce4d188a8bb699a334448d1b
Merge branch 'master' into asset-experiments
Conflicts:
source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/filelist.c
===================================================================
===================================================================
diff --cc source/blender/editors/space_file/file_ops.c
index 99d1dba,db93000..279d600
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@@ -221,6 -215,23 +221,24 @@@ static FileSelect file_select_do(bConte
return retval;
}
+ /**
+ * \warning: loops over all files so better use cautiously
+ */
+ static bool file_is_any_selected(struct FileList *files)
+ {
+ const int numfiles = filelist_numfiles(files);
+ int i;
+
++ /* Is any file selected ? */
+ for (i = 0; i < numfiles; ++i) {
- if (filelist_is_selected(files, i, CHECK_ALL)) {
++ if (filelist_entry_select_index_get(files, i, CHECK_ALL)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
{
@@@ -236,9 -247,9 +254,9 @@@
if (sel.first != sel.last) select = 0;
/* Do we have a valid selection and are we actually selecting */
- if ((sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE))) {
+ if ((sel.last >= 0) && (select != FILE_SEL_REMOVE)) {
/* Check last selection, if selected, act on the file or dir */
- if (filelist_is_selected(sfile->files, sel.last, check_type)) {
+ if (filelist_entry_select_index_get(sfile->files, sel.last, check_type)) {
retval = file_select_do(C, sel.last, do_diropen);
}
}
@@@ -478,10 -476,12 +483,12 @@@ static bool file_walk_select_selection_
int active = active_old; /* could use active_old instead, just for readability */
bool deselect = false;
+ BLI_assert(params);
+
if (has_selection) {
if (extend &&
- filelist_is_selected(files, active_old, FILE_SEL_SELECTED) &&
- filelist_is_selected(files, active_new, FILE_SEL_SELECTED))
+ filelist_entry_select_index_get(files, active_old, FILE_SEL_SELECTED) &&
+ filelist_entry_select_index_get(files, active_new, FILE_SEL_SELECTED))
{
/* conditions for deselecting: initial file is selected, new file is
* selected and either other_side isn't selected/found or we use fill */
@@@ -686,7 -685,8 +693,8 @@@ static int file_select_all_exec(bContex
/* select all only if previously no file was selected */
if (has_selection) {
- filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+ filelist_entries_select_index_range_set(sfile->files, &sel, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+ sfile->params->active_file = -1;
}
else {
const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
diff --cc source/blender/editors/space_file/filelist.c
index d23ad74,4048c9f..d95f128
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@@ -2040,136 -1062,91 +2040,136 @@@ static int groupname_to_code(const cha
return buf[0] ? BKE_idcode_from_name(buf) : 0;
}
-static void filelist_from_library(struct FileList *filelist)
+static unsigned int groupname_to_filter_id(const char *group)
+{
+ int id_code = groupname_to_code(group);
+
+ return BKE_idcode_to_idfilter(id_code);
+}
+
+/*
+ * From here, we are in 'Job Context', i.e. have to be careful about sharing stuff between bacground working thread
+ * and main one (used by UI among other things).
+ */
+
+typedef struct TodoDir {
+ int level;
+ char *dir;
+} TodoDir;
+
+static int filelist_readjob_list_dir(
+ const char *root, ListBase *entries, const char *filter_glob,
+ const bool do_lib, const char *main_name, const bool skip_currpar)
+{
+ struct direntry *files;
+ int nbr_files, nbr_entries = 0;
+
+ nbr_files = BLI_filelist_dir_contents(root, &files);
+ if (files) {
+ int i = nbr_files;
+ while (i--) {
+ FileListInternEntry *entry;
+
+ if (skip_currpar && FILENAME_IS_CURRPAR(files[i].relname)) {
+ continue;
+ }
+
+ entry = MEM_callocN(sizeof(*entry), __func__);
+ entry->relpath = MEM_dupallocN(files[i].relname);
+ if (S_ISDIR(files[i].s.st_mode)) {
+ entry->typeflag |= FILE_TYPE_DIR;
+ }
+ entry->st = files[i].s;
+
+ /* Set file type. */
+ /* If we are considering .blend files as libs, promote them to directory status! */
+ if (do_lib && BLO_has_bfile_extension(entry->relpath)) {
+ char name[FILE_MAX];
+
+ entry->typeflag = FILE_TYPE_BLENDER;
+
+ BLI_join_dirfile(name, sizeof(name), root, entry->relpath);
+
+ /* prevent current file being used as acceptable dir */
+ if (BLI_path_cmp(main_name, name) != 0) {
+ entry->typeflag |= FILE_TYPE_DIR;
+ }
+ }
+ /* Otherwise, do not check extensions for directories! */
+ else if (!(entry->typeflag & FILE_TYPE_DIR)) {
+ if (filter_glob[0] && BLI_testextensie_glob(entry->relpath, filter_glob)) {
+ entry->typeflag = FILE_TYPE_OPERATOR;
+ }
+ else {
+ entry->typeflag = file_extension_type(root, entry->relpath);
+ }
+ }
+
+ BLI_addtail(entries, entry);
+ nbr_entries++;
+ }
+ BLI_filelist_free(files, nbr_files);
+ }
+ return nbr_entries;
+}
+
+static int filelist_readjob_list_lib(const char *root, ListBase *entries, const bool skip_currpar)
{
- LinkNode *l, *names, *previews;
- struct ImBuf *ima;
- int ok, i, nprevs, nnames, idcode;
- char filename[FILE_MAX];
- char dir[FILE_MAX], group[BLO_GROUP_MAX];
+ FileListInternEntry *entry;
+ LinkNode *ln, *names;
+ int i, nnames, idcode = 0, nbr_entries = 0;
+ char dir[FILE_MAX], *group;
+ bool ok;
+
+ struct BlendHandle *libfiledata = NULL;
/* name test */
- ok = filelist_islibrary(filelist, dir, group);
+ ok = BLO_library_path_explode(root, dir, &group, NULL);
if (!ok) {
- /* free */
- if (filelist->libfiledata) BLO_blendhandle_close(filelist->libfiledata);
- filelist->libfiledata = NULL;
- return;
+ return nbr_entries;
}
-
- BLI_strncpy(filename, G.main->name, sizeof(filename));
/* there we go */
- /* for the time being only read filedata when libfiledata==0 */
- if (filelist->libfiledata == NULL) {
- filelist->libfiledata = BLO_blendhandle_from_file(dir, NULL);
- if (filelist->libfiledata == NULL) return;
+ libfiledata = BLO_blendhandle_from_file(dir, NULL);
+ if (libfiledata == NULL) {
+ return nbr_entries;
}
-
- idcode = groupname_to_code(group);
-
- /* memory for strings is passed into filelist[i].relname
- * and freed in freefilelist */
- if (idcode) {
- previews = BLO_blendhandle_get_previews(filelist->libfiledata, idcode, &nprevs);
- names = BLO_blendhandle_get_datablock_names(filelist->libfiledata, idcode, &nnames);
- /* ugh, no rewind, need to reopen */
- BLO_blendhandle_close(filelist->libfiledata);
- filelist->libfiledata = BLO_blendhandle_from_file(dir, NULL);
-
+
+ /* memory for strings is passed into filelist[i].entry->relpath and freed in filelist_entry_free. */
+ if (group) {
+ idcode = groupname_to_code(group);
+ names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, &nnames);
}
else {
- previews = NULL;
- nprevs = 0;
- names = BLO_blendhandle_get_linkable_groups(filelist->libfiledata);
+ names = BLO_blendhandle_get_linkable_groups(libfiledata);
- nnames = BLI_linklist_length(names);
+ nnames = BLI_linklist_count(names);
}
- filelist->numfiles = nnames + 1;
- filelist->filelist = MEM_mallocN(filelist->numfiles * sizeof(*filelist->filelist), __func__);
- memset(filelist->filelist, 0, filelist->numfiles * sizeof(*filelist->filelist));
-
- filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
- filelist->filelist[0].type |= S_IFDIR;
-
- for (i = 0, l = names; i < nnames; i++, l = l->next) {
- const char *blockname = l->link;
-
- filelist->filelist[i + 1].relname = BLI_strdup(blockname);
- if (idcode) {
- filelist->filelist[i + 1].type |= S_IFREG;
- }
- else {
- filelist->filelist[i + 1].type |= S_IFDIR;
- }
- }
+ BLO_blendhandle_close(libfiledata);
- if (previews && (nnames != nprevs)) {
- printf("filelist_from_library: error, found %d items, %d previews\n", nnames, nprevs);
+ if (!skip_currpar) {
+ entry = MEM_callocN(sizeof(*entry), __func__);
+ entry->relpath = BLI_strdup(FILENAME_PARENT);
+ entry->typeflag |= (FILE_TYPE_BLENDERLIB | FILE_TYPE_DIR);
+ BLI_addtail(entries, entry);
+ nbr_entries++;
}
- else if (previews) {
- for (i = 0, l = previews; i < nnames; i++, l = l->next) {
- PreviewImage *img = l->link;
- if (img) {
- unsigned int w = img->w[ICON_SIZE_PREVIEW];
- unsigned int h = img->h[ICON_SIZE_PREVIEW];
- unsigned int *rect = img->rect[ICON_SIZE_PREVIEW];
+ for (i = 0, ln = names; i < nnames; i++, ln = ln->next) {
+ const char *blockname = ln->link;
- /* first allocate imbuf for copying preview into it */
- if (w > 0 && h > 0 && rect) {
- ima = IMB_allocImBuf(w, h, 32, IB_rect);
- memcpy(ima->rect, rect, w * h * sizeof(unsigned int));
- filelist->filelist[i + 1].image = ima;
- filelist->filelist[i + 1].flags = FILE_TYPE_IMAGE;
- }
- }
+ entry = MEM_callocN(sizeof(*entry), __func__);
+ entry->relpath = BLI_strdup(blockname);
+ entry->typeflag |= FILE_TYPE_BLENDERLIB;
+ if (!(group && idcode)) {
+ entry->typeflag |= FILE_TYPE_DIR;
+ entry->blentype = groupname_to_code(blockname);
+ }
+ else {
+ entry->blentype = idcode;
}
+ BLI_addtail(entries, entry);
+ nbr_entries++;
}
BLI_linklist_free(names, free);
More information about the Bf-blender-cvs
mailing list