Fix [#21658] file browser "hide invisible" doesn't hide anything
- moved global hide_dot to filelist. - hiding dot files is now included in the filtering of files, which means that for this directory also doesn't have to be read anymore. - reverted changes of rev. 27491 and related changes in rev. 27523 in favor of a more general abstraction for the different 'file browser modes' with respect to filtering.
This commit is contained in:
@@ -50,7 +50,7 @@ int BLI_filesize(int file);
|
|||||||
int BLI_filepathsize(const char *path);
|
int BLI_filepathsize(const char *path);
|
||||||
double BLI_diskfree(char *dir);
|
double BLI_diskfree(char *dir);
|
||||||
char *BLI_getwdN(char *dir);
|
char *BLI_getwdN(char *dir);
|
||||||
void BLI_hide_dot_files(int set);
|
|
||||||
unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
|
unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
|
||||||
/**
|
/**
|
||||||
* @attention Do not confuse with BLI_exists
|
* @attention Do not confuse with BLI_exists
|
||||||
|
@@ -204,14 +204,6 @@ double BLI_diskfree(char *dir)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hide_dot= 0;
|
|
||||||
|
|
||||||
void BLI_hide_dot_files(int set)
|
|
||||||
{
|
|
||||||
if(set) hide_dot= 1;
|
|
||||||
else hide_dot= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BLI_builddir(char *dirname, char *relname)
|
void BLI_builddir(char *dirname, char *relname)
|
||||||
{
|
{
|
||||||
struct dirent *fname;
|
struct dirent *fname;
|
||||||
@@ -237,17 +229,12 @@ void BLI_builddir(char *dirname, char *relname)
|
|||||||
while ((fname = (struct dirent*) readdir(dir)) != NULL) {
|
while ((fname = (struct dirent*) readdir(dir)) != NULL) {
|
||||||
len= strlen(fname->d_name);
|
len= strlen(fname->d_name);
|
||||||
|
|
||||||
if(hide_dot && fname->d_name[0]=='.' && fname->d_name[1]!='.' && fname->d_name[1]!=0); /* ignore .file */
|
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
|
||||||
else if(hide_dot && len && fname->d_name[len-1]=='~'); /* ignore file~ */
|
if (dlink){
|
||||||
else if (((fname->d_name[0] == '.') && (fname->d_name[1] == 0) )); /* ignore . */
|
strcpy(buf+rellen,fname->d_name);
|
||||||
else {
|
dlink->name = BLI_strdup(buf);
|
||||||
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
|
BLI_addhead(dirbase,dlink);
|
||||||
if (dlink){
|
newnum++;
|
||||||
strcpy(buf+rellen,fname->d_name);
|
|
||||||
dlink->name = BLI_strdup(buf);
|
|
||||||
BLI_addhead(dirbase,dlink);
|
|
||||||
newnum++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -135,7 +135,8 @@ typedef struct FileList
|
|||||||
struct BlendHandle *libfiledata;
|
struct BlendHandle *libfiledata;
|
||||||
short hide_parent;
|
short hide_parent;
|
||||||
|
|
||||||
void (*read)(struct FileList *);
|
void (*readf)(struct FileList *);
|
||||||
|
int (*filterf)(struct FileList *, struct direntry* file, unsigned int filter, short hide_dot);
|
||||||
|
|
||||||
} FileList;
|
} FileList;
|
||||||
|
|
||||||
@@ -292,63 +293,91 @@ static int compare_extension(const void *a1, const void *a2) {
|
|||||||
return (BLI_strcasecmp(sufix1, sufix2));
|
return (BLI_strcasecmp(sufix1, sufix2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_hidden_file(const char* filename, short hide_dot)
|
||||||
|
{
|
||||||
|
int is_hidden=0;
|
||||||
|
|
||||||
|
if (hide_dot) {
|
||||||
|
if(filename[0]=='.' && filename[1]!='.' && filename[1]!=0) {
|
||||||
|
is_hidden=1; /* ignore .file */
|
||||||
|
} else if (((filename[0] == '.') && (filename[1] == 0) )) {
|
||||||
|
is_hidden=1; /* ignore . */
|
||||||
|
} else {
|
||||||
|
int len=strlen(filename);
|
||||||
|
if( (len>0) && (filename[len-1]=='~') ) {
|
||||||
|
is_hidden=1; /* ignore file~ */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (((filename[0] == '.') && (filename[1] == 0) )) {
|
||||||
|
is_hidden=1; /* ignore . */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return is_hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_filtered_file(struct direntry* file, const char* dir, unsigned int filter, short hide_dot)
|
||||||
|
{
|
||||||
|
int is_filtered=0;
|
||||||
|
if (filter) {
|
||||||
|
if (file->flags & filter) {
|
||||||
|
is_filtered=1;
|
||||||
|
} else if (file->type & S_IFDIR) {
|
||||||
|
if (filter & FOLDERFILE) {
|
||||||
|
is_filtered = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
is_filtered = 1;
|
||||||
|
}
|
||||||
|
return is_filtered && !is_hidden_file(file->relname, hide_dot);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_filtered_lib(struct direntry* file, const char* dir, unsigned int filter, short hide_dot)
|
||||||
|
{
|
||||||
|
int is_filtered=0;
|
||||||
|
char tdir[FILE_MAX], tgroup[GROUP_MAX];
|
||||||
|
if (BLO_is_a_library(dir, tdir, tgroup)) {
|
||||||
|
is_filtered = !is_hidden_file(file->relname, hide_dot);
|
||||||
|
} else {
|
||||||
|
is_filtered = is_filtered_file(file, dir, filter, hide_dot);
|
||||||
|
}
|
||||||
|
return is_filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_filtered_main(struct direntry* file, const char* dir, unsigned int filter, short hide_dot)
|
||||||
|
{
|
||||||
|
return !is_hidden_file(file->relname, hide_dot);
|
||||||
|
}
|
||||||
|
|
||||||
void filelist_filter(FileList* filelist)
|
void filelist_filter(FileList* filelist)
|
||||||
{
|
{
|
||||||
/* char dir[FILE_MAX], group[GROUP_MAX]; XXXXX */
|
|
||||||
int num_filtered = 0;
|
int num_filtered = 0;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
if (!filelist->filelist)
|
if (!filelist->filelist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* XXXXX TODO: check if the filter can be handled outside the filelist
|
|
||||||
if ( ( (filelist->type == FILE_LOADLIB) && BIF_filelist_islibrary(filelist, dir, group))
|
|
||||||
|| (filelist->type == FILE_MAIN) ) {
|
|
||||||
filelist->filter = 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!filelist->filter) {
|
|
||||||
if (filelist->fidx) {
|
|
||||||
MEM_freeN(filelist->fidx);
|
|
||||||
filelist->fidx = NULL;
|
|
||||||
}
|
|
||||||
filelist->fidx = (int *)MEM_callocN(filelist->numfiles*sizeof(int), "filteridx");
|
|
||||||
for (i = 0; i < filelist->numfiles; ++i) {
|
|
||||||
filelist->fidx[i] = i;
|
|
||||||
}
|
|
||||||
filelist->numfiltered = filelist->numfiles;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How many files are left after filter ?
|
// How many files are left after filter ?
|
||||||
for (i = 0; i < filelist->numfiles; ++i) {
|
for (i = 0; i < filelist->numfiles; ++i) {
|
||||||
if (filelist->filelist[i].flags & filelist->filter) {
|
struct direntry *file = &filelist->filelist[i];
|
||||||
|
if ( filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
|
||||||
num_filtered++;
|
num_filtered++;
|
||||||
}
|
}
|
||||||
else if (filelist->filelist[i].type & S_IFDIR) {
|
|
||||||
if (filelist->filter & FOLDERFILE) {
|
|
||||||
num_filtered++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filelist->fidx) {
|
if (filelist->fidx) {
|
||||||
MEM_freeN(filelist->fidx);
|
MEM_freeN(filelist->fidx);
|
||||||
filelist->fidx = NULL;
|
filelist->fidx = NULL;
|
||||||
}
|
}
|
||||||
filelist->fidx = (int *)MEM_callocN(num_filtered*sizeof(int), "filteridx");
|
filelist->fidx = (int *)MEM_callocN(num_filtered*sizeof(int), "filteridx");
|
||||||
filelist->numfiltered = num_filtered;
|
filelist->numfiltered = num_filtered;
|
||||||
|
|
||||||
for (i = 0, j=0; i < filelist->numfiles; ++i) {
|
for (i = 0, j=0; i < filelist->numfiles; ++i) {
|
||||||
if (filelist->filelist[i].flags & filelist->filter) {
|
struct direntry *file = &filelist->filelist[i];
|
||||||
|
if ( filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
|
||||||
filelist->fidx[j++] = i;
|
filelist->fidx[j++] = i;
|
||||||
}
|
}
|
||||||
else if (filelist->filelist[i].type & S_IFDIR) {
|
|
||||||
if (filelist->filter & FOLDERFILE) {
|
|
||||||
filelist->fidx[j++] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,13 +520,16 @@ struct FileList* filelist_new(short type)
|
|||||||
FileList* p = MEM_callocN( sizeof(FileList), "filelist" );
|
FileList* p = MEM_callocN( sizeof(FileList), "filelist" );
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case FILE_MAIN:
|
case FILE_MAIN:
|
||||||
p->read = filelist_read_main;
|
p->readf = filelist_read_main;
|
||||||
|
p->filterf = is_filtered_main;
|
||||||
break;
|
break;
|
||||||
case FILE_LOADLIB:
|
case FILE_LOADLIB:
|
||||||
p->read = filelist_read_library;
|
p->readf = filelist_read_library;
|
||||||
|
p->filterf = is_filtered_lib;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
p->read = filelist_read_dir;
|
p->readf = filelist_read_dir;
|
||||||
|
p->filterf = is_filtered_file;
|
||||||
|
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
@@ -716,7 +748,6 @@ static void filelist_read_dir(struct FileList* filelist)
|
|||||||
BLI_getwdN(wdir);
|
BLI_getwdN(wdir);
|
||||||
|
|
||||||
BLI_cleanup_dir(G.sce, filelist->dir);
|
BLI_cleanup_dir(G.sce, filelist->dir);
|
||||||
BLI_hide_dot_files(filelist->hide_dot);
|
|
||||||
filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist));
|
filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist));
|
||||||
|
|
||||||
if(!chdir(wdir)) /* fix warning about not checking return value */;
|
if(!chdir(wdir)) /* fix warning about not checking return value */;
|
||||||
@@ -761,7 +792,7 @@ static void filelist_read_library(struct FileList* filelist)
|
|||||||
|
|
||||||
void filelist_readdir(struct FileList* filelist)
|
void filelist_readdir(struct FileList* filelist)
|
||||||
{
|
{
|
||||||
filelist->read(filelist);
|
filelist->readf(filelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
int filelist_empty(struct FileList* filelist)
|
int filelist_empty(struct FileList* filelist)
|
||||||
|
@@ -194,7 +194,6 @@ short ED_fileselect_set_params(SpaceFile *sfile)
|
|||||||
params->filter = 0;
|
params->filter = 0;
|
||||||
params->sort = FILE_SORT_ALPHA;
|
params->sort = FILE_SORT_ALPHA;
|
||||||
}
|
}
|
||||||
params->oldflag = params->flag;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,19 +410,7 @@ void file_change_dir(bContext *C, int checkdir)
|
|||||||
/* could return but just refresh the current dir */
|
/* could return but just refresh the current dir */
|
||||||
}
|
}
|
||||||
filelist_setdir(sfile->files, sfile->params->dir);
|
filelist_setdir(sfile->files, sfile->params->dir);
|
||||||
/* XXX special case handling
|
|
||||||
behaviour of filebrowser changes when
|
|
||||||
browsing into .blend file */
|
|
||||||
if (sfile->params->type == FILE_LOADLIB) {
|
|
||||||
char group[GROUP_MAX];
|
|
||||||
char dir[FILE_MAX];
|
|
||||||
if (filelist_islibrary(sfile->files, dir, group)) {
|
|
||||||
sfile->params->flag &= ~FILE_FILTER;
|
|
||||||
} else {
|
|
||||||
/* reset the old flag */
|
|
||||||
sfile->params->flag = sfile->params->oldflag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(folderlist_clear_next(sfile))
|
if(folderlist_clear_next(sfile))
|
||||||
folderlist_free(sfile->folders_next);
|
folderlist_free(sfile->folders_next);
|
||||||
|
|
||||||
|
@@ -162,21 +162,20 @@ typedef struct FileSelectParams {
|
|||||||
|
|
||||||
short type; /* XXXXX for now store type here, should be moved to the operator */
|
short type; /* XXXXX for now store type here, should be moved to the operator */
|
||||||
short flag; /* settings for filter, hiding dots files,... */
|
short flag; /* settings for filter, hiding dots files,... */
|
||||||
short oldflag; /* temp storage of original flag settings */
|
|
||||||
short sort; /* sort order */
|
short sort; /* sort order */
|
||||||
short display; /* display mode flag */
|
short display; /* display mode flag */
|
||||||
short filter; /* filter when (flags & FILE_FILTER) is true */
|
short filter; /* filter when (flags & FILE_FILTER) is true */
|
||||||
|
|
||||||
/* XXX - temporary, better move to filelist */
|
/* XXX - temporary, better move to filelist */
|
||||||
short active_bookmark;
|
short active_bookmark;
|
||||||
short pad;
|
|
||||||
int active_file;
|
int active_file;
|
||||||
int selstate;
|
int selstate;
|
||||||
|
|
||||||
/* short */
|
/* short */
|
||||||
/* XXX --- still unused -- */
|
/* XXX --- still unused -- */
|
||||||
short f_fp; /* show font preview */
|
short f_fp; /* show font preview */
|
||||||
short pad2;
|
short pad;
|
||||||
char fp_str[8]; /* string to use for font preview */
|
char fp_str[8]; /* string to use for font preview */
|
||||||
|
|
||||||
/* XXX --- end unused -- */
|
/* XXX --- end unused -- */
|
||||||
|
@@ -597,14 +597,6 @@ static void rna_Sequencer_display_mode_update(bContext *C, PointerRNA *ptr)
|
|||||||
ED_sequencer_update_view(C, view);
|
ED_sequencer_update_view(C, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rna_FileSelectParams_flag_update(Main *bmain, Scene *scene, PointerRNA *ptr)
|
|
||||||
{
|
|
||||||
FileSelectParams* params = (FileSelectParams*)ptr->data;
|
|
||||||
if (params) {
|
|
||||||
params->oldflag = params->flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void rna_def_space(BlenderRNA *brna)
|
static void rna_def_space(BlenderRNA *brna)
|
||||||
@@ -1880,12 +1872,12 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
|
|||||||
prop= RNA_def_property(srna, "do_filter", PROP_BOOLEAN, PROP_NONE);
|
prop= RNA_def_property(srna, "do_filter", PROP_BOOLEAN, PROP_NONE);
|
||||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_FILTER);
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_FILTER);
|
||||||
RNA_def_property_ui_text(prop, "Filter Files", "Enable filtering of files");
|
RNA_def_property_ui_text(prop, "Filter Files", "Enable filtering of files");
|
||||||
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_FILE_PARAMS, "rna_FileSelectParams_flag_update");
|
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
|
||||||
|
|
||||||
prop= RNA_def_property(srna, "hide_dot", PROP_BOOLEAN, PROP_NONE);
|
prop= RNA_def_property(srna, "hide_dot", PROP_BOOLEAN, PROP_NONE);
|
||||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_HIDE_DOT);
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_HIDE_DOT);
|
||||||
RNA_def_property_ui_text(prop, "Hide Dot Files", "Hide hidden dot files");
|
RNA_def_property_ui_text(prop, "Hide Dot Files", "Hide hidden dot files");
|
||||||
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_FILE_LIST , "rna_FileSelectParams_flag_update");
|
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_FILE_PARAMS , NULL);
|
||||||
|
|
||||||
prop= RNA_def_property(srna, "sort", PROP_ENUM, PROP_NONE);
|
prop= RNA_def_property(srna, "sort", PROP_ENUM, PROP_NONE);
|
||||||
RNA_def_property_enum_sdna(prop, NULL, "sort");
|
RNA_def_property_enum_sdna(prop, NULL, "sort");
|
||||||
|
Reference in New Issue
Block a user