diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-09-04 17:21:42 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-09-04 17:30:09 +0300 |
commit | 45d4c925799e94c6d442a9a9066af2d3305724e1 (patch) | |
tree | b3d5a785539527510a5a2f110e36a485213ac35b /source/blender | |
parent | 640c45dc3a50ebc4c584bb7ca48d5075e0104bb4 (diff) |
Move file execute region back to C, fixing bugs
We moved this to Python too quickly, causing the following regressions:
* No auto completion for file names
* Additional handling not applied on changes, like automatic extension
appending (see file_filename_enter_handle)
* Red highlight missing when the file name already exists
Note that earlier (before the file browser redesign), this didn't use
the panel and layout code at all. So even if it's still not in Python,
at least it's integrated into regular panel management now.
OS-specific ordering of the open and cancel button is kept.
Fixes T69457.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_panels.c | 110 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 3 |
3 files changed, 113 insertions, 3 deletions
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 61f13098783..4b86f38f8e4 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -136,7 +136,8 @@ int autocomplete_file(struct bContext *C, char *str, void *arg_v); void file_params_renamefile_activate(struct SpaceFile *sfile, struct FileSelectParams *params); /* file_panels.c */ -void file_panels_register(struct ARegionType *art); +void file_tool_props_region_panels_register(struct ARegionType *art); +void file_execute_region_panels_register(struct ARegionType *art); /* file_utils.c */ void file_tile_boundbox(const ARegion *ar, FileLayout *layout, const int file, rcti *r_bounds); diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c index b41358f575f..290b5385bf7 100644 --- a/source/blender/editors/space_file/file_panels.c +++ b/source/blender/editors/space_file/file_panels.c @@ -95,7 +95,7 @@ static void file_panel_operator(const bContext *C, Panel *pa) UI_block_func_set(uiLayoutGetBlock(pa->layout), NULL, NULL, NULL); } -void file_panels_register(ARegionType *art) +void file_tool_props_region_panels_register(ARegionType *art) { PanelType *pt; @@ -109,3 +109,111 @@ void file_panels_register(ARegionType *art) pt->draw = file_panel_operator; BLI_addtail(&art->paneltypes, pt); } + +static void file_panel_execution_cancel_button(uiBlock *block) +{ + uiDefButO(block, + UI_BTYPE_BUT, + "FILE_OT_cancel", + WM_OP_EXEC_REGION_WIN, + IFACE_("Cancel"), + 0, + 0, + UI_UNIT_X, + UI_UNIT_Y, + ""); +} + +static void file_panel_execution_buttons_draw(const bContext *C, Panel *pa) +{ + bScreen *screen = CTX_wm_screen(C); + SpaceFile *sfile = CTX_wm_space_file(C); + FileSelectParams *params = ED_fileselect_get_params(sfile); + uiBlock *block = uiLayoutGetBlock(pa->layout); + uiBut *but; + uiLayout *row; + PointerRNA params_rna_ptr; + + const bool overwrite_alert = file_draw_check_exists(sfile); + const bool windows_layout = +#ifdef _WIN32 + true; +#else + false; +#endif + + RNA_pointer_create(&screen->id, &RNA_FileSelectParams, params, ¶ms_rna_ptr); + + row = uiLayoutRow(pa->layout, false); + uiLayoutSetScaleX(row, 1.3f); + uiLayoutSetScaleY(row, 1.3f); + + /* callbacks for operator check functions */ + UI_block_func_set(block, file_draw_check_cb, NULL, NULL); + + but = uiDefButR(block, + UI_BTYPE_TEXT, + -1, + "", + 0, + 0, + UI_UNIT_X * 5, + UI_UNIT_Y, + ¶ms_rna_ptr, + "filename", + 0, + 0.0f, + (float)FILE_MAXFILE, + 0, + 0, + TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name"))); + + BLI_assert(!UI_but_flag_is_set(but, UI_BUT_UNDO)); + BLI_assert(!UI_but_is_utf8(but)); + + UI_but_func_complete_set(but, autocomplete_file, NULL); + /* silly workaround calling NFunc to ensure this does not get called + * immediate ui_apply_but_func but only after button deactivates */ + UI_but_funcN_set(but, file_filename_enter_handle, NULL, but); + + /* check if this overrides a file and if the operator option is used */ + if (overwrite_alert) { + UI_but_flag_enable(but, UI_BUT_REDALERT); + } + UI_block_func_set(block, NULL, NULL, NULL); + + { + if (windows_layout == false) { + file_panel_execution_cancel_button(block); + } + but = uiDefButO(block, + UI_BTYPE_BUT, + "FILE_OT_execute", + WM_OP_EXEC_REGION_WIN, + params->title, + 0, + 0, + UI_UNIT_X, + UI_UNIT_Y, + ""); + /* Just a display hint. */ + UI_but_flag_enable(but, UI_BUT_ACTIVE_DEFAULT); + if (windows_layout) { + file_panel_execution_cancel_button(block); + } + } +} + +void file_execute_region_panels_register(ARegionType *art) +{ + PanelType *pt; + + pt = MEM_callocN(sizeof(PanelType), "spacetype file execution buttons"); + strcpy(pt->idname, "FILE_PT_execution_buttons"); + strcpy(pt->label, N_("Execute Buttons")); + strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); + pt->flag = PNL_NO_HEADER; + pt->poll = file_panel_operator_poll; + pt->draw = file_panel_execution_buttons_draw; + BLI_addtail(&art->paneltypes, pt); +} diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 1befdd52d7d..7525ac5b705 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -704,6 +704,7 @@ void ED_spacetype_file(void) art->init = file_execution_region_init; art->draw = file_execution_region_draw; BLI_addhead(&st->regiontypes, art); + file_execute_region_panels_register(art); /* regions: channels (directories) */ art = MEM_callocN(sizeof(ARegionType), "spacetype file region"); @@ -726,7 +727,7 @@ void ED_spacetype_file(void) art->init = file_tools_region_init; art->draw = file_tools_region_draw; BLI_addhead(&st->regiontypes, art); - file_panels_register(art); + file_tool_props_region_panels_register(art); BKE_spacetype_register(st); } |