From deebf4f8f0d79169a0e6c2a391670419b6492bfe Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Wed, 16 Sep 2009 17:43:09 +0000 Subject: merge with 2.5/trunk at r23271 --- source/blender/editors/space_file/file_intern.h | 2 +- source/blender/editors/space_file/file_ops.c | 92 ++++-- source/blender/editors/space_file/file_panels.c | 24 +- source/blender/editors/space_file/filelist.c | 356 +++++++++++++++++++++++- source/blender/editors/space_file/filelist.h | 12 +- source/blender/editors/space_file/filesel.c | 55 ++-- source/blender/editors/space_file/space_file.c | 48 +++- 7 files changed, 502 insertions(+), 87 deletions(-) (limited to 'source/blender/editors/space_file') diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 9f1e4ad0e25..a99594e9575 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -59,7 +59,7 @@ void FILE_OT_add_bookmark(struct wmOperatorType *ot); void FILE_OT_delete_bookmark(struct wmOperatorType *ot); void FILE_OT_hidedot(struct wmOperatorType *ot); void FILE_OT_loadimages(struct wmOperatorType *ot); -void FILE_OT_exec(struct wmOperatorType *ot); +void FILE_OT_execute(struct wmOperatorType *ot); void FILE_OT_cancel(struct wmOperatorType *ot); void FILE_OT_parent(struct wmOperatorType *ot); void FILE_OT_directory_new(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 9c73956d375..0e0ad88906e 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -190,9 +190,9 @@ static int file_border_select_exec(bContext *C, wmOperator *op) BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect); if (FILE_SELECT_DIR == file_select(sfile, ar, &rect, val )) { - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } else { - WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL); } return OPERATOR_FINISHED; } @@ -239,12 +239,12 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) file_deselect_all(sfile); if (FILE_SELECT_DIR == file_select(sfile, ar, &rect, val )) - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); else - WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL); WM_event_add_mousemove(C); /* for directory changes */ - WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL); return OPERATOR_FINISHED; } @@ -322,7 +322,7 @@ static int bookmark_select_invoke(bContext *C, wmOperator *op, wmEvent *event) BLI_cleanup_dir(G.sce, params->dir); file_change_dir(sfile); - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } return OPERATOR_FINISHED; @@ -496,6 +496,12 @@ int file_cancel_exec(bContext *C, wmOperator *unused) WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL); sfile->op = NULL; + if (sfile->files) { + filelist_free(sfile->files); + MEM_freeN(sfile->files); + sfile->files= NULL; + } + return OPERATOR_FINISHED; } @@ -520,9 +526,15 @@ int file_exec(bContext *C, wmOperator *unused) wmOperator *op= sfile->op; sfile->op = NULL; + RNA_string_set(op->ptr, "filename", sfile->params->file); BLI_strncpy(name, sfile->params->dir, sizeof(name)); + RNA_string_set(op->ptr, "directory", name); strcat(name, sfile->params->file); - RNA_string_set(op->ptr, "filename", name); + + if ( RNA_boolean_get(op->ptr, "relative_paths") ) { + BLI_makestringcode(G.sce, name); + } + RNA_string_set(op->ptr, "path", name); /* some ops have multiple files to select */ { @@ -561,16 +573,20 @@ int file_exec(bContext *C, wmOperator *unused) BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs"); fsmenu_write_file(fsmenu_get(), name); WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC); + + filelist_free(sfile->files); + MEM_freeN(sfile->files); + sfile->files= NULL; } return OPERATOR_FINISHED; } -void FILE_OT_exec(struct wmOperatorType *ot) +void FILE_OT_execute(struct wmOperatorType *ot) { /* identifiers */ ot->name= "Execute File Window"; - ot->idname= "FILE_OT_exec"; + ot->idname= "FILE_OT_execute"; /* api callbacks */ ot->exec= file_exec; @@ -587,7 +603,7 @@ int file_parent_exec(bContext *C, wmOperator *unused) BLI_parent_dir(sfile->params->dir); BLI_cleanup_dir(G.sce, sfile->params->dir); file_change_dir(sfile); - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } } @@ -614,7 +630,7 @@ int file_refresh_exec(bContext *C, wmOperator *unused) file_change_dir(sfile); - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; @@ -645,7 +661,7 @@ int file_previous_exec(bContext *C, wmOperator *unused) file_change_dir(sfile); } - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; } @@ -676,7 +692,7 @@ int file_next_exec(bContext *C, wmOperator *unused) file_change_dir(sfile); } - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; } @@ -699,13 +715,15 @@ int file_directory_new_exec(bContext *C, wmOperator *unused) BLI_join_dirfile(tmpstr, tmpstr, tmpdir); } BLI_recurdir_fileops(tmpstr); - if (!BLI_exists(tmpstr)) { + if (BLI_exists(tmpstr)) { + BLI_strncpy(sfile->params->renamefile, tmpdir, FILE_MAXFILE); + } else { filelist_free(sfile->files); filelist_parent(sfile->files); BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), FILE_MAX); } } - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; } @@ -754,7 +772,7 @@ int file_directory_exec(bContext *C, wmOperator *unused) BLI_cleanup_dir(G.sce, sfile->params->dir); BLI_add_slash(sfile->params->dir); file_change_dir(sfile); - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } @@ -769,7 +787,7 @@ int file_filename_exec(bContext *C, wmOperator *unused) if (file_select_match(sfile, sfile->params->file)) { sfile->params->file[0] = '\0'; - WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL); } } @@ -796,7 +814,7 @@ int file_hidedot_exec(bContext *C, wmOperator *unused) sfile->params->flag ^= FILE_HIDE_DOT; filelist_free(sfile->files); sfile->params->active_file = -1; - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); } return OPERATOR_FINISHED; @@ -847,13 +865,9 @@ int file_bookmark_toggle_exec(bContext *C, wmOperator *unused) ScrArea *sa= CTX_wm_area(C); ARegion *ar= file_buttons_region(sa); - if(ar) { - ar->flag ^= RGN_FLAG_HIDDEN; - ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */ - - ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa); - ED_area_tag_redraw(sa); - } + if(ar) + ED_region_toggle_hidden(C, ar); + return OPERATOR_FINISHED; } @@ -872,11 +886,13 @@ void FILE_OT_bookmark_toggle(struct wmOperatorType *ot) int file_filenum_exec(bContext *C, wmOperator *op) { SpaceFile *sfile= CTX_wm_space_file(C); + ScrArea *sa= CTX_wm_area(C); int inc = RNA_int_get(op->ptr, "increment"); if(sfile->params && (inc != 0)) { BLI_newname(sfile->params->file, inc); - WM_event_add_notifier(C, NC_WINDOW, NULL); + ED_area_tag_redraw(sa); + // WM_event_add_notifier(C, NC_WINDOW, NULL); } return OPERATOR_FINISHED; @@ -916,6 +932,24 @@ int file_rename_exec(bContext *C, wmOperator *op) } +int file_rename_poll(bContext *C) +{ + int poll = ED_operator_file_active(C); + SpaceFile *sfile= CTX_wm_space_file(C); + + if (sfile && sfile->params) { + if (sfile->params->active_file < 0) { + poll= 0; + } else { + char dir[FILE_MAX], group[FILE_MAX]; + if (filelist_islibrary(sfile->files, dir, group)) poll= 0; + } + } + else + poll= 0; + return poll; +} + void FILE_OT_rename(struct wmOperatorType *ot) { /* identifiers */ @@ -924,7 +958,7 @@ void FILE_OT_rename(struct wmOperatorType *ot) /* api callbacks */ ot->exec= file_rename_exec; - ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ + ot->poll= file_rename_poll; } @@ -938,6 +972,8 @@ int file_delete_poll(bContext *C) if (sfile->params->active_file < 0) { poll= 0; } else { + char dir[FILE_MAX], group[FILE_MAX]; + if (filelist_islibrary(sfile->files, dir, group)) poll= 0; file = filelist_file(sfile->files, sfile->params->active_file); if (file && S_ISDIR(file->type)) poll= 0; } @@ -958,7 +994,7 @@ int file_delete_exec(bContext *C, wmOperator *op) file = filelist_file(sfile->files, sfile->params->active_file); BLI_make_file_string(G.sce, str, sfile->params->dir, file->relname); BLI_delete(str, 0, 0); - WM_event_add_notifier(C, NC_FILE | ND_FILELIST, NULL); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c index c48b3529389..1b54277c383 100644 --- a/source/blender/editors/space_file/file_panels.c +++ b/source/blender/editors/space_file/file_panels.c @@ -63,7 +63,7 @@ static void file_panel_cb(bContext *C, void *arg_entry, void *arg_unused) WM_operator_properties_free(&ptr); } -static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, short *nr, int icon, int allow_delete) +static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, short *nr, int icon, int allow_delete, int reverse) { SpaceFile *sfile= CTX_wm_space_file(C); uiBlock *block; @@ -71,7 +71,7 @@ static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory cat uiLayout *box, *col; struct FSMenu* fsmenu = fsmenu_get(); char *curdir= (sfile->params)? sfile->params->dir: ""; - int i, nentries = fsmenu_get_nentries(fsmenu, category); + int i, i_iter, nentries = fsmenu_get_nentries(fsmenu, category); /* reset each time */ *nr= -1; @@ -86,12 +86,16 @@ static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory cat box= uiLayoutBox(pa->layout); col= uiLayoutColumn(box, 1); - for (i=0; i< nentries;++i) { + for (i_iter=0; i_iter< nentries;++i_iter) { char dir[FILE_MAX]; char temp[FILE_MAX]; uiLayout* layout = uiLayoutRow(col, 0); - char *entry = fsmenu_get_entry(fsmenu, category, i); + char *entry; + i= reverse ? nentries-(i_iter+1) : i_iter; + + entry = fsmenu_get_entry(fsmenu, category, i); + /* set this list item as active if we have a match */ if(strcmp(curdir, entry) == 0) *nr= i; @@ -124,7 +128,7 @@ static void file_panel_system(const bContext *C, Panel *pa) SpaceFile *sfile= CTX_wm_space_file(C); if(sfile) - file_panel_category(C, pa, FS_CATEGORY_SYSTEM, &sfile->systemnr, ICON_DISK_DRIVE, 0); + file_panel_category(C, pa, FS_CATEGORY_SYSTEM, &sfile->systemnr, ICON_DISK_DRIVE, 0, 0); } static void file_panel_bookmarks(const bContext *C, Panel *pa) @@ -137,7 +141,7 @@ static void file_panel_bookmarks(const bContext *C, Panel *pa) uiItemO(row, "Add", ICON_ZOOMIN, "file.add_bookmark"); uiItemL(row, NULL, 0); - file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, &sfile->bookmarknr, ICON_BOOKMARKS, 1); + file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, &sfile->bookmarknr, ICON_BOOKMARKS, 1, 0); } } @@ -146,7 +150,7 @@ static void file_panel_recent(const bContext *C, Panel *pa) SpaceFile *sfile= CTX_wm_space_file(C); if(sfile) - file_panel_category(C, pa, FS_CATEGORY_RECENT, &sfile->recentnr, ICON_FILE_FOLDER, 0); + file_panel_category(C, pa, FS_CATEGORY_RECENT, &sfile->recentnr, ICON_FILE_FOLDER, 0, 1); } @@ -177,6 +181,12 @@ static void file_panel_operator(const bContext *C, Panel *pa) RNA_STRUCT_BEGIN(op->ptr, prop) { if(strcmp(RNA_property_identifier(prop), "rna_type") == 0) continue; + if(strcmp(RNA_property_identifier(prop), "filemode") == 0) + continue; + if(strcmp(RNA_property_identifier(prop), "path") == 0) + continue; + if(strcmp(RNA_property_identifier(prop), "directory") == 0) + continue; if(strcmp(RNA_property_identifier(prop), "filename") == 0) continue; if(strcmp(RNA_property_identifier(prop), "display") == 0) diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 538c1e4fce7..c0b16e639c0 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -60,6 +60,7 @@ #include "BKE_library.h" #include "BKE_global.h" #include "BKE_main.h" +#include "BKE_report.h" #include "BLO_readfile.h" #include "DNA_space_types.h" @@ -109,7 +110,6 @@ typedef struct FileList { struct direntry *filelist; int *fidx; - int numfiles; int numfiltered; char dir[FILE_MAX]; @@ -118,6 +118,12 @@ typedef struct FileList short hide_dot; unsigned int filter; short changed; + + struct BlendHandle *libfiledata; + short hide_parent; + + void (*read)(struct FileList *); + ListBase loadimages; ListBase threads; } FileList; @@ -277,12 +283,20 @@ static int compare_extension(const void *a1, const void *a2) { 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); @@ -438,23 +452,29 @@ void folderlist_free(ListBase* folderlist) folderlist= NULL; } +static void filelist_read_main(struct FileList* filelist); +static void filelist_read_library(struct FileList* filelist); +static void filelist_read_dir(struct FileList* filelist); + //------------------FILELIST------------------------// -struct FileList* filelist_new() +struct FileList* filelist_new(short type) { FileList* p = MEM_callocN( sizeof(FileList), "filelist" ); - return p; -} - -struct FileList* filelist_copy(struct FileList* filelist) -{ - FileList* p = filelist_new(); - BLI_strncpy(p->dir, filelist->dir, FILE_MAX); - p->filelist = NULL; - p->fidx = NULL; + switch(type) { + case FILE_MAIN: + p->read = filelist_read_main; + break; + case FILE_LOADLIB: + p->read = filelist_read_library; + break; + default: + p->read = filelist_read_dir; + } return p; } + void filelist_free(struct FileList* filelist) { int i; @@ -493,6 +513,18 @@ void filelist_free(struct FileList* filelist) filelist->hide_dot =0; } +void filelist_freelib(struct FileList* filelist) +{ + if(filelist->libfiledata) + BLO_blendhandle_close(filelist->libfiledata); + filelist->libfiledata= 0; +} + +struct BlendHandle *filelist_lib(struct FileList* filelist) +{ + return filelist->libfiledata; +} + int filelist_numfiles(struct FileList* filelist) { return filelist->numfiltered; @@ -733,16 +765,16 @@ void filelist_setfilter(struct FileList* filelist, unsigned int filter) filelist->filter = filter; } -void filelist_readdir(struct FileList* filelist) +static void filelist_read_dir(struct FileList* filelist) { char wdir[FILE_MAX]; - if (!filelist) return; + filelist->fidx = 0; filelist->filelist = 0; 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)); @@ -750,12 +782,50 @@ void filelist_readdir(struct FileList* filelist) chdir(wdir); filelist_setfiletypes(filelist, G.have_quicktime); filelist_filter(filelist); - + if (!filelist->threads.first) { BLI_init_threads(&filelist->threads, exec_loadimages, 2); } } +static void filelist_read_main(struct FileList* filelist) +{ + if (!filelist) return; + filelist_from_main(filelist); +} + +static void filelist_read_library(struct FileList* filelist) +{ + if (!filelist) return; + BLI_cleanup_dir(G.sce, filelist->dir); + filelist_from_library(filelist); + if(!filelist->libfiledata) { + int num; + struct direntry *file; + filelist_read_dir(filelist); + file = filelist->filelist; + for(num=0; numnumfiles; num++, file++) { + if(BLO_has_bfile_extension(file->relname)) { + char name[FILE_MAXDIR+FILE_MAXFILE]; + + BLI_strncpy(name, filelist->dir, sizeof(name)); + strcat(name, file->relname); + + /* prevent current file being used as acceptable dir */ + if (BLI_streq(G.main->name, name)==0) { + file->type &= ~S_IFMT; + file->type |= S_IFDIR; + } + } + } + } +} + +void filelist_readdir(struct FileList* filelist) +{ + filelist->read(filelist); +} + int filelist_empty(struct FileList* filelist) { return filelist->filelist == 0; @@ -937,3 +1007,259 @@ void filelist_sort(struct FileList* filelist, short sort) filelist_filter(filelist); } + + +int filelist_islibrary(struct FileList* filelist, char* dir, char* group) +{ + return BLO_is_a_library(filelist->dir, dir, group); +} + +static int groupname_to_code(char *group) +{ + char buf[32]; + char *lslash; + + BLI_strncpy(buf, group, 31); + lslash= BLI_last_slash(buf); + if (lslash) + lslash[0]= '\0'; + + return BLO_idcode_from_name(buf); +} + +void filelist_from_library(struct FileList* filelist) +{ + LinkNode *l, *names, *previews; + struct ImBuf* ima; + int ok, i, nnames, idcode; + char filename[FILE_MAXDIR+FILE_MAXFILE]; + char dir[FILE_MAX], group[GROUP_MAX]; + + /* name test */ + ok= filelist_islibrary(filelist, dir, group); + if (!ok) { + /* free */ + if(filelist->libfiledata) BLO_blendhandle_close(filelist->libfiledata); + filelist->libfiledata= 0; + return; + } + + BLI_strncpy(filename, G.sce, sizeof(filename)); // G.sce = last file loaded, for UI + + /* there we go */ + /* for the time being only read filedata when libfiledata==0 */ + if (filelist->libfiledata==0) { + filelist->libfiledata= BLO_blendhandle_from_file(dir); + if(filelist->libfiledata==0) return; + } + + idcode= groupname_to_code(group); + + // memory for strings is passed into filelist[i].relname + // and free'd in freefilelist + previews = NULL; + if (idcode) { + previews= BLO_blendhandle_get_previews(filelist->libfiledata, idcode); + names= BLO_blendhandle_get_datablock_names(filelist->libfiledata, idcode); + /* ugh, no rewind, need to reopen */ + BLO_blendhandle_close(filelist->libfiledata); + filelist->libfiledata= BLO_blendhandle_from_file(dir); + + } else { + names= BLO_blendhandle_get_linkable_groups(filelist->libfiledata); + } + + nnames= BLI_linklist_length(names); + + filelist->numfiles= nnames + 1; + filelist->filelist= malloc(filelist->numfiles * sizeof(*filelist->filelist)); + memset(filelist->filelist, 0, filelist->numfiles * sizeof(*filelist->filelist)); + + filelist->filelist[0].relname= BLI_strdup(".."); + filelist->filelist[0].type |= S_IFDIR; + + for (i=0, l= names; inext) { + char *blockname= l->link; + + filelist->filelist[i + 1].relname= BLI_strdup(blockname); + if (!idcode) + filelist->filelist[i + 1].type |= S_IFDIR; + } + + if(previews) { + for (i=0, l= previews; inext) { + PreviewImage *img= l->link; + + if (img) { + unsigned int w = img->w[PREVIEW_MIPMAP_LARGE]; + unsigned int h = img->h[PREVIEW_MIPMAP_LARGE]; + unsigned int *rect = img->rect[PREVIEW_MIPMAP_LARGE]; + + /* first allocate imbuf for copying preview into it */ + if (w > 0 && h > 0 && rect) { + ima = IMB_allocImBuf(w, h, 32, IB_rect, 0); + memcpy(ima->rect, rect, w*h*sizeof(unsigned int)); + filelist->filelist[i + 1].image = ima; + filelist->filelist[i + 1].flags = IMAGEFILE; + } + } + } + } + + BLI_linklist_free(names, free); + if (previews) BLI_linklist_free(previews, (void(*)(void*)) MEM_freeN); + + filelist_sort(filelist, FILE_SORT_ALPHA); + + BLI_strncpy(G.sce, filename, sizeof(filename)); // prevent G.sce to change + + filelist->filter = 0; + filelist_filter(filelist); +} + +void filelist_hideparent(struct FileList* filelist, short hide) +{ + filelist->hide_parent = hide; +} + +void filelist_from_main(struct FileList *filelist) +{ + ID *id; + struct direntry *files, *firstlib = NULL; + ListBase *lb; + int a, fake, idcode, ok, totlib, totbl; + + // filelist->type = FILE_MAIN; // XXXXX TODO: add modes to filebrowser + + if(filelist->dir[0]=='/') filelist->dir[0]= 0; + + if(filelist->dir[0]) { + idcode= groupname_to_code(filelist->dir); + if(idcode==0) filelist->dir[0]= 0; + } + + if( filelist->dir[0]==0) { + + /* make directories */ + filelist->numfiles= 23; + filelist->filelist= (struct direntry *)malloc(filelist->numfiles * sizeof(struct direntry)); + + for(a=0; anumfiles; a++) { + memset( &(filelist->filelist[a]), 0 , sizeof(struct direntry)); + filelist->filelist[a].type |= S_IFDIR; + } + + filelist->filelist[0].relname= BLI_strdup(".."); + filelist->filelist[2].relname= BLI_strdup("Scene"); + filelist->filelist[3].relname= BLI_strdup("Object"); + filelist->filelist[4].relname= BLI_strdup("Mesh"); + filelist->filelist[5].relname= BLI_strdup("Curve"); + filelist->filelist[6].relname= BLI_strdup("Metaball"); + filelist->filelist[7].relname= BLI_strdup("Material"); + filelist->filelist[8].relname= BLI_strdup("Texture"); + filelist->filelist[9].relname= BLI_strdup("Image"); + filelist->filelist[10].relname= BLI_strdup("Ika"); + filelist->filelist[11].relname= BLI_strdup("Wave"); + filelist->filelist[12].relname= BLI_strdup("Lattice"); + filelist->filelist[13].relname= BLI_strdup("Lamp"); + filelist->filelist[14].relname= BLI_strdup("Camera"); + filelist->filelist[15].relname= BLI_strdup("Ipo"); + filelist->filelist[16].relname= BLI_strdup("World"); + filelist->filelist[17].relname= BLI_strdup("Screen"); + filelist->filelist[18].relname= BLI_strdup("VFont"); + filelist->filelist[19].relname= BLI_strdup("Text"); + filelist->filelist[20].relname= BLI_strdup("Armature"); + filelist->filelist[21].relname= BLI_strdup("Action"); + filelist->filelist[22].relname= BLI_strdup("NodeTree"); + filelist_sort(filelist, FILE_SORT_ALPHA); + } + else { + + /* make files */ + idcode= groupname_to_code(filelist->dir); + + lb= wich_libbase(G.main, idcode ); + if(lb==0) return; + + id= lb->first; + filelist->numfiles= 0; + while(id) { + if (!filelist->hide_dot || id->name[2] != '.') { + filelist->numfiles++; + } + + id= id->next; + } + + /* XXXXX TODO: if databrowse F4 or append/link filelist->hide_parent has to be set */ + if (!filelist->hide_parent) filelist->numfiles+= 1; + filelist->filelist= (struct direntry *)malloc(filelist->numfiles * sizeof(struct direntry)); + + files = filelist->filelist; + + if (!filelist->hide_parent) { + memset( &(filelist->filelist[0]), 0 , sizeof(struct direntry)); + filelist->filelist[0].relname= BLI_strdup(".."); + filelist->filelist[0].type |= S_IFDIR; + + files++; + } + + id= lb->first; + totlib= totbl= 0; + + while(id) { + ok = 1; + if(ok) { + if (!filelist->hide_dot || id->name[2] != '.') { + memset( files, 0 , sizeof(struct direntry)); + if(id->lib==NULL) + files->relname= BLI_strdup(id->name+2); + else { + files->relname= MEM_mallocN(FILE_MAXDIR+FILE_MAXFILE+32, "filename for lib"); + sprintf(files->relname, "%s | %s", id->lib->name, id->name+2); + } + /* files->type |= S_IFDIR; */ +#if 0 // XXXXX TODO show the selection status of the objects + if(!filelist->has_func) { /* F4 DATA BROWSE */ + if(idcode==ID_OB) { + if( ((Object *)id)->flag & SELECT) files->flags |= ACTIVE; + } + else if(idcode==ID_SCE) { + if( ((Scene *)id)->r.scemode & R_BG_RENDER) files->flags |= ACTIVE; + } + } +#endif + files->nr= totbl+1; + files->poin= id; + fake= id->flag & LIB_FAKEUSER; + if(idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) { + files->flags |= IMAGEFILE; + } + if(id->lib && fake) sprintf(files->extra, "LF %d", id->us); + else if(id->lib) sprintf(files->extra, "L %d", id->us); + else if(fake) sprintf(files->extra, "F %d", id->us); + else sprintf(files->extra, " %d", id->us); + + if(id->lib) { + if(totlib==0) firstlib= files; + totlib++; + } + + files++; + } + totbl++; + } + + id= id->next; + } + + /* only qsort of library blocks */ + if(totlib>1) { + qsort(firstlib, totlib, sizeof(struct direntry), compare_name); + } + } + filelist->filter = 0; + filelist_filter(filelist); +} + diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index dd3c2c766c1..a8d909f899e 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -42,12 +42,13 @@ struct FolderList; struct direntry; struct BlendHandle; struct Scene; +struct Main; struct rcti; +struct ReportList; -struct FileList * filelist_new(); +struct FileList * filelist_new(short type); void filelist_init_icons(); void filelist_free_icons(); -struct FileList * filelist_copy(struct FileList* filelist); int filelist_find(struct FileList* filelist, char *file); void filelist_free(struct FileList* filelist); void filelist_sort(struct FileList* filelist, short sort); @@ -71,6 +72,13 @@ int filelist_empty(struct FileList* filelist); void filelist_parent(struct FileList* filelist); void filelist_setfiletypes(struct FileList* filelist, short has_quicktime); + +int filelist_islibrary (struct FileList* filelist, char* dir, char* group); +void filelist_from_main(struct FileList* filelist); +void filelist_from_library(struct FileList* filelist); +void filelist_freelib(struct FileList* filelist); +void filelist_hideparent(struct FileList* filelist, short hide); + struct ListBase * folderlist_new(); void folderlist_free(struct ListBase* folderlist); void folderlist_popdir(struct ListBase* folderlist, char *dir); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index f300505933f..a0787ef989d 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -117,12 +117,30 @@ short ED_fileselect_set_params(SpaceFile *sfile) 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 */ } + + ED_fileselect_reset_params(sfile); params = sfile->params; /* set the parameters from the operator, if it exists */ if (op) { BLI_strncpy(params->title, op->type->name, sizeof(params->title)); + + params->type = RNA_int_get(op->ptr, "filemode"); + + 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; params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0; params->filter |= RNA_boolean_get(op->ptr, "filter_image") ? IMAGEFILE : 0; @@ -137,36 +155,33 @@ short ED_fileselect_set_params(SpaceFile *sfile) 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; - /* 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->type = FILE_UNIX; params->flag |= FILE_HIDE_DOT; params->display = FILE_SHORTDISPLAY; params->filter = 0; params->sort = FILE_SORT_ALPHA; } - /* new params, refresh file list */ - if(sfile->files) filelist_free(sfile->files); - return 1; } void ED_fileselect_reset_params(SpaceFile *sfile) { + sfile->params->type = FILE_UNIX; sfile->params->flag = 0; sfile->params->title[0] = '\0'; } @@ -357,19 +372,15 @@ FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar void file_change_dir(struct SpaceFile *sfile) { if (sfile->params) { - if (BLI_exists(sfile->params->dir)) { - filelist_setdir(sfile->files, sfile->params->dir); + filelist_setdir(sfile->files, sfile->params->dir); - if(folderlist_clear_next(sfile)) - folderlist_free(sfile->folders_next); + if(folderlist_clear_next(sfile)) + folderlist_free(sfile->folders_next); - folderlist_pushdir(sfile->folders_prev, sfile->params->dir); + folderlist_pushdir(sfile->folders_prev, sfile->params->dir); - filelist_free(sfile->files); - sfile->params->active_file = -1; - } else { - BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), FILE_MAX); - } + filelist_free(sfile->files); + sfile->params->active_file = -1; } } diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 22ad03f3523..27948618d03 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -45,6 +45,7 @@ #include "BLI_blenlib.h" #include "BLI_arithb.h" #include "BLI_rand.h" +#include "BLI_storage_types.h" #include "BKE_colortools.h" #include "BKE_context.h" @@ -119,6 +120,7 @@ static void file_free(SpaceLink *sl) SpaceFile *sfile= (SpaceFile *) sl; if(sfile->files) { + filelist_freelib(sfile->files); filelist_free(sfile->files); MEM_freeN(sfile->files); sfile->files= NULL; @@ -153,6 +155,17 @@ static void file_free(SpaceLink *sl) /* spacetype; init callback, area size changes, screen set, etc */ static void file_init(struct wmWindowManager *wm, ScrArea *sa) { + SpaceFile *sfile= (SpaceFile*)sa->spacedata.first; + if(sfile->params) { + MEM_freeN(sfile->params); + sfile->params = 0; + ED_fileselect_set_params(sfile); + if (sfile->files) { + filelist_free(sfile->files); + MEM_freeN(sfile->files); + sfile->files= NULL; + } + } printf("file_init\n"); } @@ -165,7 +178,8 @@ static SpaceLink *file_duplicate(SpaceLink *sl) /* clear or remove stuff from old */ sfilen->op = NULL; /* file window doesn't own operators */ - sfilen->files = filelist_new(); + if (sfileo->params) + sfilen->files = filelist_new(sfileo->params->type); if(sfileo->folders_prev) sfilen->folders_prev = MEM_dupallocN(sfileo->folders_prev); @@ -190,7 +204,7 @@ static void file_refresh(const bContext *C, ScrArea *sa) if (!sfile->folders_prev) sfile->folders_prev = folderlist_new(); if (!sfile->files) { - sfile->files = filelist_new(); + sfile->files = filelist_new(params->type); file_change_dir(sfile); params->active_file = -1; // added this so it opens nicer (ton) } @@ -201,7 +215,17 @@ static void file_refresh(const bContext *C, ScrArea *sa) filelist_readdir(sfile->files); } if(params->sort!=FILE_SORT_NONE) filelist_sort(sfile->files, params->sort); - + + if (params->renamefile[0] != '\0') { + int idx = filelist_find(sfile->files, params->renamefile); + if (idx >= 0) { + struct direntry *file= filelist_file(sfile->files, idx); + if (file) { + file->flags |= EDITING; + } + } + params->renamefile[0] = '\0'; + } if (sfile->layout) sfile->layout->dirty= 1; } @@ -212,14 +236,14 @@ static void file_listener(ScrArea *sa, wmNotifier *wmn) /* context changes */ switch(wmn->category) { - case NC_FILE: + case NC_SPACE: switch (wmn->data) { - case ND_FILELIST: + case ND_SPACE_FILE_LIST: if (sfile->files) filelist_free(sfile->files); ED_area_tag_refresh(sa); ED_area_tag_redraw(sa); break; - case ND_PARAMS: + case ND_SPACE_FILE_PARAMS: ED_area_tag_refresh(sa); ED_area_tag_redraw(sa); break; @@ -249,12 +273,12 @@ static void file_main_area_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ switch(wmn->category) { - case NC_FILE: + case NC_SPACE: switch (wmn->data) { - case ND_FILELIST: + case ND_SPACE_FILE_LIST: ED_region_tag_redraw(ar); break; - case ND_PARAMS: + case ND_SPACE_FILE_PARAMS: ED_region_tag_redraw(ar); break; } @@ -330,7 +354,7 @@ void file_operatortypes(void) WM_operatortype_append(FILE_OT_select_bookmark); WM_operatortype_append(FILE_OT_loadimages); WM_operatortype_append(FILE_OT_highlight); - WM_operatortype_append(FILE_OT_exec); + WM_operatortype_append(FILE_OT_execute); WM_operatortype_append(FILE_OT_cancel); WM_operatortype_append(FILE_OT_parent); WM_operatortype_append(FILE_OT_previous); @@ -470,9 +494,9 @@ static void file_ui_area_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ switch(wmn->category) { - case NC_FILE: + case NC_SPACE: switch (wmn->data) { - case ND_FILELIST: + case ND_SPACE_FILE_LIST: ED_region_tag_redraw(ar); break; } -- cgit v1.2.3