diff options
author | Andrea Weikert <elubie@gmx.net> | 2009-07-26 22:52:27 +0400 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2009-07-26 22:52:27 +0400 |
commit | cbb9dfaab80ed52950a4ea4c1570370eddacfa64 (patch) | |
tree | 3df161c74b8d43634bfb032f2ada65d6496b3cad /source/blender/editors | |
parent | 4741137fc9639a3902a0a7bbbebb7256841ac027 (diff) |
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 :)
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 53 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 31 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 6 |
6 files changed, 80 insertions, 19 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 780b99c3cae..f2906686db5 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -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)) { diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index dce56e05d6b..9f1e4ad0e25 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -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); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 0bc2e310810..46bfa022914 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -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); diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 6e442c654ca..60a37aac9bd 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.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); } diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index dd3c2c766c1..785e40d145c 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -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); diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 077ad65830c..cdf65fc5af2 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -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); |