patch [#23968] filter_filetypes property to allow operators to filter by file extensions in the file selector

modified the patch to store the string internally rather then an array of allocated string pointers, less hassle with memory allocation.
changed to use fnmatch, so *.foo is needed (not .foo as with the patch)
This commit is contained in:
Campbell Barton 2010-09-24 07:05:43 +00:00
parent 99643037ca
commit 6a4b9298c8
12 changed files with 50 additions and 8 deletions

@ -36,6 +36,7 @@ class BvhImporter(bpy.types.Operator, ImportHelper):
bl_label = "Import BVH"
filename_ext = ".bvh"
filter_glob = StringProperty(default="*.bvh", options={'HIDDEN'})
scale = FloatProperty(name="Scale", description="Scale the BVH by this value", min=0.0001, max=1000000.0, soft_min=0.001, soft_max=100.0, default=0.1)
frame_start = IntProperty(name="Start Frame", description="Starting frame for the animation", default=1)

@ -36,6 +36,7 @@ class Import3DS(bpy.types.Operator, ImportHelper):
bl_label = 'Import 3DS'
filename_ext = ".3ds"
filter_glob = StringProperty(default="*.3ds", options={'HIDDEN'})
constrain_size = FloatProperty(name="Size Constraint", description="Scale the model by 10 until it reacehs the size constraint. Zero Disables.", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=10.0)
use_image_search = BoolProperty(name="Image Search", description="Search subdirectories for any assosiated images (Warning, may be slow)", default=True)

@ -37,6 +37,7 @@ class ImportOBJ(bpy.types.Operator, ImportHelper):
bl_label = "Import OBJ"
filename_ext = ".obj"
filter_glob = StringProperty(default="*.obj;*.mtl", options={'HIDDEN'})
CREATE_SMOOTH_GROUPS = BoolProperty(name="Smooth Groups", description="Surround smooth groups by sharp edges", default= True)
CREATE_FGONS = BoolProperty(name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default= True)

@ -37,6 +37,8 @@ class ImportMDD(bpy.types.Operator, ImportHelper):
bl_label = "Import MDD"
filename_ext = ".mdd"
filter_glob = StringProperty(default="*.mdd", options={'HIDDEN'})
frame_start = IntProperty(name="Start Frame", description="Start frame for inserting animation", min=-300000, max=300000, default=0)
frame_step = IntProperty(name="Step", min=1, max=1000, default=1)

@ -57,15 +57,21 @@ class FILEBROWSER_HT_header(bpy.types.Header):
row = layout.row(align=True)
row.active = params.use_filter
row.prop(params, "use_filter_folder", text="")
row.prop(params, "use_filter_blender", text="")
row.prop(params, "use_filter_image", text="")
row.prop(params, "use_filter_movie", text="")
row.prop(params, "use_filter_script", text="")
row.prop(params, "use_filter_font", text="")
row.prop(params, "use_filter_sound", text="")
row.prop(params, "use_filter_text", text="")
if params.filter_glob:
#if st.operator and hasattr(st.operator, "filter_glob"):
# row.prop(params, "filter_glob", text="")
row.label(params.filter_glob)
else:
row.prop(params, "use_filter_blender", text="")
row.prop(params, "use_filter_image", text="")
row.prop(params, "use_filter_movie", text="")
row.prop(params, "use_filter_script", text="")
row.prop(params, "use_filter_font", text="")
row.prop(params, "use_filter_sound", text="")
row.prop(params, "use_filter_text", text="")
def register():

@ -1085,6 +1085,7 @@ class WM_OT_addon_install(bpy.types.Operator):
filepath = StringProperty(name="File Path", description="File path to write file to")
filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
filter_glob = StringProperty(default="*.py;*.zip", options={'HIDDEN'})
def execute(self, context):
import traceback

@ -108,6 +108,7 @@ typedef struct FileList
short prv_h;
short hide_dot;
unsigned int filter;
char filter_glob[64];
short changed;
struct BlendHandle *libfiledata;
@ -547,6 +548,7 @@ void filelist_free(struct FileList* filelist)
free(filelist->filelist);
filelist->filelist = 0;
filelist->filter = 0;
filelist->filter_glob[0] = '\0';
filelist->numfiltered =0;
filelist->hide_dot =0;
}
@ -713,6 +715,11 @@ void filelist_setfilter(struct FileList* filelist, unsigned int filter)
filelist->filter = filter;
}
void filelist_setfilter_types(struct FileList* filelist, const char *filter_glob)
{
BLI_strncpy(filelist->filter_glob, filter_glob, sizeof(filelist->filter_glob));
}
static void filelist_read_dir(struct FileList* filelist)
{
char wdir[FILE_MAX];
@ -824,6 +831,9 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime)
file->flags |= MOVIEFILE;
} else if(BLI_testextensie_array(file->relname, imb_ext_audio)) {
file->flags |= SOUNDFILE;
} else if(filelist->filter_glob
&& BLI_testextensie_glob(file->relname, filelist->filter_glob)) {
file->flags |= OPERATORFILE;
}
}
}

@ -58,6 +58,7 @@ void filelist_setdir(struct FileList* filelist, const char *dir);
struct direntry * filelist_file(struct FileList* filelist, int index);
void filelist_hidedot(struct FileList* filelist, short hide);
void filelist_setfilter(struct FileList* filelist, unsigned int filter);
void filelist_setfilter_types(struct FileList* filelist, const char *filter_glob);
void filelist_filter(struct FileList* filelist);
void filelist_swapselect(struct FileList* filelist);
void filelist_imgsize(struct FileList* filelist, short w, short h);

@ -105,6 +105,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
/* set path to most recently opened .blend */
BLI_split_dirfile(G.sce, sfile->params->dir, sfile->params->file);
sfile->params->filter_glob[0] = '\0';
}
params = sfile->params;
@ -168,6 +169,11 @@ short ED_fileselect_set_params(SpaceFile *sfile)
params->filter |= RNA_boolean_get(op->ptr, "filter_btx") ? BTXFILE : 0;
if(RNA_struct_find_property(op->ptr, "filter_collada"))
params->filter |= RNA_boolean_get(op->ptr, "filter_collada") ? COLLADAFILE : 0;
if (RNA_struct_find_property(op->ptr, "filter_glob")) {
RNA_string_get(op->ptr, "filter_glob", params->filter_glob);
params->filter |= (OPERATORFILE|FOLDERFILE);
}
if (params->filter != 0) {
if (U.uiflag & USER_FILTERFILEEXTS) {
params->flag |= FILE_FILTER;

@ -192,6 +192,7 @@ static void file_refresh(const bContext *C, ScrArea *sa)
}
filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT);
filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);
filelist_setfilter_types(sfile->files, params->filter_glob);
if (filelist_empty(sfile->files))
{
thumbnails_stop(sfile->files, C);

@ -163,6 +163,8 @@ typedef struct FileSelectParams {
char renamefile[80];
char renameedit[80]; /* annoying but the first is only used for initialization */
char filter_glob[64]; /* list of filetypes to filter */
short type; /* XXXXX for now store type here, should be moved to the operator */
short flag; /* settings for filter, hiding dots files,... */
short sort; /* sort order */
@ -725,6 +727,7 @@ enum FileSortTypeE {
#define FOLDERFILE (1<<11) /* represents folders for filtering */
#define BTXFILE (1<<12)
#define COLLADAFILE (1<<13)
#define OPERATORFILE (1<<14) /* from filter_glob operator property */
/* SpaceImage->dt_uv */
#define SI_UVDT_OUTLINE 0

@ -2126,6 +2126,11 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Filter Folder", "Show folders");
RNA_def_property_ui_icon(prop, ICON_FILE_FOLDER, 0);
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
prop= RNA_def_property(srna, "filter_glob", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "filter_glob");
RNA_def_property_ui_text(prop, "Extension Filter", "");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
}
@ -2141,6 +2146,10 @@ static void rna_def_space_filebrowser(BlenderRNA *brna)
prop= RNA_def_property(srna, "params", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "params");
RNA_def_property_ui_text(prop, "Filebrowser Parameter", "Parameters and Settings for the Filebrowser");
prop= RNA_def_property(srna, "operator", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "op");
RNA_def_property_ui_text(prop, "Operator", "");
}
static void rna_def_space_info(BlenderRNA *brna)