diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-11-01 20:32:37 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-11-01 21:44:03 +0300 |
commit | c2bcde5c285ec731c3f869324455d85c39ff3c75 (patch) | |
tree | f2268f76d2317aa94354edb5bae48ed47c9405d9 /source/blender/windowmanager | |
parent | 1e8a2e1a100ce7a8d2ae5fb4ecfcecd4a801c2f3 (diff) |
UI: show blocking popup when auto execution of scripts is disabled.
This is important information, and it was easily missed at the top/bottom of
the screen.
Ref T57197.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 107 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_window.h | 2 |
3 files changed, 112 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index e562053b62c..c829dd9b589 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -521,6 +521,9 @@ void wm_event_do_notifiers(bContext *C) WM_window_cursor_keymap_status_refresh(C, win); CTX_wm_window_set(C, NULL); } + + /* Autorun warning */ + wm_test_autorun_warning(C); } static int wm_event_always_pass(const wmEvent *event) diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 2283ae0118b..05f139858a5 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -2322,3 +2322,110 @@ void WM_OT_save_mainfile(wmOperatorType *ot) } /** \} */ + +/** \name Auto-execution of scripts warning popup + * + * \{ */ + +static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *UNUSED(arg)) +{ + wmWindow *win = CTX_wm_window(C); + UI_popup_block_close(C, win, arg_block); +} + +static void wm_block_autorun_warning_allow(bContext *C, void *arg_block, void *UNUSED(arg)) +{ + PointerRNA props_ptr; + wmWindow *win = CTX_wm_window(C); + + UI_popup_block_close(C, win, arg_block); + + wmOperatorType *ot = WM_operatortype_find("WM_OT_revert_mainfile", false); + + WM_operator_properties_create_ptr(&props_ptr, ot); + RNA_boolean_set(&props_ptr, "use_scripts", true); + WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr); + WM_operator_properties_free(&props_ptr); +} + +/* Build the autorun warning dialog UI */ +static uiBlock *block_create_autorun_warning(struct bContext *C, struct ARegion *ar, void *UNUSED(arg1)) +{ + uiStyle *style = UI_style_get(); + uiBlock *block = UI_block_begin(C, ar, "autorun_warning_popup", UI_EMBOSS); + + UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_LOOP | UI_BLOCK_NO_WIN_CLIP | UI_BLOCK_NUMSELECT); + UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); + UI_block_emboss_set(block, UI_EMBOSS); + + uiLayout *layout = UI_block_layout( + block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 10, 2, U.widget_unit * 24, U.widget_unit * 6, 0, style); + + /* Text and some vertical space */ + uiLayout *col = uiLayoutColumn(layout, true); + uiItemL(col, IFACE_("For security reasons, automatic execution of Python scripts in this file was disabled:"), ICON_ERROR); + uiLayout *sub = uiLayoutRow(col, true); + uiLayoutSetRedAlert(sub, true); + uiItemL(sub, G.autoexec_fail, ICON_BLANK1); + uiItemL(col, IFACE_("This may lead to unexpected behavior."), ICON_BLANK1); + + uiItemS(layout); + uiItemS(layout); + + /* Buttons */ + uiBut *but; + uiLayout *split = uiLayoutSplit(layout, 0.0f, true); + col = uiLayoutColumn(split, false); + + /* Allow reload if we have a saved file. */ + if (G.relbase_valid) { + but = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, ICON_NONE, IFACE_("Allow Executon"), 0, 0, 50, UI_UNIT_Y, + NULL, 0, 0, 0, 0, TIP_("Reload file with execution of Python scripts enabled")); + UI_but_func_set(but, wm_block_autorun_warning_allow, block, NULL); + } + else { + uiItemS(col); + } + + /* empty space between buttons */ + col = uiLayoutColumn(split, false); + uiItemS(col); + + col = uiLayoutColumn(split, 1); + but = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, ICON_NONE, IFACE_("Ignore"), 0, 0, 50, UI_UNIT_Y, + NULL, 0, 0, 0, 0, TIP_("Continue using file without Python scripts")); + UI_but_func_set(but, wm_block_autorun_warning_ignore, block, NULL); + + UI_block_bounds_set_centered(block, 10); + + return block; +} + +void wm_test_autorun_warning(bContext *C) +{ + /* Test if any auto-execution of scripts failed. */ + if ((G.f & G_SCRIPT_AUTOEXEC_FAIL) == 0) { + return; + } + + /* Only show the warning once. */ + if (G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET) { + return; + } + + G.f |= G_SCRIPT_AUTOEXEC_FAIL_QUIET; + + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = (wm->winactive) ? wm->winactive : wm->windows.first; + + if (win) { + wmWindow *prevwin = CTX_wm_window(C); + CTX_wm_window_set(C, win); + UI_popup_block_invoke(C, block_create_autorun_warning, NULL); + CTX_wm_window_set(C, prevwin); + } +} + +/** \} */ diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index 4fd5d66fb43..5988c8dab17 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -88,6 +88,8 @@ void wm_quit_with_optional_confirmation_prompt(bContext *C, wmWindow *win) ATTR int wm_window_new_exec(bContext *C, struct wmOperator *op); int wm_window_new_main_exec(bContext *C, struct wmOperator *op); +void wm_test_autorun_warning(bContext *C); + /* Initial (unmaximized) size to start with for * systems that can't find it for themselves (X11). * Clamped by real desktop limits */ |