2.5 file browser
* operator for create new directory activated (IKEY) * operator for rename (works on files and directories so far) (CTRL+LMB) Note: fail to rename is rather quiet, no message popup, just doesn't rename if it can't. So far checked that (On Windows Vista) rename fails on system directories, which I think acceptable. Note: I removed the code that (silently) deletes file if I rename file to an existing one. Considered harmful :)
This commit is contained in:
parent
4741137fc9
commit
cbb9dfaab8
|
@ -48,6 +48,7 @@ class FILEBROWSER_MT_directory(bpy.types.Menu):
|
|||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.itemO("file.directory_new", text="New Directory", icon='ICON_NEWFOLDER')
|
||||
layout.itemO("file.refresh", text="Refresh", icon='ICON_FILE_REFRESH')
|
||||
layout.itemO("file.parent", text="Parent", icon='ICON_FILE_PARENT')
|
||||
|
||||
|
|
|
@ -77,7 +77,6 @@ struct direntry{
|
|||
#define SELECT 1
|
||||
#define HIDDEN 1
|
||||
#define FIRST 1
|
||||
#define ACTIVE 2
|
||||
#define DESELECT 0
|
||||
#define NOT_YET 0
|
||||
#define VISIBLE 0
|
||||
|
|
|
@ -311,10 +311,10 @@ void BLI_recurdir_fileops(char *dirname) {
|
|||
int BLI_rename(char *from, char *to) {
|
||||
if (!BLI_exists(from)) return 0;
|
||||
|
||||
/* make sure the filenames are different (case insensitive) before removing */
|
||||
if (BLI_exists(to) && BLI_strcasecmp(from, to))
|
||||
if(BLI_delete(to, 0, 0)) return 1;
|
||||
|
||||
/* refuse to rename if file already exists */
|
||||
if (BLI_exists(to))
|
||||
return 1;
|
||||
|
||||
return rename(from, to);
|
||||
}
|
||||
|
||||
|
@ -391,8 +391,9 @@ void BLI_recurdir_fileops(char *dirname) {
|
|||
int BLI_rename(char *from, char *to) {
|
||||
if (!BLI_exists(from)) return 0;
|
||||
|
||||
if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1;
|
||||
|
||||
/* refuse to rename if file already exists */
|
||||
if (BLI_exists(to)) return 1;
|
||||
|
||||
return rename(from, to);
|
||||
}
|
||||
|
||||
|
|
|
@ -495,6 +495,25 @@ void file_draw_previews(const bContext *C, ARegion *ar)
|
|||
uiSetRoundBox(0);
|
||||
}
|
||||
|
||||
static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
|
||||
{
|
||||
char newname[FILE_MAX+12];
|
||||
char orgname[FILE_MAX+12];
|
||||
char filename[FILE_MAX+12];
|
||||
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||
struct direntry *file = (struct direntry *)arg1;
|
||||
|
||||
BLI_make_file_string(G.sce, orgname, sfile->params->dir, oldname);
|
||||
BLI_strncpy(filename, file->relname, sizeof(filename));
|
||||
BLI_make_file_string(G.sce, newname, sfile->params->dir, filename);
|
||||
|
||||
if( strcmp(orgname, newname) != 0 ) {
|
||||
BLI_rename(orgname, newname);
|
||||
|
||||
/* to refresh the file list, does sorting again */
|
||||
filelist_free(sfile->files);
|
||||
}
|
||||
}
|
||||
|
||||
void file_draw_list(const bContext *C, ARegion *ar)
|
||||
{
|
||||
|
@ -554,15 +573,17 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||
sy = v2d->tot.ymax - sy;
|
||||
|
||||
file = filelist_file(files, i);
|
||||
|
||||
if (params->active_file == i) {
|
||||
if (file->flags & ACTIVE) colorid= TH_HILITE;
|
||||
else colorid = TH_BACK;
|
||||
draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,20);
|
||||
} else if (file->flags & ACTIVE) {
|
||||
colorid = TH_HILITE;
|
||||
draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,0);
|
||||
}
|
||||
|
||||
if (!(file->flags & EDITING)) {
|
||||
if (params->active_file == i) {
|
||||
if (file->flags & ACTIVE) colorid= TH_HILITE;
|
||||
else colorid = TH_BACK;
|
||||
draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,20);
|
||||
} else if (file->flags & ACTIVE) {
|
||||
colorid = TH_HILITE;
|
||||
draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,0);
|
||||
}
|
||||
}
|
||||
|
||||
spos = sx;
|
||||
file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
|
||||
|
@ -571,7 +592,19 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||
UI_ThemeColor4(TH_TEXT);
|
||||
|
||||
sw = file_string_width(file->relname);
|
||||
file_draw_string(spos, sy, file->relname, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||
if (file->flags & EDITING) {
|
||||
uiBlock *block = uiBeginBlock(C, ar, "FileName", UI_EMBOSS);
|
||||
uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3,
|
||||
layout->column_widths[COLUMN_NAME], layout->tile_h, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
|
||||
uiButSetRenameFunc(but, renamebutton_cb, file);
|
||||
if ( 0 == uiButActiveOnly(C, block, but)) {
|
||||
file->flags &= ~EDITING;
|
||||
}
|
||||
uiEndBlock(C, block);
|
||||
uiDrawBlock(C, block);
|
||||
} else {
|
||||
file_draw_string(spos, sy, file->relname, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||
}
|
||||
spos += layout->column_widths[COLUMN_NAME] + 12;
|
||||
if (params->display == FILE_SHOWSHORT) {
|
||||
if (!(file->type & S_IFDIR)) {
|
||||
|
|
|
@ -70,6 +70,7 @@ 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);
|
||||
void FILE_OT_rename(struct wmOperatorType *ot);
|
||||
|
||||
int file_exec(bContext *C, struct wmOperator *unused);
|
||||
int file_cancel_exec(bContext *C, struct wmOperator *unused);
|
||||
|
|
|
@ -870,6 +870,37 @@ void FILE_OT_filenum(struct wmOperatorType *ot)
|
|||
RNA_def_int(ot->srna, "increment", 1, 0, 100, "Increment", "", 0,100);
|
||||
}
|
||||
|
||||
int file_rename_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
ScrArea *sa= CTX_wm_area(C);
|
||||
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||
|
||||
if(sfile->params) {
|
||||
int idx = sfile->params->active_file;
|
||||
int numfiles = filelist_numfiles(sfile->files);
|
||||
if ( (0<=idx) && (idx<numfiles) ) {
|
||||
struct direntry *file= filelist_file(sfile->files, idx);
|
||||
file->flags |= EDITING;
|
||||
}
|
||||
ED_area_tag_redraw(sa);
|
||||
}
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
|
||||
}
|
||||
|
||||
void FILE_OT_rename(struct wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Rename File or Directory";
|
||||
ot->idname= "FILE_OT_rename";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= file_rename_exec;
|
||||
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
||||
|
||||
}
|
||||
|
||||
int file_delete_poll(bContext *C)
|
||||
{
|
||||
int poll = ED_operator_file_active(C);
|
||||
|
|
|
@ -113,7 +113,6 @@ typedef struct FileList
|
|||
int numfiles;
|
||||
int numfiltered;
|
||||
char dir[FILE_MAX];
|
||||
int has_func;
|
||||
short prv_w;
|
||||
short prv_h;
|
||||
short hide_dot;
|
||||
|
@ -698,7 +697,6 @@ struct direntry * filelist_file(struct FileList* filelist, int index)
|
|||
return &filelist->filelist[fidx];
|
||||
}
|
||||
|
||||
|
||||
int filelist_find(struct FileList* filelist, char *file)
|
||||
{
|
||||
int index = -1;
|
||||
|
@ -922,9 +920,5 @@ void filelist_sort(struct FileList* filelist, short sort)
|
|||
qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_extension);
|
||||
}
|
||||
|
||||
file= filelist->filelist;
|
||||
for(num=0; num<filelist->numfiles; num++, file++) {
|
||||
file->flags &= ~HILITE;
|
||||
}
|
||||
filelist_filter(filelist);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ void filelist_sort(struct FileList* filelist, short sort);
|
|||
int filelist_numfiles(struct FileList* filelist);
|
||||
const char * filelist_dir(struct FileList* filelist);
|
||||
void filelist_setdir(struct FileList* filelist, const char *dir);
|
||||
struct direntry * filelist_file(struct FileList* filelist, int index);
|
||||
void filelist_end_edit(struct FileList* filelist, int index);
|
||||
void filelist_hidedot(struct FileList* filelist, short hide);
|
||||
void filelist_setfilter(struct FileList* filelist, unsigned int filter);
|
||||
void filelist_filter(struct FileList* filelist);
|
||||
|
|
|
@ -272,7 +272,7 @@ static void file_main_area_draw(const bContext *C, ARegion *ar)
|
|||
float col[3];
|
||||
|
||||
/* Needed, because filelist is not initialized on loading */
|
||||
if (!sfile->files)
|
||||
if (!sfile->files || filelist_empty(sfile->files))
|
||||
file_refresh(C, NULL);
|
||||
|
||||
layout = ED_fileselect_get_layout(sfile, ar);
|
||||
|
@ -346,6 +346,7 @@ void file_operatortypes(void)
|
|||
WM_operatortype_append(FILE_OT_filenum);
|
||||
WM_operatortype_append(FILE_OT_directory_new);
|
||||
WM_operatortype_append(FILE_OT_delete);
|
||||
WM_operatortype_append(FILE_OT_rename);
|
||||
}
|
||||
|
||||
/* NOTE: do not add .blend file reading on this level */
|
||||
|
@ -360,7 +361,7 @@ 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_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 */
|
||||
|
@ -368,6 +369,7 @@ void file_keymap(struct wmWindowManager *wm)
|
|||
WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_PRESS, 0, 0);
|
||||
WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
|
||||
WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0);
|
||||
WM_keymap_add_item(keymap, "FILE_OT_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
|
||||
WM_keymap_add_item(keymap, "FILE_OT_highlight", MOUSEMOVE, KM_ANY, 0, 0);
|
||||
WM_keymap_add_item(keymap, "FILE_OT_loadimages", TIMER1, KM_ANY, KM_ANY, 0);
|
||||
kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0);
|
||||
|
|
|
@ -642,7 +642,8 @@ enum FileSortTypeE {
|
|||
#define FILE_BOOKMARKS 512
|
||||
|
||||
/* files in filesel list: 2=ACTIVE */
|
||||
#define HILITE 1
|
||||
#define EDITING 1
|
||||
#define ACTIVE 2
|
||||
#define BLENDERFILE 4
|
||||
#define PSXFILE 8
|
||||
#define IMAGEFILE 16
|
||||
|
|
Loading…
Reference in New Issue