diff options
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 42 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 11 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 120 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 11 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 2 |
7 files changed, 81 insertions, 115 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 1ec2e3c804b..e31d813fc5e 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -75,25 +75,6 @@ #include "file_intern.h" // own include -/* button events */ -enum { - B_FS_DIRNAME, - B_FS_FILENAME -} /*eFile_ButEvents*/; - - -static void do_file_buttons(bContext *C, void *UNUSED(arg), int event) -{ - switch (event) { - 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. * The controls are laid out as follows: * @@ -139,7 +120,6 @@ void file_draw_buttons(const bContext *C, ARegion *ar) /* Initialize UI block. */ BLI_snprintf(uiblockstr, sizeof(uiblockstr), "win %p", (void *)ar); block = uiBeginBlock(C, ar, uiblockstr, UI_EMBOSS); - uiBlockSetHandleFunc(block, do_file_buttons, NULL); /* exception to make space for collapsed region icon */ for (artmp = CTX_wm_area(C)->regionbase.first; artmp; artmp = artmp->next) { @@ -180,21 +160,31 @@ void file_draw_buttons(const bContext *C, ARegion *ar) /* callbacks for operator check functions */ uiBlockSetFunc(block, file_draw_check_cb, NULL, NULL); - 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, 0, 0, - TIP_("File path")); + but = uiDefBut(block, TEX, -1, "", + min_x, line1_y, line1_w - chan_offs, btn_h, + params->dir, 0.0, (float)FILE_MAX, 0, 0, + TIP_("File path")); uiButSetCompleteFunc(but, autocomplete_directory, NULL); uiButSetFlag(but, UI_BUT_NO_UTF8); + uiButClearFlag(but, UI_BUT_UNDO); + uiButSetNFunc(but, file_directory_enter_handle, NULL, but); + + /* TODO, directory editing is non-functional while a library is loaded + * until this is properly supported just disable it. */ + if (sfile->files && filelist_lib(sfile->files)) + uiButSetFlag(but, UI_BUT_DISABLED); if ((params->flag & FILE_DIRSEL_ONLY) == 0) { - but = uiDefButTextO(block, TEX, "FILE_OT_filename", 0, "", + but = uiDefBut(block, TEX, -1, "", min_x, line2_y, line2_w - chan_offs, btn_h, params->file, 0.0, (float)FILE_MAXFILE, 0, 0, TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name"))); uiButSetCompleteFunc(but, autocomplete_file, NULL); uiButSetFlag(but, UI_BUT_NO_UTF8); - uiButClearFlag(but, UI_BUT_UNDO); /* operator button above does this automatic */ + uiButClearFlag(but, UI_BUT_UNDO); + /* silly workaround calling NFunc to ensure this does not get called + * immediate ui_apply_but_func but only after button deactivates */ + uiButSetNFunc(but, file_filename_enter_handle, NULL, but); /* check if this overrides a file and if the operator option is used */ if (overwrite_alert) { diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 134fe0ac6bc..841cb0d5f77 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -72,8 +72,6 @@ void FILE_OT_execute(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_directory(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); @@ -88,11 +86,12 @@ 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); +void file_directory_enter_handle(bContext *C, void *arg_unused, void *arg_but); +void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but); + int file_highlight_set(struct SpaceFile *sfile, struct ARegion *ar, int mx, int my); void file_sfile_to_operator(struct wmOperator *op, struct SpaceFile *sfile, char *filepath); @@ -106,8 +105,8 @@ float file_string_width(const char *str); float file_font_pointsize(void); void file_change_dir(bContext *C, int checkdir); int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file); -bool autocomplete_directory(struct bContext *C, char *str, void *arg_v); -bool autocomplete_file(struct bContext *C, char *str, void *arg_v); +int autocomplete_directory(struct bContext *C, char *str, void *arg_v); +int autocomplete_file(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 00b593817aa..f8f647786f9 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -47,6 +47,8 @@ #include "ED_screen.h" #include "ED_fileselect.h" +#include "UI_interface.h" + #include "MEM_guardedalloc.h" #include "RNA_access.h" @@ -1133,6 +1135,12 @@ int file_directory_new_exec(bContext *C, wmOperator *op) /* reload dir to make sure we're seeing what's in the directory */ ED_fileselect_clear(wm, sfile); + + if (RNA_boolean_get(op->ptr, "open")) { + BLI_strncpy(sfile->params->dir, path, sizeof(sfile->params->dir)); + file_change_dir(C, 1); + } + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; @@ -1155,7 +1163,8 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) prop = RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); - + prop = RNA_def_boolean(ot->srna, "open", false, "Open", "Open new directory"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } @@ -1196,36 +1205,13 @@ static void file_expand_directory(bContext *C) } } -static int file_directory_invoke(bContext *C, wmOperator *op, const 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)) +void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UNUSED(arg_but)) { SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { file_expand_directory(C); - if (!BLI_exists(sfile->params->dir)) { - BLI_dir_create_recursive(sfile->params->dir); - } - /* special case, user may have pasted a filepath into the directory */ if (BLI_is_file(sfile->params->dir)) { char path[sizeof(sfile->params->dir)]; @@ -1234,39 +1220,53 @@ int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) } BLI_cleanup_dir(G.main->name, sfile->params->dir); - file_change_dir(C, 1); - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); - } + if (BLI_exists(sfile->params->dir)) { + /* if directory exists, enter it immediately */ + file_change_dir(C, 1); - return OPERATOR_FINISHED; -} + /* don't do for now because it selects entire text instead of + * placing cursor at the end */ + /* UI_textbutton_activate_but(C, but); */ + } + else { + const char *lastdir = folderlist_peeklastdir(sfile->folders_prev); -static int file_filename_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) -{ - SpaceFile *sfile = CTX_wm_space_file(C); + /* if not, ask to create it and enter if confirmed */ + PointerRNA ptr; + WM_operator_properties_create(&ptr, "FILE_OT_directory_new"); + RNA_string_set(&ptr, "directory", sfile->params->dir); + RNA_boolean_set(&ptr, "open", true); - if (sfile->params) { - file_expand_directory(C); + if (lastdir) + BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir)); - return file_filename_exec(C, op); - } - return OPERATOR_CANCELLED; + WM_operator_name_call(C, "FILE_OT_directory_new", WM_OP_INVOKE_DEFAULT, &ptr); + WM_operator_properties_free(&ptr); + } + + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); + } } -int file_filename_exec(bContext *C, wmOperator *UNUSED(unused)) +void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg_but) { SpaceFile *sfile = CTX_wm_space_file(C); + uiBut *but = (uiBut*)arg_but; char matched_file[FILE_MAX]; char filepath[sizeof(sfile->params->dir)]; if (sfile->params) { - int matches = 0; + int matches; matched_file[0] = '\0'; filepath[0] = '\0'; - if ((matches = file_select_match(sfile, sfile->params->file, matched_file))) { + file_expand_directory(C); + + matches = file_select_match(sfile, sfile->params->file, matched_file); + + if (matches) { /* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */ sfile->params->file[0] = '\0'; /* replace the pattern (or filename that the user typed in, with the first selected file of the match */ @@ -1285,6 +1285,7 @@ int file_filename_exec(bContext *C, wmOperator *UNUSED(unused)) BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); sfile->params->file[0] = '\0'; file_change_dir(C, 1); + UI_textbutton_activate_but(C, but); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); } else if (sfile->params->type == FILE_LOADLIB) { @@ -1295,47 +1296,12 @@ int file_filename_exec(bContext *C, wmOperator *UNUSED(unused)) BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); sfile->params->file[0] = '\0'; file_change_dir(C, 0); + UI_textbutton_activate_but(C, but); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } } } } - - return OPERATOR_FINISHED; -} - -/* TODO, directory operator is non-functional while a library is loaded - * until this is properly supported just disable it. */ -static int file_directory_poll(bContext *C) -{ - /* sfile->files can be NULL on file load */ - SpaceFile *sfile = CTX_wm_space_file(C); - return ED_operator_file_active(C) && (sfile->files == NULL || filelist_lib(sfile->files) == NULL); -} - -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 = file_directory_poll; /* <- important, handler is on window level */ -} - -void FILE_OT_filename(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Enter File Name"; - ot->description = "Enter a file name"; - ot->idname = "FILE_OT_filename"; - - /* api callbacks */ - ot->invoke = file_filename_invoke; - ot->exec = file_filename_exec; } void FILE_OT_refresh(struct wmOperatorType *ot) diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index a2f81498dd3..872960432d9 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -479,6 +479,17 @@ void folderlist_pushdir(ListBase *folderlist, const char *dir) BLI_addtail(folderlist, folder); } +const char *folderlist_peeklastdir(ListBase *folderlist) +{ + struct FolderList *folder; + + if (!folderlist->last) + return NULL; + + folder = folderlist->last; + return folder->foldername; +} + int folderlist_clear_next(struct SpaceFile *sfile) { struct FolderList *folder; diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index d093d427eae..eb99b0d21ab 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -98,6 +98,7 @@ void folderlist_free(struct ListBase *folderlist); struct ListBase * folderlist_duplicate(ListBase *folderlist); void folderlist_popdir(struct ListBase *folderlist, char *dir); void folderlist_pushdir(struct ListBase *folderlist, const char *dir); +const char * folderlist_peeklastdir(struct ListBase *folderdist); int folderlist_clear_next(struct SpaceFile *sfile); void thumbnails_start(struct FileList *filelist, const struct bContext *C); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 3cda5dd5e80..ff0add36bdc 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -634,7 +634,7 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche return match; } -bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) +int autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) { SpaceFile *sfile = CTX_wm_space_file(C); int match = AUTOCOMPLETE_NO_MATCH; @@ -684,10 +684,10 @@ bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) } } - return match == AUTOCOMPLETE_FULL_MATCH; + return match; } -bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) +int autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) { SpaceFile *sfile = CTX_wm_space_file(C); int match = AUTOCOMPLETE_NO_MATCH; @@ -706,7 +706,8 @@ bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) } match = autocomplete_end(autocpl, str); } - return match == AUTOCOMPLETE_FULL_MATCH; + + return match; } void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile) diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 0bc2d073e0a..62048752fa1 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -395,8 +395,6 @@ static 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); - WM_operatortype_append(FILE_OT_filename); } /* NOTE: do not add .blend file reading on this level */ |