Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r--source/blender/editors/space_file/file_draw.c146
-rw-r--r--source/blender/editors/space_file/file_header.c187
-rw-r--r--source/blender/editors/space_file/file_intern.h14
-rw-r--r--source/blender/editors/space_file/file_ops.c154
-rw-r--r--source/blender/editors/space_file/filesel.c56
-rw-r--r--source/blender/editors/space_file/space_file.c4
6 files changed, 323 insertions, 238 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 02ee8f508c1..f1f20a36b59 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -90,6 +90,8 @@ enum {
B_FS_EXEC,
B_FS_CANCEL,
B_FS_PARENT,
+ B_FS_DIRNAME,
+ B_FS_FILENAME
} eFile_ButEvents;
@@ -105,68 +107,130 @@ 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;
}
}
-/* note; this function uses pixelspace (0, 0, winx, winy), not view2d */
+/* Note: This function uses pixelspace (0, 0, winx, winy), not view2d.
+ * The controls are laid out as follows:
+ *
+ * -------------------------------------------
+ * | Directory input | execute |
+ * -------------------------------------------
+ * | Filename input | + | - | cancel |
+ * -------------------------------------------
+ *
+ * The input widgets will stretch to fill any excess space.
+ * When there isn't enough space for all controls to be shown, they are
+ * hidden in this order: x/-, execute/cancel, input widgets.
+ */
void file_draw_buttons(const bContext *C, ARegion *ar)
{
- SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
+ /* Button layout. */
+ const short min_x = 10;
+ const short max_x = ar->winx - 10;
+ const short line2_y = ar->winy - IMASEL_BUTTONS_HEIGHT - 12;
+ const short line1_y = line2_y + IMASEL_BUTTONS_HEIGHT/2 + 4;
+ const short input_minw = 20;
+ const short btn_h = 21;
+ const short btn_fn_w = 14;
+ const short btn_minw = 80;
+ const short btn_margin = 20;
+ const short separator = 4;
+
+ /* Additional locals. */
+ char name[20];
+ short loadbutton;
+ short fnumbuttons;
+ short available_w = max_x - min_x;
+ short line1_w = available_w;
+ short line2_w = available_w;
+
+ uiBut* but;
+ uiBlock* block;
+ SpaceFile* sfile = (SpaceFile*) CTX_wm_space_data(C);
FileSelectParams* params = ED_fileselect_get_params(sfile);
- uiBlock *block;
- int loadbutton;
- char name[20];
- float slen;
- int filebuty1, filebuty2;
-
- float xmin = 8;
- float xmax = ar->winx - 10;
-
- filebuty1= ar->winy - IMASEL_BUTTONS_HEIGHT - 12;
- filebuty2= filebuty1 + IMASEL_BUTTONS_HEIGHT/2 + 4;
-
- /* HEADER */
+
+ /* Initialize UI block. */
sprintf(name, "win %p", 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));
- if(ar->winx > loadbutton+20) {
- if(params->title[0]==0) {
- loadbutton= 0;
- }
+
+ /* Is there enough space for the execute / cancel buttons? */
+ loadbutton = UI_GetStringWidth(sfile->params->title) + btn_margin;
+ if (loadbutton < btn_minw) {
+ loadbutton = MAX2(btn_minw,
+ btn_margin + UI_GetStringWidth(params->title));
}
- else {
- loadbutton= 0;
+
+ if (available_w <= loadbutton + separator + input_minw
+ || params->title[0] == 0) {
+ loadbutton = 0;
+ } else {
+ line1_w -= (loadbutton + separator);
+ line2_w = line1_w;
}
- 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, "");
+ /* Is there enough space for file number increment/decrement buttons? */
+ fnumbuttons = 2 * btn_fn_w;
+ if (!loadbutton || line2_w <= fnumbuttons + separator + input_minw) {
+ fnumbuttons = 0;
+ } else {
+ line2_w -= (fnumbuttons + separator);
+ }
+
+ /* Text input fields for directory and file. */
+ if (available_w > 0) {
+ but = uiDefBut(block, TEX, B_FS_DIRNAME, "",
+ min_x, line1_y, line1_w, btn_h,
+ params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0,
+ "File path.");
+ uiButSetCompleteFunc(but, autocomplete_directory, NULL);
+ uiDefBut(block, TEX, B_FS_FILENAME, "",
+ min_x, line2_y, line2_w, btn_h,
+ params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0,
+ "File name.");
+ }
+
+ /* Filename number increment / decrement buttons. */
+ if (fnumbuttons) {
+ uiBlockBeginAlign(block);
+ but = uiDefButO(block, BUT, "FILE_OT_filenum", 0, "-",
+ min_x + line2_w + separator, line2_y,
+ btn_fn_w, btn_h,
+ "Decrement the filename number.");
+ RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", -1);
+ but = uiDefButO(block, BUT, "FILE_OT_filenum", 0, "+",
+ min_x + line2_w + separator + btn_fn_w, line2_y,
+ btn_fn_w, btn_h,
+ "Increment the filename number.");
+ RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", 1);
+ uiBlockEndAlign(block);
+ }
+
+ /* Execute / cancel buttons. */
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, "");
- uiDefBut(block, BUT, B_FS_CANCEL, "Cancel", xmax-loadbutton, filebuty1, loadbutton, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
+ uiDefBut(block, BUT, B_FS_EXEC, params->title,
+ max_x - loadbutton, line1_y, loadbutton, btn_h,
+ params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, params->title);
+ uiDefBut(block, BUT, B_FS_CANCEL, "Cancel",
+ max_x - loadbutton, line2_y, loadbutton, btn_h,
+ params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "Cancel.");
}
-
+
uiEndBlock(C, block);
uiDrawBlock(C, block);
}
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);
diff --git a/source/blender/editors/space_file/file_header.c b/source/blender/editors/space_file/file_header.c
deleted file mode 100644
index 4799003d6c7..00000000000
--- a/source/blender/editors/space_file/file_header.c
+++ /dev/null
@@ -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);
-}
-
-
-
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 2f3fae47abb..dce56e05d6b 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -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,34 @@ 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);
+void autocomplete_directory(struct bContext *C, char *str, void *arg_v);
/* file_panels.c */
void file_panels_register(struct ARegionType *art);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index c4435e85749..8f1d2598c61 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -142,10 +142,10 @@ static void file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short v
{
// XXX error("Path too long, cannot enter this directory");
} else {
+ BLI_cleanup_dir(G.sce, params->dir);
strcat(params->dir, file->relname);
- strcat(params->dir,"/");
+ BLI_add_slash(params->dir);
params->file[0] = '\0';
- BLI_cleanup_dir(G.sce, params->dir);
file_change_dir(sfile);
}
}
@@ -557,11 +557,13 @@ int file_parent_exec(bContext *C, wmOperator *unused)
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
if(sfile->params) {
- BLI_parent_dir(sfile->params->dir);
- file_change_dir(sfile);
+ if (BLI_has_parent(sfile->params->dir)) {
+ BLI_parent_dir(sfile->params->dir);
+ file_change_dir(sfile);
+ WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
+ }
}
- WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
-
+
return OPERATOR_FINISHED;
}
@@ -652,6 +654,101 @@ 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));
+ }
+ }
+#ifdef WIN32
+ if (sfile->params->dir[0] == '\0')
+ get_default_root(sfile->params->dir);
+#endif
+ BLI_add_slash(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 +869,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 */
+}
+
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 476145d11a2..d34eb29a78d 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -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)
{
@@ -290,7 +301,7 @@ FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar
void file_change_dir(struct SpaceFile *sfile)
{
- if (sfile->params) {
+ if (sfile->params && BLI_exists(sfile->params->dir)) {
filelist_setdir(sfile->files, sfile->params->dir);
if(folderlist_clear_next(sfile))
@@ -302,3 +313,46 @@ 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;
+}
+
+
+void autocomplete_directory(struct bContext *C, char *str, void *arg_v)
+{
+ char tmp[FILE_MAX];
+ SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
+
+ /* search if str matches the beginning of name */
+ if(str[0] && sfile->files) {
+ AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX);
+ int nentries = filelist_numfiles(sfile->files);
+ int i;
+
+ for(i= 0; i<nentries; ++i) {
+ struct direntry* file = filelist_file(sfile->files, i);
+ char* dir = filelist_dir(sfile->files);
+ if (file && S_ISDIR(file->type)) {
+ BLI_make_file_string(G.sce, tmp, dir, file->relname);
+ autocomplete_do_name(autocpl,tmp);
+ }
+ }
+ autocomplete_end(autocpl, str);
+ }
+} \ No newline at end of file
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 3167d2809c9..5af79eb2800 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -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);