diff options
author | Andrea Weikert <elubie@gmx.net> | 2010-11-06 19:09:12 +0300 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2010-11-06 19:09:12 +0300 |
commit | dcda17b3b322cd9658dda2c9365eb4b5ff903f07 (patch) | |
tree | 45e5682d9c219bea6c8920fc1b09bae84c8e037a /source/blender/editors/space_file | |
parent | a1c7cccae4356e66ebd7b2b01fec6e738d007a43 (diff) |
== filebrowser ==
Bringing back missing feature: Create new directory by typing a not existing name into the directory button.
Note: Small issue still with autocomplete -> if typing the new directory directly after autocomplete, it doesn't execute the operator yet.
Also fixed some minor compile/cleanup issues with warning about signed/unsigned comparison and missing header.
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 74 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 1 |
4 files changed, 70 insertions, 8 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 65415d382ec..f461ee83242 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -177,7 +177,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar) /* callbacks for operator check functions */ uiBlockSetFunc(block, file_draw_check_cb, NULL, NULL); - but = uiDefBut(block, TEX, B_FS_DIRNAME, "", + but = uiDefButTextO(block, TEX, "FILE_OT_directory", 0, "", min_x, line1_y, line1_w-chan_offs, btn_h, params->dir, 0.0, (float)FILE_MAX-1, 0, 0, "File path."); diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 07a24454520..bd789cd573b 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -66,6 +66,7 @@ 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_directory(struct wmOperatorType *ot); void FILE_OT_previous(struct wmOperatorType *ot); void FILE_OT_next(struct wmOperatorType *ot); void FILE_OT_refresh(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 1af8e9d14be..2e8db0dc998 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -947,6 +947,8 @@ int file_directory_new_exec(bContext *C, wmOperator *op) { char name[FILE_MAXFILE]; char path[FILE_MAX]; + int generate_name= 1; + SpaceFile *sfile= CTX_wm_space_file(C); if(!sfile->params) { @@ -954,13 +956,22 @@ int file_directory_new_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* create a new, non-existing folder name */ - if (!new_folder_path(sfile->params->dir, path, name)) { - BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name."); - return OPERATOR_CANCELLED; + path[0] = '\0'; + + if(RNA_struct_find_property(op->ptr, "directory")) { + RNA_string_get(op->ptr, "directory", path); + if (path[0] != '\0') generate_name= 0; } - - /* rename the file */ + + if (generate_name) { + /* create a new, non-existing folder name */ + if (!new_folder_path(sfile->params->dir, path, name)) { + BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name."); + return OPERATOR_CANCELLED; + } + } + + /* create the file */ BLI_recurdir_fileops(path); if (!BLI_exists(path)) { @@ -994,9 +1005,13 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) ot->invoke= WM_operator_confirm; ot->exec= file_directory_new_exec; ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ + + RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory"); + } -int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) + +static void file_expand_directory(bContext *C) { SpaceFile *sfile= CTX_wm_space_file(C); @@ -1011,6 +1026,39 @@ int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) if (sfile->params->dir[0] == '\0') get_default_root(sfile->params->dir); #endif + } +} + +int file_directory_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +{ + SpaceFile *sfile= CTX_wm_space_file(C); + + if(sfile->params) { + file_expand_directory(C); + + if (!BLI_exists(sfile->params->dir)) { + return WM_operator_confirm_message(C, op, "Create new directory?"); + } + + return file_directory_exec(C, op); + } + + return OPERATOR_CANCELLED; +} + + + +int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) +{ + SpaceFile *sfile= CTX_wm_space_file(C); + + if(sfile->params) { + file_expand_directory(C); + + if (!BLI_exists(sfile->params->dir)) { + BLI_recurdir_fileops(sfile->params->dir); + } + BLI_cleanup_dir(G.main->name, sfile->params->dir); BLI_add_slash(sfile->params->dir); file_change_dir(C, 1); @@ -1037,6 +1085,18 @@ int file_filename_exec(bContext *C, wmOperator *UNUSED(unused)) return OPERATOR_FINISHED; } +void FILE_OT_directory(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Enter Directory Name"; + ot->description= "Enter a directory name"; + ot->idname= "FILE_OT_directory"; + + /* api callbacks */ + ot->invoke= file_directory_invoke; + ot->exec= file_directory_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ +} void FILE_OT_refresh(struct wmOperatorType *ot) { diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 92244165dc1..b46704c8a6b 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -377,6 +377,7 @@ void file_operatortypes(void) WM_operatortype_append(FILE_OT_delete); WM_operatortype_append(FILE_OT_rename); WM_operatortype_append(FILE_OT_smoothscroll); + WM_operatortype_append(FILE_OT_directory); } /* NOTE: do not add .blend file reading on this level */ |