directory only filesel for operators which don't have a filepath or filename property.

This commit is contained in:
Campbell Barton 2011-06-16 15:01:22 +00:00
parent 216ba20942
commit fd24c99b5d
5 changed files with 52 additions and 31 deletions

@ -185,6 +185,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
uiButSetCompleteFunc(but, autocomplete_directory, NULL);
uiButSetFlag(but, UI_BUT_NO_UTF8);
if((params->flag & FILE_DIRSEL_ONLY) == 0) {
but = uiDefBut(block, TEX, B_FS_FILENAME, "",
min_x, line2_y, line2_w-chan_offs, btn_h,
params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0,
@ -196,13 +197,14 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
if(overwrite_alert) {
uiButSetFlag(but, UI_BUT_REDALERT);
}
}
/* clear func */
uiBlockSetFunc(block, NULL, NULL, NULL);
}
/* Filename number increment / decrement buttons. */
if (fnumbuttons) {
if (fnumbuttons && (params->flag & FILE_DIRSEL_ONLY) == 0) {
uiBlockBeginAlign(block);
but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMOUT,
min_x + line2_w + separator - chan_offs, line2_y,

@ -205,9 +205,10 @@ static FileSelect file_select(bContext* C, const rcti* rect, FileSelType select,
SpaceFile *sfile= CTX_wm_space_file(C);
FileSelect retval = FILE_SELECT_NOTHING;
FileSelection sel= file_selection_get(C, rect, fill); /* get the selection */
const FileCheckType check_type= (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
/* flag the files as selected in the filelist */
filelist_select(sfile->files, &sel, select, SELECTED_FILE, CHECK_ALL);
filelist_select(sfile->files, &sel, select, SELECTED_FILE, check_type);
/* Don't act on multiple selected files */
if (sel.first != sel.last) select = 0;
@ -216,7 +217,7 @@ static FileSelect file_select(bContext* C, const rcti* rect, FileSelType select,
if ( (sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE)) )
{
/* Check last selection, if selected, act on the file or dir */
if (filelist_is_selected(sfile->files, sel.last, CHECK_ALL)) {
if (filelist_is_selected(sfile->files, sel.last, check_type)) {
retval = file_select_do(C, sel.last);
}
}
@ -378,8 +379,10 @@ static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op))
/* select all only if previously no file was selected */
if (is_selected) {
filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, SELECTED_FILE, CHECK_ALL);
} else {
filelist_select(sfile->files, &sel, FILE_SEL_ADD, SELECTED_FILE, CHECK_FILES);
}
else {
const FileCheckType check_type= (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
filelist_select(sfile->files, &sel, FILE_SEL_ADD, SELECTED_FILE, check_type);
}
ED_area_tag_redraw(sa);
return OPERATOR_FINISHED;

@ -915,6 +915,8 @@ void filelist_select_file(struct FileList* filelist, int index, FileSelType sele
int check_ok = 0;
switch (check) {
case CHECK_DIRS:
check_ok = S_ISDIR(file->type);
break;
case CHECK_ALL:
check_ok = 1;
break;

@ -121,6 +121,9 @@ short ED_fileselect_set_params(SpaceFile *sfile)
/* set the parameters from the operator, if it exists */
if (op) {
short is_filename= FALSE;
short is_dir= FALSE;
BLI_strncpy(params->title, op->type->name, sizeof(params->title));
if(RNA_struct_find_property(op->ptr, "filemode"))
@ -128,7 +131,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
else
params->type = FILE_SPECIAL;
if (RNA_struct_find_property(op->ptr, "filepath") && RNA_property_is_set(op->ptr, "filepath")) {
if ((is_dir= is_filename= RNA_struct_find_property(op->ptr, "filepath")!=NULL) && RNA_property_is_set(op->ptr, "filepath")) {
char name[FILE_MAX];
RNA_string_get(op->ptr, "filepath", name);
if (params->type == FILE_LOADLIB) {
@ -140,12 +143,13 @@ short ED_fileselect_set_params(SpaceFile *sfile)
}
}
else {
if (RNA_struct_find_property(op->ptr, "directory") && RNA_property_is_set(op->ptr, "directory")) {
if ((is_dir= RNA_struct_find_property(op->ptr, "directory")!=NULL) && RNA_property_is_set(op->ptr, "directory")) {
RNA_string_get(op->ptr, "directory", params->dir);
sfile->params->file[0]= '\0';
is_dir= TRUE;
}
if (RNA_struct_find_property(op->ptr, "filename") && RNA_property_is_set(op->ptr, "filename")) {
if ((is_filename= RNA_struct_find_property(op->ptr, "filename")!=NULL) && RNA_property_is_set(op->ptr, "filename")) {
RNA_string_get(op->ptr, "filename", params->file);
}
}
@ -155,6 +159,13 @@ short ED_fileselect_set_params(SpaceFile *sfile)
BLI_path_abs(params->dir, G.main->name);
}
if(is_dir==TRUE && is_filename==FALSE) {
params->flag |= FILE_DIRSEL_ONLY;
}
else {
params->flag &= ~FILE_DIRSEL_ONLY;
}
params->filter = 0;
if(RNA_struct_find_property(op->ptr, "filter_blender"))
params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0;
@ -216,10 +227,12 @@ short ED_fileselect_set_params(SpaceFile *sfile)
params->display= FILE_SHORTDISPLAY;
}
} else {
}
else {
/* default values, if no operator */
params->type = FILE_UNIX;
params->flag |= FILE_HIDE_DOT;
params->flag &= ~FILE_DIRSEL_ONLY;
params->display = FILE_SHORTDISPLAY;
params->filter = 0;
params->filter_glob[0] = '\0';

@ -696,18 +696,19 @@ enum FileSortTypeE {
#define FILE_OPENFILE 0
#define FILE_SAVE 1
/* sfile->flag and simasel->flag */
#define FILE_SHOWSHORT 1
#define FILE_RELPATH 2 /* was FILE_STRINGCODE */
#define FILE_LINK 4
#define FILE_HIDE_DOT 8
#define FILE_AUTOSELECT 16
#define FILE_ACTIVELAY 32
#define FILE_ATCURSOR 64
#define FILE_SYNCPOSE 128
#define FILE_FILTER 256
#define FILE_BOOKMARKS 512
#define FILE_GROUP_INSTANCE 1024
/* sfile->params->flag and simasel->flag */
#define FILE_SHOWSHORT (1<<0)
#define FILE_RELPATH (1<<1) /* was FILE_STRINGCODE */
#define FILE_LINK (1<<2)
#define FILE_HIDE_DOT (1<<3)
#define FILE_AUTOSELECT (1<<4)
#define FILE_ACTIVELAY (1<<5)
#define FILE_ATCURSOR (1<<6)
#define FILE_DIRSEL_ONLY (1<<7)
#define FILE_FILTER (1<<8)
#define FILE_BOOKMARKS (1<<9)
#define FILE_GROUP_INSTANCE (1<<10)
/* files in filesel list: file types */
#define BLENDERFILE (1<<2)