Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Show First 20 Lines • Show All 2,715 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *UNUSED(arg)) | static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *UNUSED(arg)) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| UI_popup_block_close(C, win, arg_block); | UI_popup_block_close(C, win, arg_block); | ||||
| } | } | ||||
| static void wm_block_autorun_warning_allow(bContext *C, void *arg_block, void *UNUSED(arg)) | static void wm_block_autorun_warning_reload_with_scripts(bContext *C, | ||||
| void *arg_block, | |||||
| void *UNUSED(arg)) | |||||
| { | { | ||||
| PointerRNA props_ptr; | |||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| UI_popup_block_close(C, win, arg_block); | UI_popup_block_close(C, win, arg_block); | ||||
| /* Save user preferences for permanent execution. */ | /* Save user preferences for permanent execution. */ | ||||
| if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { | if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { | ||||
| WM_operator_name_call(C, "WM_OT_save_userpref", WM_OP_EXEC_DEFAULT, NULL); | WM_operator_name_call(C, "WM_OT_save_userpref", WM_OP_EXEC_DEFAULT, NULL); | ||||
| } | } | ||||
| /* Load file again with scripts enabled. */ | /* Load file again with scripts enabled. | ||||
| * The reload is necessary to allow scripts to run when the files loads. */ | |||||
| wmOperatorType *ot = WM_operatortype_find("WM_OT_revert_mainfile", false); | wmOperatorType *ot = WM_operatortype_find("WM_OT_revert_mainfile", false); | ||||
| PointerRNA props_ptr; | |||||
| WM_operator_properties_create_ptr(&props_ptr, ot); | WM_operator_properties_create_ptr(&props_ptr, ot); | ||||
| RNA_boolean_set(&props_ptr, "use_scripts", true); | RNA_boolean_set(&props_ptr, "use_scripts", true); | ||||
| WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr); | WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr); | ||||
| WM_operator_properties_free(&props_ptr); | WM_operator_properties_free(&props_ptr); | ||||
| } | } | ||||
| static void wm_block_autorun_warning_enable_scripts(bContext *C, | |||||
| void *arg_block, | |||||
| void *UNUSED(arg)) | |||||
| { | |||||
| wmWindow *win = CTX_wm_window(C); | |||||
| Main *bmain = CTX_data_main(C); | |||||
| UI_popup_block_close(C, win, arg_block); | |||||
| /* Save user preferences for permanent execution. */ | |||||
| if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { | |||||
| WM_operator_name_call(C, "WM_OT_save_userpref", WM_OP_EXEC_DEFAULT, NULL); | |||||
| } | |||||
| /* Force a full refresh, but without reloading the file. */ | |||||
| LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | |||||
| BKE_scene_free_depsgraph_hash(scene); | |||||
| } | |||||
| } | |||||
| /* Build the autorun warning dialog UI */ | /* Build the autorun warning dialog UI */ | ||||
| static uiBlock *block_create_autorun_warning(struct bContext *C, | static uiBlock *block_create_autorun_warning(struct bContext *C, | ||||
| struct ARegion *ar, | struct ARegion *ar, | ||||
| void *UNUSED(arg1)) | void *UNUSED(arg1)) | ||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| uiStyle *style = UI_style_get(); | uiStyle *style = UI_style_get(); | ||||
| uiBlock *block = UI_block_begin(C, ar, "autorun_warning_popup", UI_EMBOSS); | uiBlock *block = UI_block_begin(C, ar, "autorun_warning_popup", UI_EMBOSS); | ||||
| UI_block_flag_enable( | UI_block_flag_enable( | ||||
| block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_LOOP | UI_BLOCK_NO_WIN_CLIP | UI_BLOCK_NUMSELECT); | 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_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| Show All 31 Lines | static uiBlock *block_create_autorun_warning(struct bContext *C, | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| /* Buttons */ | /* Buttons */ | ||||
| uiBut *but; | uiBut *but; | ||||
| uiLayout *split = uiLayoutSplit(layout, 0.0f, true); | uiLayout *split = uiLayoutSplit(layout, 0.0f, true); | ||||
| col = uiLayoutColumn(split, false); | col = uiLayoutColumn(split, false); | ||||
| /* Allow reload if we have a saved file. */ | /* Allow reload if we have a saved file. | ||||
| if (G.relbase_valid) { | * Otherwise just enable scripts and reset the depsgraphs. */ | ||||
| if (G.relbase_valid && wm->file_saved) { | |||||
| but = uiDefIconTextBut(block, | but = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_NONE, | ICON_NONE, | ||||
| IFACE_("Allow Execution"), | IFACE_("Allow Execution"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 50, | 50, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | NULL, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Reload file with execution of Python scripts enabled")); | TIP_("Reload file with execution of Python scripts enabled")); | ||||
| UI_but_func_set(but, wm_block_autorun_warning_allow, block, NULL); | UI_but_func_set(but, wm_block_autorun_warning_reload_with_scripts, block, NULL); | ||||
| } | } | ||||
| else { | else { | ||||
| uiItemS(col); | but = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | |||||
| 0, | |||||
| ICON_NONE, | |||||
| IFACE_("Allow Execution"), | |||||
| 0, | |||||
| 0, | |||||
| 50, | |||||
| UI_UNIT_Y, | |||||
| NULL, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| TIP_("Enable scripts")); | |||||
| UI_but_func_set(but, wm_block_autorun_warning_enable_scripts, block, NULL); | |||||
| } | } | ||||
| /* empty space between buttons */ | /* empty space between buttons */ | ||||
| col = uiLayoutColumn(split, false); | col = uiLayoutColumn(split, false); | ||||
| uiItemS(col); | uiItemS(col); | ||||
| col = uiLayoutColumn(split, 1); | col = uiLayoutColumn(split, 1); | ||||
| but = uiDefIconTextBut(block, | but = uiDefIconTextBut(block, | ||||
| ▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines | |||||