int file_parent_exec(bContext *C, wmOperator *UNUSED(unused)) { SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { if (BLI_parent_dir(sfile->params->dir)) { BLI_cleanup_dir(G.main->name, sfile->params->dir); /* if not browsing in .blend file, we still want to check whether the path is a directory */ if (sfile->params->type == FILE_LOADLIB) { char tdir[FILE_MAX], tgroup[FILE_MAX]; if (BLO_is_a_library(sfile->params->dir, tdir, tgroup)) { file_change_dir(C, 0); } else { file_change_dir(C, 1); } } else { file_change_dir(C, 1); } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } } return OPERATOR_FINISHED; }
static void filelist_read_library(struct FileList* filelist) { if (!filelist) return; BLI_cleanup_dir(G.main->name, filelist->dir); filelist_from_library(filelist); if (!filelist->libfiledata) { int num; struct direntry *file; BLI_make_exist(filelist->dir); filelist_read_dir(filelist); file = filelist->filelist; for (num=0; num<filelist->numfiles; num++, file++) { if (BLO_has_bfile_extension(file->relname)) { char name[FILE_MAX]; BLI_join_dirfile(name, sizeof(name), filelist->dir, file->relname); /* prevent current file being used as acceptable dir */ if (BLI_path_cmp(G.main->name, name) != 0) { file->type &= ~S_IFMT; file->type |= S_IFDIR; } } } } }
int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) { SpaceFile *sfile= CTX_wm_space_file(C); if(sfile->params) { file_expand_directory(C); if (!BLI_exists(sfile->params->dir)) { BLI_recurdir_fileops(sfile->params->dir); } /* special case, user may have pasted a fulepath into the directory */ if(BLI_exists(sfile->params->dir) && BLI_is_dir(sfile->params->dir) == 0) { char path[sizeof(sfile->params->dir)]; BLI_strncpy(path, sfile->params->dir, sizeof(path)); BLI_split_dirfile(path, sfile->params->dir, sfile->params->file); } BLI_cleanup_dir(G.main->name, sfile->params->dir); BLI_add_slash(sfile->params->dir); file_change_dir(C, 1); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } return OPERATOR_FINISHED; }
static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) { FileSelect retval = FILE_SELECT_NOTHING; SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_params(sfile); int numfiles = filelist_numfiles(sfile->files); struct direntry *file; /* make the selected file active */ if ((selected_idx >= 0) && (selected_idx < numfiles) && (file = filelist_file(sfile->files, selected_idx))) { params->active_file = selected_idx; if (S_ISDIR(file->type)) { if (do_diropen == false) { params->file[0] = '\0'; retval = FILE_SELECT_DIR; } /* the path is too long and we are not going up! */ else if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) { // XXX error("Path too long, cannot enter this directory"); } else { if (strcmp(file->relname, "..") == 0) { /* avoids /../../ */ BLI_parent_dir(params->dir); } else { BLI_cleanup_dir(G.main->name, params->dir); strcat(params->dir, file->relname); BLI_add_slash(params->dir); } file_change_dir(C, 0); retval = FILE_SELECT_DIR; } } else { if (file->relname) { BLI_strncpy(params->file, file->relname, FILE_MAXFILE); } retval = FILE_SELECT_FILE; } } return retval; }
int file_parent_exec(bContext *C, wmOperator *UNUSED(unused)) { SpaceFile *sfile= CTX_wm_space_file(C); if(sfile->params) { if (BLI_has_parent(sfile->params->dir)) { BLI_parent_dir(sfile->params->dir); BLI_cleanup_dir(G.main->name, sfile->params->dir); file_change_dir(C, 0); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } } return OPERATOR_FINISHED; }
int BLI_parent_dir(char *path) { static char parent_dir[]= {'.', '.', SEP, '\0'}; /* "../" or "..\\" */ char tmp[FILE_MAXDIR+FILE_MAXFILE+4]; BLI_strncpy(tmp, path, sizeof(tmp)-4); BLI_add_slash(tmp); strcat(tmp, parent_dir); BLI_cleanup_dir(NULL, tmp); if (!BLI_testextensie(tmp, parent_dir)) { BLI_strncpy(path, tmp, sizeof(tmp)); return 1; } else { return 0; } }
static void filelist_read_dir(struct FileList* filelist) { char wdir[FILE_MAX]= ""; if (!filelist) return; filelist->fidx = NULL; filelist->filelist = NULL; BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ BLI_cleanup_dir(G.main->name, filelist->dir); filelist->numfiles = BLI_dir_contents(filelist->dir, &(filelist->filelist)); if (!chdir(wdir)) {} /* fix warning about not checking return value */ filelist_setfiletypes(filelist); filelist_filter(filelist); }
static void filelist_read_dir(struct FileList *filelist) { if (!filelist) return; filelist->fidx = NULL; filelist->filelist = NULL; BLI_make_exist(filelist->dir); BLI_cleanup_dir(G.main->name, filelist->dir); filelist->numfiles = BLI_filelist_dir_contents(filelist->dir, &(filelist->filelist)); /* We shall *never* get an empty list here, since we now the dir exists and is readable * (ensured by BLI_make_exist()). So we expect at the very least the parent '..' entry. */ BLI_assert(filelist->numfiles != 0); filelist_setfiletypes(filelist); }
static int bookmark_select_exec(bContext *C, wmOperator *op) { SpaceFile *sfile = CTX_wm_space_file(C); if (RNA_struct_find_property(op->ptr, "dir")) { char entry[256]; FileSelectParams *params = sfile->params; RNA_string_get(op->ptr, "dir", entry); BLI_strncpy(params->dir, entry, sizeof(params->dir)); BLI_cleanup_dir(G.main->name, params->dir); file_change_dir(C, 1); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } return OPERATOR_FINISHED; }
/** * \note RNA_struct_property_is_set_ex is used here because we want * the previously used settings to be used here rather then overriding them */ short ED_fileselect_set_params(SpaceFile *sfile) { 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_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); sfile->params->filter_glob[0] = '\0'; /* set the default thumbnails size */ sfile->params->thumbnail_size = 128; } params = sfile->params; /* set the parameters from the operator, if it exists */ if (op) { PropertyRNA *prop; const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL); const bool is_filepath = (RNA_struct_find_property(op->ptr, "filepath") != NULL); const bool is_filename = (RNA_struct_find_property(op->ptr, "filename") != NULL); const bool is_directory = (RNA_struct_find_property(op->ptr, "directory") != NULL); const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != NULL); BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title)); if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) { params->type = RNA_property_int_get(op->ptr, prop); } else { params->type = FILE_SPECIAL; } if (is_filepath && RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { char name[FILE_MAX]; RNA_string_get(op->ptr, "filepath", name); if (params->type == FILE_LOADLIB) { BLI_strncpy(params->dir, name, sizeof(params->dir)); sfile->params->file[0] = '\0'; } else { BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); } } else { if (is_directory && RNA_struct_property_is_set_ex(op->ptr, "directory", false)) { RNA_string_get(op->ptr, "directory", params->dir); sfile->params->file[0] = '\0'; } if (is_filename && RNA_struct_property_is_set_ex(op->ptr, "filename", false)) { RNA_string_get(op->ptr, "filename", params->file); } } if (params->dir[0]) { BLI_cleanup_dir(G.main->name, params->dir); BLI_path_abs(params->dir, G.main->name); } if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) { params->flag |= FILE_DIRSEL_ONLY; } else { params->flag &= ~FILE_DIRSEL_ONLY; } params->filter = 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER_BACKUP : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_image"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_IMAGE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_movie"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_MOVIE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_python"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_PYSCRIPT : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_font"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FTFONT : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_sound"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_SOUND : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_text"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_TEXT : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_folder"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FOLDER : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_btx"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BTX : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_collada"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_COLLADA : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_glob"))) { RNA_property_string_get(op->ptr, prop, params->filter_glob); params->filter |= (FILE_TYPE_OPERATOR | FILE_TYPE_FOLDER); } else { params->filter_glob[0] = '\0'; } if (params->filter != 0) { if (U.uiflag & USER_FILTERFILEEXTS) { params->flag |= FILE_FILTER; } else { params->flag &= ~FILE_FILTER; } } if (U.uiflag & USER_HIDE_DOT) { params->flag |= FILE_HIDE_DOT; } else { params->flag &= ~FILE_HIDE_DOT; } if (params->type == FILE_LOADLIB) { params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0; params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0; params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0; } if ((prop = RNA_struct_find_property(op->ptr, "display_type"))) { params->display = RNA_property_enum_get(op->ptr, prop); } if (params->display == FILE_DEFAULTDISPLAY) { if (U.uiflag & USER_SHOW_THUMBNAILS) { if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE)) params->display = FILE_IMGDISPLAY; else params->display = FILE_SHORTDISPLAY; } else { params->display = FILE_SHORTDISPLAY; } } if (is_relative_path) { if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { if (!RNA_property_is_set_ex(op->ptr, prop, false)) { RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS) != 0); } } } } 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'; } /* operator has no setting for this */ params->sort = FILE_SORT_ALPHA; params->active_file = -1; /* initialize the list with previous folders */ if (!sfile->folders_prev) sfile->folders_prev = folderlist_new(); if (!sfile->params->dir[0]) { if (G.main->name[0]) { BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir)); } else { const char *doc_path = BKE_appdir_folder_default(); if (doc_path) { BLI_strncpy(sfile->params->dir, doc_path, sizeof(sfile->params->dir)); } } } folderlist_pushdir(sfile->folders_prev, sfile->params->dir); /* switching thumbnails needs to recalc layout [#28809] */ if (sfile->layout) { sfile->layout->dirty = true; } return 1; }
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; /* set the parameters from the operator, if it exists */ if (op) { BLI_strncpy(params->title, op->type->name, sizeof(params->title)); if(RNA_struct_find_property(op->ptr, "filename")) params->type = RNA_int_get(op->ptr, "filemode"); else params->type = FILE_SPECIAL; if (RNA_property_is_set(op->ptr, "path")) { RNA_string_get(op->ptr, "path", name); if (params->type == FILE_LOADLIB) { BLI_strncpy(params->dir, name, sizeof(params->dir)); BLI_cleanup_dir(G.sce, params->dir); } else { /* if operator has path set, use it, otherwise keep the last */ 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 */ } } params->filter = 0; if(RNA_struct_find_property(op->ptr, "filter_blender")) params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_image")) params->filter |= RNA_boolean_get(op->ptr, "filter_image") ? IMAGEFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_movie")) params->filter |= RNA_boolean_get(op->ptr, "filter_movie") ? MOVIEFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_text")) params->filter |= RNA_boolean_get(op->ptr, "filter_text") ? TEXTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_python")) params->filter |= RNA_boolean_get(op->ptr, "filter_python") ? PYSCRIPTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_font")) params->filter |= RNA_boolean_get(op->ptr, "filter_font") ? FTFONTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_sound")) params->filter |= RNA_boolean_get(op->ptr, "filter_sound") ? SOUNDFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_text")) params->filter |= RNA_boolean_get(op->ptr, "filter_text") ? TEXTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_folder")) params->filter |= RNA_boolean_get(op->ptr, "filter_folder") ? FOLDERFILE : 0; if (params->filter != 0) params->flag |= FILE_FILTER; params->flag |= FILE_HIDE_DOT; if (params->type == FILE_LOADLIB) { params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0; params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0; params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0; } if(params->filter & (IMAGEFILE|MOVIEFILE)) params->display= FILE_IMGDISPLAY; else params->display= FILE_SHORTDISPLAY; } else { /* default values, if no operator */ params->type = FILE_UNIX; params->flag |= FILE_HIDE_DOT; params->display = FILE_SHORTDISPLAY; params->filter = 0; params->sort = FILE_SORT_ALPHA; } return 1; }
short ED_fileselect_set_params(SpaceFile *sfile) { 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_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); sfile->params->filter_glob[0] = '\0'; } params = sfile->params; /* set the parameters from the operator, if it exists */ if (op) { const short is_files= (RNA_struct_find_property(op->ptr, "files") != NULL); const short is_filepath= (RNA_struct_find_property(op->ptr, "filepath") != NULL); const short is_filename= (RNA_struct_find_property(op->ptr, "filename") != NULL); const short is_directory= (RNA_struct_find_property(op->ptr, "directory") != NULL); const short is_relative_path= (RNA_struct_find_property(op->ptr, "relative_path") != NULL); BLI_strncpy(params->title, op->type->name, sizeof(params->title)); if(RNA_struct_find_property(op->ptr, "filemode")) params->type = RNA_int_get(op->ptr, "filemode"); else params->type = FILE_SPECIAL; if (is_filepath && RNA_struct_property_is_set(op->ptr, "filepath")) { char name[FILE_MAX]; RNA_string_get(op->ptr, "filepath", name); if (params->type == FILE_LOADLIB) { BLI_strncpy(params->dir, name, sizeof(params->dir)); sfile->params->file[0]= '\0'; } else { BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); } } else { if (is_directory && RNA_struct_property_is_set(op->ptr, "directory")) { RNA_string_get(op->ptr, "directory", params->dir); sfile->params->file[0]= '\0'; } if (is_filename && RNA_struct_property_is_set(op->ptr, "filename")) { RNA_string_get(op->ptr, "filename", params->file); } } if(params->dir[0]) { BLI_cleanup_dir(G.main->name, params->dir); BLI_path_abs(params->dir, G.main->name); } if(is_directory==TRUE && is_filename==FALSE && is_filepath==FALSE && is_files==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; if(RNA_struct_find_property(op->ptr, "filter_image")) params->filter |= RNA_boolean_get(op->ptr, "filter_image") ? IMAGEFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_movie")) params->filter |= RNA_boolean_get(op->ptr, "filter_movie") ? MOVIEFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_text")) params->filter |= RNA_boolean_get(op->ptr, "filter_text") ? TEXTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_python")) params->filter |= RNA_boolean_get(op->ptr, "filter_python") ? PYSCRIPTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_font")) params->filter |= RNA_boolean_get(op->ptr, "filter_font") ? FTFONTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_sound")) params->filter |= RNA_boolean_get(op->ptr, "filter_sound") ? SOUNDFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_text")) params->filter |= RNA_boolean_get(op->ptr, "filter_text") ? TEXTFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_folder")) params->filter |= RNA_boolean_get(op->ptr, "filter_folder") ? FOLDERFILE : 0; if(RNA_struct_find_property(op->ptr, "filter_btx")) 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); } else { params->filter_glob[0] = '\0'; } if (params->filter != 0) { if (U.uiflag & USER_FILTERFILEEXTS) { params->flag |= FILE_FILTER; } else { params->flag &= ~FILE_FILTER; } } if (U.uiflag & USER_HIDE_DOT) { params->flag |= FILE_HIDE_DOT; } else { params->flag &= ~FILE_HIDE_DOT; } if (params->type == FILE_LOADLIB) { params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0; params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0; params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0; } if(RNA_struct_find_property(op->ptr, "display_type")) params->display= RNA_enum_get(op->ptr, "display_type"); if(params->display==FILE_DEFAULTDISPLAY) { if (U.uiflag & USER_SHOW_THUMBNAILS) { if(params->filter & (IMAGEFILE|MOVIEFILE)) params->display= FILE_IMGDISPLAY; else params->display= FILE_SHORTDISPLAY; } else { params->display= FILE_SHORTDISPLAY; } } if (is_relative_path) { if (!RNA_struct_property_is_set(op->ptr, "relative_path")) { RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS); } } } 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'; params->sort = FILE_SORT_ALPHA; } /* initialize the list with previous folders */ if (!sfile->folders_prev) sfile->folders_prev = folderlist_new(); folderlist_pushdir(sfile->folders_prev, sfile->params->dir); /* switching thumbnails needs to recalc layout [#28809] */ if (sfile->layout) { sfile->layout->dirty= TRUE; } return 1; }