[Bf-blender-cvs] [6b07e8e] asset-experiments: Take IDTypes into account when sorting by types.
Bastien Montagne
noreply at git.blender.org
Mon Dec 8 16:43:07 CET 2014
Commit: 6b07e8e31d05464919e23c8d04f1af46cef1c375
Author: Bastien Montagne
Date: Mon Dec 8 16:40:43 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rB6b07e8e31d05464919e23c8d04f1af46cef1c375
Take IDTypes into account when sorting by types.
Also:
* Changed BLO_library_path_explode, now r_group and r_name must be pointers of char pointer,
if found they will point to right place in r_dir 'memspace'.
* Select everything in IDTypes filtering by default.
===================================================================
M source/blender/blenloader/BLO_readfile.h
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/space_file/file_draw.c
M source/blender/editors/space_file/file_ops.c
M source/blender/editors/space_file/filelist.c
M source/blender/editors/space_file/filelist.h
M source/blender/editors/space_file/filesel.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index cb0e90b..bf3f32c 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -205,7 +205,7 @@ bool BLO_has_bfile_extension(const char *str);
* \param r_name the string that'll contain data's name part of the path, if any. May be NULL.
* \return true if path contains a blend file.
*/
-bool BLO_library_path_explode(const char *path, char *r_dir, char *r_group, char *r_name);
+bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name);
/**
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9072fed..d470010 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1146,7 +1146,7 @@ bool BLO_has_bfile_extension(const char *str)
return BLI_testextensie_array(str, ext_test);
}
-bool BLO_library_path_explode(const char *path, char *r_dir, char *r_group, char *r_name)
+bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
{
/* We might get some data names with slashes, so we have to go up in path until we find blend file itself,
* then we now next path item is group, and everything else is data name. */
@@ -1154,10 +1154,10 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char *r_group, char
r_dir[0] = '\0';
if (r_group) {
- r_group[0] = '\0';
+ *r_group = NULL;
}
if (r_name) {
- r_name[0] = '\0';
+ *r_name = NULL;
}
/* if path leads to an existing directory or file, we can be sure we're not in a library */
@@ -1183,17 +1183,17 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char *r_group, char
return false;
}
- if (slash) {
- BLI_assert(strlen(slash + 1) <= BLO_GROUP_MAX);
+ if (slash[1] != '\0') {
+ BLI_assert(strlen(slash + 1) < BLO_GROUP_MAX);
if (r_group) {
- strcpy(r_group, slash + 1);
+ *r_group = slash + 1;
}
}
- if (prev_slash) {
- BLI_assert(strlen(prev_slash + 1) <= MAX_ID_NAME - 2);
+ if (prev_slash && (prev_slash[1] != '\0')) {
+ BLI_assert(strlen(prev_slash + 1) < MAX_ID_NAME - 2);
if (r_name) {
- strcpy(r_name, prev_slash + 1);
+ *r_name = prev_slash + 1;
}
}
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 1d90237..eb4e571 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -471,7 +471,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
align = (FILE_IMGDISPLAY == params->display) ? UI_STYLE_TEXT_CENTER : UI_STYLE_TEXT_LEFT;
for (i = offset; (i < numfiles) && (i < offset + numfiles_layout); i++) {
- char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], group[BLO_GROUP_MAX], name_buff[MAX_ID_NAME], *name;
+ char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], *group, *name;
ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
sx += (int)(v2d->tot.xmin + 0.1f * UI_UNIT_X);
sy = (int)(v2d->tot.ymax - sy);
@@ -479,8 +479,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
file = filelist_file(files, i);
BLI_join_dirfile(path, sizeof(path), filelist_dir(files), file->relname);
- if (BLO_library_path_explode(path, dir, group, name_buff)) {
- name = (name_buff[0] != '\0') ? name_buff : group;
+ if (BLO_library_path_explode(path, dir, &group, &name)) {
+ if (!name) {
+ name = group;
+ }
+ BLI_assert(name);
}
else {
name = file->relname;
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 02cd76b..39e1837 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -868,7 +868,7 @@ int file_parent_exec(bContext *C, wmOperator *UNUSED(unused))
BLI_cleanup_dir(G.main->name, sfile->params->dir);
/* if not browsing in .blend file, we still want to check whether the path is a directory */
if (sfile->params->type == FILE_LOADLIB) {
- char tdir[FILE_MAX], tgroup[FILE_MAX];
+ char tdir[FILE_MAX];
if (BLO_library_path_explode(sfile->params->dir, tdir, NULL, NULL)) {
file_change_dir(C, 0);
}
@@ -1348,7 +1348,7 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
}
else if (sfile->params->type == FILE_LOADLIB) {
- char tdir[FILE_MAX], tgroup[FILE_MAX];
+ char tdir[FILE_MAX];
BLI_add_slash(filepath);
if (BLO_library_path_explode(filepath, tdir, NULL, NULL)) {
BLI_cleanup_dir(G.main->name, filepath);
@@ -1525,8 +1525,8 @@ static int file_rename_poll(bContext *C)
poll = 0;
}
else {
- char dir[FILE_MAX], group[FILE_MAX];
- if (filelist_islibrary(sfile->files, dir, group)) poll = 0;
+ char dir[FILE_MAX];
+ if (filelist_islibrary(sfile->files, dir, NULL)) poll = 0;
}
}
else
@@ -1553,12 +1553,12 @@ static int file_delete_poll(bContext *C)
SpaceFile *sfile = CTX_wm_space_file(C);
if (sfile && sfile->params) {
- char dir[FILE_MAX], group[FILE_MAX];
+ char dir[FILE_MAX];
int numfiles = filelist_numfiles(sfile->files);
int i;
int num_selected = 0;
- if (filelist_islibrary(sfile->files, dir, group)) poll = 0;
+ if (filelist_islibrary(sfile->files, dir, NULL)) poll = 0;
for (i = 0; i < numfiles; i++) {
if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
num_selected++;
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 5397a46..a849c1f 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -290,6 +290,34 @@ static int compare_extension(const void *a1, const void *a2)
else {
if (compare_is_directory(entry2)) return (1);
}
+
+ if ((entry1->flags & BLENDERLIB) && !(entry2->flags & BLENDERLIB)) return -1;
+ if (!(entry1->flags & BLENDERLIB) && (entry2->flags & BLENDERLIB)) return 1;
+ if ((entry1->flags & BLENDERLIB) && (entry2->flags & BLENDERLIB)) {
+ char lib1[FILE_MAX_LIBEXTRA], lib2[FILE_MAX_LIBEXTRA];
+ char *group1, *group2, *name1, *name2;
+ int grp_comp;
+
+ BLO_library_path_explode(entry1->path, lib1, &group1, &name1);
+ BLO_library_path_explode(entry2->path, lib2, &group2, &name2);
+
+ BLI_assert(group1);
+ BLI_assert(group2);
+
+ grp_comp = strcmp(group1, group2);
+ if (grp_comp != 0 || (!name1 && !name2)) {
+ return grp_comp;
+ }
+
+ if (!name1) {
+ return -1;
+ }
+ if (!name2) {
+ return 1;
+ }
+ return BLI_strcasecmp(name1, name2);
+ }
+
if (S_ISREG(entry1->type)) {
if (S_ISREG(entry2->type) == 0) return (-1);
}
@@ -298,13 +326,13 @@ static int compare_extension(const void *a1, const void *a2)
}
if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
-
+
/* make sure "." and ".." are always first */
if (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);
-
+
return (BLI_strcasecmp(sufix1, sufix2));
}
@@ -449,13 +477,14 @@ static bool is_hidden_file(const char *filename, const bool hide_dot)
static bool is_filtered_file(struct direntry *file, const char *UNUSED(root), FileListFilter *filter)
{
- bool is_filtered = false;
- if (filter->filter) {
- if (file->flags & filter->filter) {
- is_filtered = true;
+ bool is_filtered = !is_hidden_file(file->relname, filter->hide_dot);
+
+ if (is_filtered && filter->filter && !FILENAME_IS_BREADCRUMBS(file->relname)) {
+ if ((file->type & S_IFDIR) && !(filter->filter & FOLDERFILE)) {
+ is_filtered = false;
}
- else if ((file->type & S_IFDIR) && ((filter->filter & FOLDERFILE) || FILENAME_IS_BREADCRUMBS(file->relname))) {
- is_filtered = true;
+ if (!(file->type & S_IFDIR) && !(file->flags & filter->filter)) {
+ is_filtered = false;
}
if (is_filtered && (filter->filter_search[0] != '\0')) {
if (fnmatch(filter->filter_search, file->relname, FNM_CASEFOLD) != 0) {
@@ -463,29 +492,21 @@ static bool is_filtered_file(struct direntry *file, const char *UNUSED(root), Fi
}
}
}
- else {
- is_filtered = true;
- }
- if (is_filtered) {
- is_filtered = !is_hidden_file(file->relname, filter->hide_dot);
- }
return is_filtered;
}
static bool is_filtered_lib(struct direntry *file, const char *root, FileListFilter *filter)
{
- bool is_filtered = false;
- char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], group[BLO_GROUP_MAX];
+ bool is_filtered;
+ char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], *group;
BLI_join_dirfile(path, sizeof(path), root, file->relname);
- if (BLO_library_path_explode(path, dir, group, NULL)) {
+ if (BLO_library_path_explode(path, dir, &group, NULL)) {
is_filtered = !is_hidden_file(file->relname, filter->hide_dot);
- if (filter->filter) {
- if (is_filtered && (file->type & S_IFDIR) && !(filter->filter & FOLDERFILE) &&
- !FILENAME_IS_BREADCRUMBS(file->relname))
- {
+ if (is_filtered && filter->filter && !FILENAME_IS_BREADCRUMBS(file->relname)) {
+ if ((file->type & S_IFDIR) && !(filter->filter & FOLDERFILE)) {
is_filtered = false;
}
if (is_filtered && (filter->filter_search[0] != '\0')) {
@@ -493,7 +514,7 @@ static bool is_filtered_lib(struct direntry *file, const char *root, FileListFil
is_filtered = false;
}
}
- if (is_filtered && group[0] != '\0') {
+ if (is_filtered && group) {
unsigned int filter_id = groupname_to_filter_id(group);
if (!(filter_id & filter->filter_id)) {
is_filtered = false;
@@ -777,11 +798,11 @@ int filelist_geticon(struct FileList *filelist, const int index)
else if (file->flags & TEXTFILE)
return ICON_FILE_TEXT;
else {
- char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], group[BLO_GROUP_MAX];
+ char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], *group;
BLI_join_dirfile(path, sizeof(path), filelist->dir, file->relname);
- if (BLO_library_path
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list