diff options
author | Andrea Weikert <elubie@gmx.net> | 2007-09-02 21:25:03 +0400 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2007-09-02 21:25:03 +0400 |
commit | 356ab943736e8a2434a8ff5845873482597ba5e2 (patch) | |
tree | 910356ace904dc4f11f1daf15330bb0827934f5b /source/blender/src/fsmenu.c | |
parent | 22c23fb04f7f1297b971f03d69b8b04b7dd9caa4 (diff) |
== imagebrowser ==
Initial commit of imagebrowser in trunk.
BIG COMMIT!
Main changes:
* completely reworked imasel space
* creation and storage of the preview images for materials, textures, world and lamp
* thumbnails of images and movie files when browsing in the file system
* loading previews from external .blend when linking or appending
* thumbnail caching according to the Thumbnail Managing Standard: http://jens.triq.net/thumbnail-spec/
* for now just kept imasel access mostly as old imgbrowser (CTRL+F4, CTRL+F1) a bit hidden still.
* filtering of file types (images, movies, .blend, py,...)
* preliminary managing of bookmarks ('B' button to add, XKEY while bookmark active to delete)
More detailed info which will be updated here: http://wiki.blender.org/index.php/User:Elubie/PreviewImageBrowser
Places that need special review (and probably fixes):
* BLO_blendhandle_get_previews in readblenentry
* readfile.c: do_version and refactorings of do_library_append
* UI integration
TODO and known issues still:
* Accented characters do not display correctly with international fonts
* Crash was reported when browsing in directory with movie files
* Bookmark management still needs some UI work (second scrollbar?), feedback here is welcome!
Credits:
Samir Bharadwaj (samirbharadwaj@yahoo.com) for the icon images.
Many thanks to everyone who gave feedback and helped so far!
Diffstat (limited to 'source/blender/src/fsmenu.c')
-rw-r--r-- | source/blender/src/fsmenu.c | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/source/blender/src/fsmenu.c b/source/blender/src/fsmenu.c new file mode 100644 index 00000000000..1d03291b135 --- /dev/null +++ b/source/blender/src/fsmenu.c @@ -0,0 +1,260 @@ +/** + * $Id: fsmenu.c 11698 2007-08-19 12:22:51Z elubie $ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include "MEM_guardedalloc.h" + +#include "BMF_Api.h" + +#include "BLI_blenlib.h" +#include "BLI_linklist.h" +#include "BLI_dynstr.h" +#include "BIF_usiblender.h" + + +#include "BIF_fsmenu.h" /* include ourselves */ + + +/* FSMENU HANDLING */ + + /* FSMenuEntry's without paths indicate seperators */ +typedef struct _FSMenuEntry FSMenuEntry; +struct _FSMenuEntry { + FSMenuEntry *next; + + char *path; + short save; +}; + +static FSMenuEntry *fsmenu= 0; + +int fsmenu_get_nentries(void) +{ + FSMenuEntry *fsme; + int count= 0; + + for (fsme= fsmenu; fsme; fsme= fsme->next) + count++; + + return count; +} +int fsmenu_is_entry_a_seperator(int idx) +{ + FSMenuEntry *fsme; + + for (fsme= fsmenu; fsme && idx; fsme= fsme->next) + idx--; + + return (fsme && !fsme->path)?1:0; +} +char *fsmenu_get_entry(int idx) +{ + FSMenuEntry *fsme; + + for (fsme= fsmenu; fsme && idx; fsme= fsme->next) + idx--; + + return fsme?fsme->path:NULL; +} +char *fsmenu_build_menu(void) +{ + DynStr *ds= BLI_dynstr_new(); + FSMenuEntry *fsme; + char *menustr; + + for (fsme= fsmenu; fsme; fsme= fsme->next) { + if (!fsme->path) { + /* clean consecutive seperators and ignore trailing ones */ + if (fsme->next) { + if (fsme->next->path) { + BLI_dynstr_append(ds, "%l|"); + } else { + FSMenuEntry *next= fsme->next; + fsme->next= next->next; + MEM_freeN(next); + } + } + } else { + if (fsme->save) { + BLI_dynstr_append(ds, "o "); + } else { + BLI_dynstr_append(ds, " "); + } + BLI_dynstr_append(ds, fsme->path); + if (fsme->next) BLI_dynstr_append(ds, "|"); + } + } + + menustr= BLI_dynstr_get_cstring(ds); + BLI_dynstr_free(ds); + return menustr; +} +static FSMenuEntry *fsmenu_get_last_separator(void) +{ + FSMenuEntry *fsme, *lsep=NULL; + + for (fsme= fsmenu; fsme; fsme= fsme->next) + if (!fsme->path) + lsep= fsme; + + return lsep; +} + +static FSMenuEntry *fsmenu_get_first_separator(void) +{ + FSMenuEntry *fsme, *lsep=NULL; + + for (fsme= fsmenu; fsme; fsme= fsme->next) + if (!fsme->path) { + lsep= fsme; + break; + } + + return lsep; +} + +void fsmenu_insert_entry(char *path, int sorted, short save) +{ + FSMenuEntry *prev; + FSMenuEntry *fsme; + + if (save) { + prev = fsmenu_get_first_separator(); + } else { + prev = fsmenu_get_last_separator(); + } + fsme= prev?prev->next:fsmenu; + + for (; fsme; prev= fsme, fsme= fsme->next) { + if (fsme->path) { + if (BLI_streq(path, fsme->path)) { + return; + } else if (sorted && strcmp(path, fsme->path)<0) { + break; + } + } else { + // if we're bookmarking this, file should come + // before the last separator, only automatically added + // current dir go after the last sep. + if (save) { + break; + } + } + } + + fsme= MEM_mallocN(sizeof(*fsme), "fsme"); + fsme->path= BLI_strdup(path); + fsme->save = save; + + if (prev) { + fsme->next= prev->next; + prev->next= fsme; + } else { + fsme->next= fsmenu; + fsmenu= fsme; + } +} +void fsmenu_append_separator(void) +{ + if (fsmenu) { + FSMenuEntry *fsme= fsmenu; + + while (fsme->next) fsme= fsme->next; + + fsme->next= MEM_mallocN(sizeof(*fsme), "fsme"); + fsme->next->next= NULL; + fsme->next->path= NULL; + } +} +void fsmenu_remove_entry(int idx) +{ + FSMenuEntry *prev= NULL, *fsme= fsmenu; + + for (fsme= fsmenu; fsme && idx; prev= fsme, fsme= fsme->next) + idx--; + + if (fsme) { + if (prev) { + prev->next= fsme->next; + } else { + fsmenu= fsme->next; + if (fsme->save) { + if (prev) { + prev->next= fsme->next; + } else { + fsmenu= fsme->next; + } + // you should only be able to remove entries that were + // not added by default + if (fsme->path) { + MEM_freeN(fsme->path); + } + MEM_freeN(fsme); + } + } + } +} + +void fsmenu_write_file(const char *filename) +{ + FSMenuEntry *fsme= fsmenu; + + FILE *fp = fopen(filename, "w"); + if (!fp) return; + + for (fsme= fsmenu; fsme; fsme= fsme->next) { + if (fsme->path && fsme->save) { + fprintf(fp, "%s\n", fsme->path); + } + } + fclose(fp); +} + +void fsmenu_free(void) +{ + FSMenuEntry *fsme= fsmenu; + + while (fsme) { + FSMenuEntry *n= fsme->next; + + if (fsme->path) MEM_freeN(fsme->path); + MEM_freeN(fsme); + + fsme= n; + } +} + + + |