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:
Andrea Weikert
2010-03-20 14:23:56 +00:00
parent ca3736c123
commit 08164794b2
6 changed files with 84 additions and 88 deletions

View File

@@ -50,7 +50,7 @@ int BLI_filesize(int file);
int BLI_filepathsize(const char *path);
double BLI_diskfree(char *dir);
char *BLI_getwdN(char *dir);
void BLI_hide_dot_files(int set);
unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
/**
* @attention Do not confuse with BLI_exists

View File

@@ -204,14 +204,6 @@ double BLI_diskfree(char *dir)
#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)
{
struct dirent *fname;
@@ -237,17 +229,12 @@ void BLI_builddir(char *dirname, char *relname)
while ((fname = (struct dirent*) readdir(dir)) != NULL) {
len= strlen(fname->d_name);
if(hide_dot && fname->d_name[0]=='.' && fname->d_name[1]!='.' && fname->d_name[1]!=0); /* ignore .file */
else if(hide_dot && len && fname->d_name[len-1]=='~'); /* ignore file~ */
else if (((fname->d_name[0] == '.') && (fname->d_name[1] == 0) )); /* ignore . */
else {
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
if (dlink){
strcpy(buf+rellen,fname->d_name);
dlink->name = BLI_strdup(buf);
BLI_addhead(dirbase,dlink);
newnum++;
}
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
if (dlink){
strcpy(buf+rellen,fname->d_name);
dlink->name = BLI_strdup(buf);
BLI_addhead(dirbase,dlink);
newnum++;
}
}

View File

@@ -135,7 +135,8 @@ typedef struct FileList
struct BlendHandle *libfiledata;
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;
@@ -292,63 +293,91 @@ static int compare_extension(const void *a1, const void *a2) {
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)
{
/* char dir[FILE_MAX], group[GROUP_MAX]; XXXXX */
int num_filtered = 0;
int i, j;
if (!filelist->filelist)
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 ?
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++;
}
else if (filelist->filelist[i].type & S_IFDIR) {
if (filelist->filter & FOLDERFILE) {
num_filtered++;
}
}
}
if (filelist->fidx) {
MEM_freeN(filelist->fidx);
filelist->fidx = NULL;
MEM_freeN(filelist->fidx);
filelist->fidx = NULL;
}
filelist->fidx = (int *)MEM_callocN(num_filtered*sizeof(int), "filteridx");
filelist->numfiltered = num_filtered;
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;
}
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" );
switch(type) {
case FILE_MAIN:
p->read = filelist_read_main;
p->readf = filelist_read_main;
p->filterf = is_filtered_main;
break;
case FILE_LOADLIB:
p->read = filelist_read_library;
p->readf = filelist_read_library;
p->filterf = is_filtered_lib;
break;
default:
p->read = filelist_read_dir;
p->readf = filelist_read_dir;
p->filterf = is_filtered_file;
}
return p;
@@ -716,7 +748,6 @@ static void filelist_read_dir(struct FileList* filelist)
BLI_getwdN(wdir);
BLI_cleanup_dir(G.sce, filelist->dir);
BLI_hide_dot_files(filelist->hide_dot);
filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist));
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)
{
filelist->read(filelist);
filelist->readf(filelist);
}
int filelist_empty(struct FileList* filelist)

View File

@@ -194,7 +194,6 @@ short ED_fileselect_set_params(SpaceFile *sfile)
params->filter = 0;
params->sort = FILE_SORT_ALPHA;
}
params->oldflag = params->flag;
return 1;
}
@@ -411,19 +410,7 @@ void file_change_dir(bContext *C, int checkdir)
/* could return but just refresh the current 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))
folderlist_free(sfile->folders_next);

View File

@@ -162,21 +162,20 @@ typedef struct FileSelectParams {
short type; /* XXXXX for now store type here, should be moved to the operator */
short flag; /* settings for filter, hiding dots files,... */
short oldflag; /* temp storage of original flag settings */
short sort; /* sort order */
short display; /* display mode flag */
short filter; /* filter when (flags & FILE_FILTER) is true */
/* XXX - temporary, better move to filelist */
short active_bookmark;
short pad;
int active_file;
int selstate;
/* short */
/* XXX --- still unused -- */
short f_fp; /* show font preview */
short pad2;
short pad;
char fp_str[8]; /* string to use for font preview */
/* XXX --- end unused -- */

View File

@@ -597,14 +597,6 @@ static void rna_Sequencer_display_mode_update(bContext *C, PointerRNA *ptr)
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
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);
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_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);
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_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);
RNA_def_property_enum_sdna(prop, NULL, "sort");