2.5 file browser
New: * added filter and display to some operator properties. Now file browser opens showing only .blend files and folders on file->open and on image->open changes to image display and only shows images and movies. Fixes: * fixed stupid removal of wrong prototype in last commit * fixed a few warnings
This commit is contained in:
@@ -70,8 +70,7 @@ typedef struct FileLayout
|
||||
|
||||
struct FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile);
|
||||
|
||||
short ED_fileselect_set_params(struct SpaceFile *sfile, const char *title, const char *dir, const char *path,
|
||||
short flag, short display, short filter, short sort);
|
||||
short ED_fileselect_set_params(struct SpaceFile *sfile);
|
||||
|
||||
void ED_fileselect_reset_params(struct SpaceFile *sfile);
|
||||
|
||||
|
||||
@@ -121,7 +121,10 @@ static void file_panel_operator(const bContext *C, Panel *pa)
|
||||
continue;
|
||||
if(strcmp(RNA_property_identifier(prop), "filename") == 0)
|
||||
continue;
|
||||
|
||||
if(strcmp(RNA_property_identifier(prop), "display") == 0)
|
||||
continue;
|
||||
if(strncmp(RNA_property_identifier(prop), "filter", 6) == 0)
|
||||
continue;
|
||||
uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0);
|
||||
}
|
||||
RNA_STRUCT_END;
|
||||
|
||||
@@ -903,9 +903,6 @@ void filelist_swapselect(struct FileList* filelist)
|
||||
|
||||
void filelist_sort(struct FileList* filelist, short sort)
|
||||
{
|
||||
struct direntry *file;
|
||||
int num;/* , act= 0; */
|
||||
|
||||
switch(sort) {
|
||||
case FILE_SORT_ALPHA:
|
||||
qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_name);
|
||||
|
||||
@@ -54,7 +54,7 @@ void filelist_sort(struct FileList* filelist, short sort);
|
||||
int filelist_numfiles(struct FileList* filelist);
|
||||
const char * filelist_dir(struct FileList* filelist);
|
||||
void filelist_setdir(struct FileList* filelist, const char *dir);
|
||||
void filelist_end_edit(struct FileList* filelist, int index);
|
||||
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_filter(struct FileList* filelist);
|
||||
|
||||
@@ -73,6 +73,8 @@
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
#include "UI_view2d.h"
|
||||
@@ -95,41 +97,60 @@ static int fnmatch(const char *pattern, const char *string, int flags)
|
||||
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
|
||||
{
|
||||
if (!sfile->params) {
|
||||
ED_fileselect_set_params(sfile, "", NULL, "/", 0, FILE_SHORTDISPLAY, 0, FILE_SORT_ALPHA);
|
||||
ED_fileselect_set_params(sfile);
|
||||
}
|
||||
return sfile->params;
|
||||
}
|
||||
|
||||
short ED_fileselect_set_params(SpaceFile *sfile, const char *title, const char *last_dir, const char *path,
|
||||
short flag, short display, short filter, short sort)
|
||||
short ED_fileselect_set_params(SpaceFile *sfile)
|
||||
{
|
||||
char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
|
||||
FileSelectParams *params;
|
||||
wmOperator *op = sfile->op;
|
||||
|
||||
/* create new parameters if necessary */
|
||||
if (!sfile->params) {
|
||||
sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
|
||||
/* set path to most recently opened .blend */
|
||||
BLI_strncpy(sfile->params->dir, G.sce, sizeof(sfile->params->dir));
|
||||
BLI_split_dirfile(G.sce, dir, file);
|
||||
BLI_strncpy(sfile->params->file, file, sizeof(sfile->params->file));
|
||||
BLI_make_file_string(G.sce, sfile->params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
|
||||
}
|
||||
|
||||
params = sfile->params;
|
||||
|
||||
params->flag = flag;
|
||||
params->display = display;
|
||||
params->filter = filter;
|
||||
params->sort = sort;
|
||||
|
||||
BLI_strncpy(params->title, title, sizeof(params->title));
|
||||
|
||||
if(last_dir){
|
||||
BLI_strncpy(params->dir, last_dir, sizeof(params->dir));
|
||||
}
|
||||
else {
|
||||
BLI_strncpy(name, path, sizeof(name));
|
||||
BLI_convertstringcode(name, G.sce);
|
||||
|
||||
BLI_split_dirfile(name, dir, file);
|
||||
BLI_strncpy(params->file, file, sizeof(params->file));
|
||||
BLI_strncpy(params->dir, dir, sizeof(params->dir));
|
||||
BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
|
||||
/* set the parameters from the operator, if it exists */
|
||||
if (op) {
|
||||
BLI_strncpy(params->title, op->type->name, sizeof(params->title));
|
||||
params->filter = 0;
|
||||
params->filter |= RNA_boolean_get(op->ptr, "filter_folder") ? FOLDERFILE : 0;
|
||||
params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0;
|
||||
params->filter |= RNA_boolean_get(op->ptr, "filter_image") ? IMAGEFILE : 0;
|
||||
params->filter |= RNA_boolean_get(op->ptr, "filter_movie") ? MOVIEFILE : 0;
|
||||
if (params->filter != 0)
|
||||
params->flag |= FILE_FILTER;
|
||||
|
||||
if (RNA_property_is_set(op->ptr, "display")) {
|
||||
params->display= RNA_int_get(op->ptr, "display");
|
||||
} else {
|
||||
params->display = FILE_SHORTDISPLAY;
|
||||
}
|
||||
|
||||
/* if operator has path set, use it, otherwise keep the last */
|
||||
if (RNA_property_is_set(op->ptr, "filename")) {
|
||||
RNA_string_get(op->ptr, "filename", name);
|
||||
BLI_convertstringcode(name, G.sce);
|
||||
BLI_split_dirfile(name, dir, file);
|
||||
BLI_strncpy(params->file, file, sizeof(params->file));
|
||||
BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
|
||||
}
|
||||
} else {
|
||||
/* default values, if no operator */
|
||||
params->flag = 0;
|
||||
params->display = FILE_SHORTDISPLAY;
|
||||
params->filter = 0;
|
||||
params->sort = FILE_SORT_ALPHA;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -144,7 +165,6 @@ void ED_fileselect_reset_params(SpaceFile *sfile)
|
||||
int ED_fileselect_layout_numfiles(FileLayout* layout, struct ARegion *ar)
|
||||
{
|
||||
int numfiles;
|
||||
short width, height;
|
||||
|
||||
if (layout->flag & FILE_LAYOUT_HOR) {
|
||||
short width = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*layout->tile_border_x;
|
||||
|
||||
@@ -310,7 +310,9 @@ void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename)
|
||||
if (line[len-1] == '\n') {
|
||||
line[len-1] = '\0';
|
||||
}
|
||||
fsmenu_insert_entry(fsmenu, category, line, 0, 1);
|
||||
if (BLI_exist(line)) {
|
||||
fsmenu_insert_entry(fsmenu, category, line, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,11 +195,11 @@ static void file_refresh(const bContext *C, ScrArea *sa)
|
||||
params->active_file = -1; // added this so it opens nicer (ton)
|
||||
}
|
||||
filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT);
|
||||
filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);
|
||||
if (filelist_empty(sfile->files))
|
||||
{
|
||||
filelist_readdir(sfile->files);
|
||||
}
|
||||
filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);
|
||||
if(params->sort!=FILE_SORT_NONE) filelist_sort(sfile->files, params->sort);
|
||||
|
||||
if (sfile->layout) sfile->layout->dirty= 1;
|
||||
|
||||
@@ -609,6 +609,10 @@ static const EnumPropertyItem image_file_type_items[] = {
|
||||
static void image_filesel(bContext *C, wmOperator *op, const char *path)
|
||||
{
|
||||
RNA_string_set(op->ptr, "filename", path);
|
||||
RNA_boolean_set(op->ptr, "filter_image", 1);
|
||||
RNA_boolean_set(op->ptr, "filter_movie", 1);
|
||||
RNA_boolean_set(op->ptr, "filter_folder", 1);
|
||||
RNA_enum_set(op->ptr, "display", FILE_IMGDISPLAY);
|
||||
WM_event_add_fileselect(C, op);
|
||||
}
|
||||
|
||||
@@ -649,6 +653,14 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
void IMAGE_OT_open(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
static EnumPropertyItem file_display_items[] = {
|
||||
{FILE_SHORTDISPLAY, "FILE_SHORTDISPLAY", ICON_SHORTDISPLAY, "Short List", "Display files as short list"},
|
||||
{FILE_LONGDISPLAY, "FILE_LONGDISPLAY", ICON_LONGDISPLAY, "Long List", "Display files as a detailed list"},
|
||||
{FILE_IMGDISPLAY, "FILE_IMGDISPLAY", ICON_IMGDISPLAY, "Thumbnails", "Display files as thumbnails"},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
/* identifiers */
|
||||
ot->name= "Open";
|
||||
ot->idname= "IMAGE_OT_open";
|
||||
@@ -663,6 +675,19 @@ void IMAGE_OT_open(wmOperatorType *ot)
|
||||
|
||||
/* properties */
|
||||
RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "File path of image to open.");
|
||||
|
||||
prop= RNA_def_boolean(ot->srna, "filter_image", 0, "Show image files", "");
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "filter", IMAGEFILE);
|
||||
prop= RNA_def_boolean(ot->srna, "filter_movie", 0, "Show movie files", "");
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "filter", MOVIEFILE);
|
||||
prop= RNA_def_boolean(ot->srna, "filter_folder", 0, "Show folders", "");
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "filter", FOLDERFILE);
|
||||
|
||||
prop= RNA_def_property(ot->srna, "display", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "display");
|
||||
RNA_def_property_enum_items(prop, file_display_items);
|
||||
RNA_def_property_ui_text(prop, "Display Mode", "Display mode for the file list");
|
||||
|
||||
}
|
||||
|
||||
/******************** replace image operator ********************/
|
||||
|
||||
@@ -820,18 +820,8 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
|
||||
/* settings for filebrowser, sfile is not operator owner but sends events */
|
||||
sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||
sfile->op= handler->op;
|
||||
|
||||
/* XXX for now take the settings from the existing (previous) filebrowser
|
||||
should be stored in settings and passed via the operator */
|
||||
if (sfile->params) {
|
||||
flag = sfile->params->flag;
|
||||
filter = sfile->params->filter;
|
||||
display = sfile->params->display;
|
||||
sort = sfile->params->sort;
|
||||
dir = sfile->params->dir;
|
||||
}
|
||||
|
||||
ED_fileselect_set_params(sfile, handler->op->type->name, dir, path, flag, display, filter, sort);
|
||||
ED_fileselect_set_params(sfile);
|
||||
dir = NULL;
|
||||
MEM_freeN(path);
|
||||
|
||||
|
||||
@@ -672,6 +672,8 @@ static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
|
||||
RNA_string_set(op->ptr, "filename", G.sce);
|
||||
RNA_boolean_set(op->ptr, "filter_blender", 1);
|
||||
RNA_boolean_set(op->ptr, "filter_folder", 1);
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
@@ -693,6 +695,7 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
|
||||
|
||||
static void WM_OT_open_mainfile(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
ot->name= "Open Blender File";
|
||||
ot->idname= "WM_OT_open_mainfile";
|
||||
|
||||
@@ -700,7 +703,13 @@ static void WM_OT_open_mainfile(wmOperatorType *ot)
|
||||
ot->exec= wm_open_mainfile_exec;
|
||||
ot->poll= WM_operator_winactive;
|
||||
|
||||
RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
|
||||
RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "File path of blendfile to open.");
|
||||
|
||||
prop= RNA_def_boolean(ot->srna, "filter_blender", 0, "Filter Blendfiles", "");
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "filter", BLENDERFILE);
|
||||
prop= RNA_def_boolean(ot->srna, "filter_folder", 0, "Filter Blendfiles", "");
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "filter", FOLDERFILE);
|
||||
|
||||
}
|
||||
|
||||
static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
|
||||
|
||||
Reference in New Issue
Block a user