2.5 file browser

* directory button enabled again, c code for now, can later become nicer operator
* filename button enabled (pattern match for selection)
* RNA completed (title, file and directory)
* some unused code removal.
This commit is contained in:
2009-07-10 17:05:04 +00:00
parent 8f60227750
commit 66ca86b40b
9 changed files with 206 additions and 208 deletions

View File

@@ -746,10 +746,6 @@
RelativePath="..\..\..\source\blender\editors\space_file\file_draw.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\editors\space_file\file_header.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\editors\space_file\file_intern.h"
>

View File

@@ -3434,7 +3434,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
data= MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData");
data->window= CTX_wm_window(C);
data->region= ar;
if( ELEM(but->type, BUT_CURVE, SEARCH_MENU) ); // XXX curve is temp
if( ELEM3(but->type, BUT_CURVE, SEARCH_MENU, TEX) ); // XXX curve is temp
else data->interactive= 1;
data->state = BUTTON_STATE_INIT;

View File

@@ -90,6 +90,8 @@ enum {
B_FS_EXEC,
B_FS_CANCEL,
B_FS_PARENT,
B_FS_DIRNAME,
B_FS_FILENAME
} eFile_ButEvents;
@@ -105,6 +107,12 @@ static void do_file_buttons(bContext *C, void *arg, int event)
case B_FS_PARENT:
file_parent_exec(C, NULL); /* file_ops.c */
break;
case B_FS_FILENAME:
file_filename_exec(C, NULL);
break;
case B_FS_DIRNAME:
file_directory_exec(C, NULL);
break;
}
}
@@ -130,10 +138,6 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
block = uiBeginBlock(C, ar, name, UI_EMBOSS);
uiBlockSetHandleFunc(block, do_file_buttons, NULL);
/* XXXX
uiSetButLock( filelist_gettype(simasel->files)==FILE_MAIN && simasel->returnfunc, NULL);
*/
/* space available for load/save buttons? */
slen = UI_GetStringWidth(sfile->params->title);
loadbutton= slen > 60 ? slen + 20 : MAX2(80, 20+UI_GetStringWidth(params->title));
@@ -146,8 +150,8 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
loadbutton= 0;
}
uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"", xmin+2, filebuty1, xmax-xmin-loadbutton-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"", xmin+2, filebuty2, xmax-xmin-loadbutton-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
uiDefBut(block, TEX, B_FS_FILENAME ,"", xmin+2, filebuty1, xmax-xmin-loadbutton-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
uiDefBut(block, TEX, B_FS_DIRNAME,"", xmin+2, filebuty2, xmax-xmin-loadbutton-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
if(loadbutton) {
uiDefBut(block, BUT, B_FS_EXEC, params->title, xmax-loadbutton, filebuty2, loadbutton, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
@@ -160,13 +164,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
static void draw_tile(short sx, short sy, short width, short height, int colorid, int shade)
{
/* TODO: BIF_ThemeColor seems to need this to show the color, not sure why? - elubie */
//glEnable(GL_BLEND);
//glColor4ub(0, 0, 0, 100);
//glDisable(GL_BLEND);
/* I think it was a missing glDisable() - ton */
{
UI_ThemeColorShade(colorid, shade);
uiSetRoundBox(15);
uiRoundBox(sx, sy - height, sx + width, sy, 6);

View File

@@ -1,187 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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) 2008 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <string.h>
#include <stdio.h>
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BKE_context.h"
#include "BKE_screen.h"
#include "BKE_global.h"
#include "ED_screen.h"
#include "ED_types.h"
#include "ED_util.h"
#include "ED_fileselect.h"
#include "WM_api.h"
#include "WM_types.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "file_intern.h"
#include "filelist.h"
#define B_SORTIMASELLIST 1
#define B_RELOADIMASELDIR 2
#define B_FILTERIMASELDIR 3
#define B_HIDEDOTFILES 4
/* ************************ header area region *********************** */
static void do_file_header_buttons(bContext *C, void *arg, int event)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
switch(event) {
case B_SORTIMASELLIST:
filelist_sort(sfile->files, sfile->params->sort);
WM_event_add_notifier(C, NC_WINDOW, NULL);
break;
case B_RELOADIMASELDIR:
WM_event_add_notifier(C, NC_WINDOW, NULL);
break;
case B_FILTERIMASELDIR:
if(sfile->params) {
if (sfile->params->flag & FILE_FILTER) {
filelist_setfilter(sfile->files,sfile->params->filter);
filelist_filter(sfile->files);
} else {
filelist_setfilter(sfile->files,0);
filelist_filter(sfile->files);
}
}
WM_event_add_notifier(C, NC_WINDOW, NULL);
break;
case B_HIDEDOTFILES:
if(sfile->params) {
filelist_free(sfile->files);
filelist_hidedot(sfile->files, sfile->params->flag & FILE_HIDE_DOT);
WM_event_add_notifier(C, NC_WINDOW, NULL);
}
break;
}
}
void file_header_buttons(const bContext *C, ARegion *ar)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
FileSelectParams* params = ED_fileselect_get_params(sfile);
uiBlock *block;
int xco, yco= 3;
int xcotitle;
block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
uiBlockSetHandleFunc(block, do_file_header_buttons, NULL);
xco= ED_area_header_standardbuttons(C, block, yco);
/*
if((sa->flag & HEADER_NO_PULLDOWN)==0) {
int xmax;
xmax= GetButStringLength("View");
uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C),
"View", xco, yco-2, xmax-3, 24, "");
xco+=XIC+xmax;
}
*/
xco += 5;
uiBlockBeginAlign(block);
uiDefIconButO(block, BUT, "FILE_OT_parent", WM_OP_INVOKE_DEFAULT, ICON_FILE_PARENT, xco+=XIC, yco, 20, 20, "Navigate to Parent Folder");
uiDefIconButO(block, BUT, "FILE_OT_refresh", WM_OP_INVOKE_DEFAULT, ICON_FILE_REFRESH, xco+=XIC, yco, 20, 20, "Refresh List of Files");
uiBlockEndAlign(block);
xco += 5;
uiBlockBeginAlign(block);
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_SHORTDISPLAY, xco+=XIC, yco, XIC,YIC, &params->display, 1.0, FILE_SHORTDISPLAY, 0, 0, "Displays short file description");
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_LONGDISPLAY, xco+=XIC, yco, XIC,YIC, &params->display, 1.0, FILE_LONGDISPLAY, 0, 0, "Displays long file description");
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_IMGDISPLAY, xco+=XIC, yco, XIC,YIC, &params->display, 1.0, FILE_IMGDISPLAY, 0, 0, "Displays files as thumbnails");
uiBlockEndAlign(block);
xco+=XIC;
uiBlockBeginAlign(block);
uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTALPHA, xco+=XIC, yco, XIC,YIC, &params->sort, 1.0, 0.0, 0, 0, "Sorts files alphabetically");
uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTBYEXT, xco+=XIC, yco, XIC,YIC, &params->sort, 1.0, 3.0, 0, 0, "Sorts files by extension");
uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTTIME, xco+=XIC, yco, XIC,YIC, &params->sort, 1.0, 1.0, 0, 0, "Sorts files by time");
uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTSIZE, xco+=XIC, yco, XIC,YIC, &params->sort, 1.0, 2.0, 0, 0, "Sorts files by size");
uiBlockEndAlign(block);
xco+=XIC;
uiDefIconButBitS(block, TOG, FILE_HIDE_DOT, B_HIDEDOTFILES, ICON_GHOST,xco+=XIC,yco,XIC,YIC, &params->flag, 0, 0, 0, 0, "Hide dot files");
xco+=XIC;
uiDefIconButBitS(block, TOG, FILE_FILTER, B_FILTERIMASELDIR, ICON_FILTER,xco+=XIC,yco,XIC,YIC, &params->flag, 0, 0, 0, 0, "Filter files");
if (params->flag & FILE_FILTER) {
xco+=4;
uiBlockBeginAlign(block);
uiDefIconButBitS(block, TOG, IMAGEFILE, B_FILTERIMASELDIR, ICON_FILE_IMAGE,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show images");
uiDefIconButBitS(block, TOG, BLENDERFILE, B_FILTERIMASELDIR, ICON_FILE_BLEND,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show .blend files");
uiDefIconButBitS(block, TOG, MOVIEFILE, B_FILTERIMASELDIR, ICON_FILE_MOVIE,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show movies");
uiDefIconButBitS(block, TOG, PYSCRIPTFILE, B_FILTERIMASELDIR, ICON_FILE_SCRIPT,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show python scripts");
uiDefIconButBitS(block, TOG, FTFONTFILE, B_FILTERIMASELDIR, ICON_FILE_FONT,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show fonts");
uiDefIconButBitS(block, TOG, SOUNDFILE, B_FILTERIMASELDIR, ICON_FILE_SOUND,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show sound files");
uiDefIconButBitS(block, TOG, TEXTFILE, B_FILTERIMASELDIR, ICON_FILE_BLANK,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show text files");
uiDefIconButBitS(block, TOG, FOLDERFILE, B_FILTERIMASELDIR, ICON_FILE_FOLDER,xco+=XIC,yco,XIC,YIC, &params->filter, 0, 0, 0, 0, "Show folders");
uiBlockEndAlign(block);
xco+=XIC;
}
xcotitle= xco;
xco+= UI_GetStringWidth(params->title);
uiBlockSetEmboss(block, UI_EMBOSS);
/* always as last */
UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
uiEndBlock(C, block);
uiDrawBlock(C, block);
}

View File

@@ -34,9 +34,6 @@ struct ARegion;
struct ARegionType;
struct SpaceFile;
/* file_header.c */
void file_header_buttons(const bContext *C, ARegion *ar);
/* file_ops.c */
struct ARegion *file_buttons_region(struct ScrArea *sa);
@@ -65,23 +62,33 @@ void FILE_OT_loadimages(struct wmOperatorType *ot);
void FILE_OT_exec(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);
void FILE_OT_filename(struct wmOperatorType *ot);
void FILE_OT_previous(struct wmOperatorType *ot);
void FILE_OT_next(struct wmOperatorType *ot);
void FILE_OT_refresh(struct wmOperatorType *ot);
void FILE_OT_bookmark_toggle(struct wmOperatorType *ot);
void FILE_OT_filenum(struct wmOperatorType *ot);
void FILE_OT_delete(struct wmOperatorType *ot);
int file_exec(bContext *C, struct wmOperator *unused);
int file_cancel_exec(bContext *C, struct wmOperator *unused);
int file_parent_exec(bContext *C, struct wmOperator *unused);
int file_previous_exec(bContext *C, struct wmOperator *unused);
int file_next_exec(bContext *C, struct wmOperator *unused);
int file_filename_exec(bContext *C, struct wmOperator *unused);
int file_directory_exec(bContext *C, struct wmOperator *unused);
int file_directory_new_exec(bContext *C,struct wmOperator *unused);
int file_delete_exec(bContext *C, struct wmOperator *unused);
int file_hilight_set(struct SpaceFile *sfile, struct ARegion *ar, int mx, int my);
/* filesel.c */
float file_string_width(const char* str);
float file_font_pointsize();
void file_change_dir(struct SpaceFile *sfile);
int file_select_match(struct SpaceFile *sfile, const char *pattern);
/* file_panels.c */
void file_panels_register(struct ARegionType *art);

View File

@@ -652,6 +652,96 @@ int file_next_exec(bContext *C, wmOperator *unused)
return OPERATOR_FINISHED;
}
int file_directory_new_exec(bContext *C, wmOperator *unused)
{
char tmpstr[FILE_MAX];
char tmpdir[FILE_MAXFILE];
int i = 1;
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
if(sfile->params) {
BLI_strncpy(tmpstr, sfile->params->dir, FILE_MAX);
BLI_join_dirfile(tmpstr, tmpstr, "New Folder");
while (BLI_exists(tmpstr)) {
BLI_snprintf(tmpdir, FILE_MAXFILE, "New Folder(%d)", i++);
BLI_strncpy(tmpstr, sfile->params->dir, FILE_MAX);
BLI_join_dirfile(tmpstr, tmpstr, tmpdir);
}
BLI_recurdir_fileops(tmpstr);
if (!BLI_exists(tmpstr)) {
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);
return OPERATOR_FINISHED;
}
void FILE_OT_directory_new(struct wmOperatorType *ot)
{
/* identifiers */
ot->name= "Create New Directory";
ot->idname= "FILE_OT_directory_new";
/* api callbacks */
ot->invoke= WM_operator_confirm;
ot->exec= file_directory_new_exec;
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
}
int file_directory_exec(bContext *C, wmOperator *unused)
{
char tmpstr[FILE_MAX];
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
if(sfile->params) {
if ( sfile->params->dir[0] == '~' ) {
if (sfile->params->dir[1] == '\0') {
BLI_strncpy(sfile->params->dir, BLI_gethome(), sizeof(sfile->params->dir) );
} else {
/* replace ~ with home */
char homestr[FILE_MAX];
char *d = &sfile->params->dir[1];
while ( (*d == '\\') || (*d == '/') )
d++;
BLI_strncpy(homestr, BLI_gethome(), FILE_MAX);
BLI_add_slash(homestr);
BLI_join_dirfile(tmpstr, homestr, d);
BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir));
}
}
file_change_dir(sfile);
}
WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
return OPERATOR_FINISHED;
}
int file_filename_exec(bContext *C, wmOperator *unused)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
if(sfile->params) {
if (file_select_match(sfile, sfile->params->file))
{
sfile->params->file[0] = '\0';
WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL);
}
}
return OPERATOR_FINISHED;
}
void FILE_OT_refresh(struct wmOperatorType *ot)
{
/* identifiers */
@@ -772,3 +862,48 @@ void FILE_OT_filenum(struct wmOperatorType *ot)
RNA_def_int(ot->srna, "increment", 1, 0, 100, "Increment", "", 0,100);
}
int file_delete_poll(bContext *C)
{
int poll = ED_operator_file_active(C);
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
struct direntry* file;
if(!sfile->params ) poll= 0;
if (sfile->params->active_file < 0) {
poll= 0;
} else {
file = filelist_file(sfile->files, sfile->params->active_file);
if (file && S_ISDIR(file->type)) poll= 0;
}
return poll;
}
int file_delete_exec(bContext *C, wmOperator *op)
{
char str[FILE_MAX];
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
struct direntry* file;
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);
return OPERATOR_FINISHED;
}
void FILE_OT_delete(struct wmOperatorType *ot)
{
/* identifiers */
ot->name= "Delete File";
ot->idname= "FILE_OT_delete";
/* api callbacks */
ot->invoke= WM_operator_confirm;
ot->exec= file_delete_exec;
ot->poll= file_delete_poll; /* <- important, handler is on window level */
}

View File

@@ -80,6 +80,17 @@
#include "file_intern.h"
#include "filelist.h"
#if defined __BeOS
static int fnmatch(const char *pattern, const char *string, int flags)
{
return 0;
}
#elif defined WIN32 && !defined _LIBC
/* use fnmatch included in blenlib */
#include "BLI_fnmatch.h"
#else
#include <fnmatch.h>
#endif
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
{
@@ -299,3 +310,22 @@ void file_change_dir(struct SpaceFile *sfile)
sfile->params->active_file = -1;
}
}
int file_select_match(struct SpaceFile *sfile, const char *pattern)
{
int match = 0;
if (strchr(pattern, '*') || strchr(pattern, '?') || strchr(pattern, '[')) {
int i;
struct direntry *file;
int n = filelist_numfiles(sfile->files);
for (i = 0; i < n; i++) {
file = filelist_file(sfile->files, i);
if (fnmatch(pattern, file->relname, 0) == 0) {
file->flags |= ACTIVE;
match = 1;
}
}
}
return match;
}

View File

@@ -321,6 +321,8 @@ void file_operatortypes(void)
WM_operatortype_append(FILE_OT_delete_bookmark);
WM_operatortype_append(FILE_OT_hidedot);
WM_operatortype_append(FILE_OT_filenum);
WM_operatortype_append(FILE_OT_directory_new);
WM_operatortype_append(FILE_OT_delete);
}
/* NOTE: do not add .blend file reading on this level */
@@ -335,6 +337,8 @@ void file_keymap(struct wmWindowManager *wm)
WM_keymap_add_item(keymap, "FILE_OT_hidedot", HKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FILE_OT_previous", BACKSPACEKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FILE_OT_next", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0);
/* WM_keymap_add_item(keymap, "FILE_OT_directory_new", IKEY, KM_PRESS, 0, 0); */ /* XXX needs button */
WM_keymap_add_item(keymap, "FILE_OT_delete", XKEY, KM_PRESS, 0, 0);
/* keys for main area */
keymap= WM_keymap_listbase(wm, "FileMain", SPACE_FILE, 0);

View File

@@ -893,6 +893,21 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
srna= RNA_def_struct(brna, "FileSelectParams", NULL);
RNA_def_struct_ui_text(srna, "File Select Parameters", "File Select Parameters.");
prop= RNA_def_property(srna, "title", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "title");
RNA_def_property_ui_text(prop, "Title", "Title for the file browser.");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop= RNA_def_property(srna, "directory", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "dir");
RNA_def_property_ui_text(prop, "Directory", "Directory displayed in the file browser.");
RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL);
prop= RNA_def_property(srna, "file", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "file");
RNA_def_property_ui_text(prop, "File Name", "Active file in the file browser.");
RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL);
prop= RNA_def_property(srna, "display", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "display");
RNA_def_property_enum_items(prop, file_display_items);