Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| PointerRNA ptr_a, ptr_b; | PointerRNA ptr_a, ptr_b; | ||||
| RNA_pointer_create(NULL, &RNA_Preferences, userdef_prev, &ptr_a); | RNA_pointer_create(NULL, &RNA_Preferences, userdef_prev, &ptr_a); | ||||
| RNA_pointer_create(NULL, &RNA_Preferences, userdef_curr, &ptr_b); | RNA_pointer_create(NULL, &RNA_Preferences, userdef_curr, &ptr_b); | ||||
| const bool is_dirty = userdef_curr->runtime.is_dirty; | const bool is_dirty = userdef_curr->runtime.is_dirty; | ||||
| rna_struct_update_when_changed(C, bmain, &ptr_a, &ptr_b); | rna_struct_update_when_changed(C, bmain, &ptr_a, &ptr_b); | ||||
| WM_reinit_gizmomap_all(bmain); | WM_reinit_gizmomap_all(bmain); | ||||
Severin: This static variable is easy to avoid I think. Just pass it as `arg` to `UI_popup_block_invoke… | |||||
| WM_keyconfig_reload(C); | WM_keyconfig_reload(C); | ||||
| userdef_curr->runtime.is_dirty = is_dirty; | userdef_curr->runtime.is_dirty = is_dirty; | ||||
| } | } | ||||
| /* Warning dialog box for the "loading factory settings" operator. */ | |||||
| static void wm_block_load_factory_cancel(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_load_factory_load(bContext *C, void *arg_block, void *arg) | |||||
| { | |||||
| wmWindow *win = CTX_wm_window(C); | |||||
| UI_popup_block_close(C, win, arg_block); | |||||
| const bool load_startup_file = POINTER_AS_INT(arg); | |||||
| WM_operator_name_call(C, | |||||
| load_startup_file ? | |||||
| "WM_OT_read_factory_settings" : | |||||
| "WM_OT_read_factory_userpref", | |||||
| WM_OP_EXEC_DEFAULT, NULL); | |||||
| } | |||||
| static void wm_block_load_factory_cancel_button(uiBlock *block) | |||||
| { | |||||
| uiBut *but = uiDefIconTextBut( | |||||
| block, UI_BTYPE_BUT, 0, ICON_NONE, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | |||||
| UI_but_func_set(but, wm_block_load_factory_cancel, block, NULL); | |||||
| UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | |||||
| } | |||||
| static void wm_block_load_factory_load_button(uiBlock *block, const bool load_startup_file) | |||||
| { | |||||
| uiBut *but = uiDefIconTextBut(block, | |||||
| UI_BTYPE_BUT, | |||||
| 0, | |||||
| ICON_NONE, | |||||
| load_startup_file ? | |||||
| IFACE_("Load Factory Settings") : | |||||
| IFACE_("Load Factory Preferences"), | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| UI_UNIT_Y, | |||||
| NULL, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| ""); | |||||
| UI_but_func_set(but, wm_block_load_factory_load, block, POINTER_FROM_INT(load_startup_file)); | |||||
| UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | |||||
| UI_but_flag_enable(but, UI_BUT_ACTIVE_DEFAULT); | |||||
| } | |||||
Done Inline ActionsThis should take into account rBbdad412fa76e6f so the dialog is wide enough with any text size setting. HooglyBoogly: This should take into account rBbdad412fa76e6f so the dialog is wide enough with any text size… | |||||
| static uiBlock *block_create_load_factory_dialog(struct bContext *C, | |||||
| struct ARegion *region, | |||||
| void *arg) | |||||
| { | |||||
| const uiStyle *style = UI_style_get_dpi(); | |||||
| const short icon_size = 64 * U.dpi_fac; | |||||
| const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points); | |||||
Not Done Inline ActionsWhere is this function coming from? I can't find it in master. Severin: Where is this function coming from? I can't find it in master. | |||||
| const int dialog_width = icon_size + (text_points_max * 42 * U.dpi_fac); | |||||
| /* By default, the space between icon and text/buttons will be equal to the 'columnspace', | |||||
| this extra padding will add some space by increasing the left column width, | |||||
| making the icon placement more symmetrical, between the block edge and the text. */ | |||||
| const float icon_padding = 5.0f * U.dpi_fac; | |||||
| /* Fixed size for icon column. */ | |||||
| const float split_factor = ((float)icon_size + icon_padding) / | |||||
| (float)(dialog_width - style->columnspace); | |||||
| const bool load_startup_file = POINTER_AS_INT(arg); | |||||
| uiBlock *block = UI_block_begin(C, region, "load_factory_dialog", 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 *block_layout = UI_block_layout( | |||||
| block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, dialog_width, 0, 0, style); | |||||
| /* Split layout to put alert icon on left side. */ | |||||
| uiLayout *split_block = uiLayoutSplit(block_layout, split_factor, false); | |||||
| /* Alert icon. */ | |||||
| uiLayout *layout = uiLayoutRow(split_block, false); | |||||
| /* Using 'align_left' with 'row' avoids stretching the icon along the width of column. */ | |||||
| uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_LEFT); | |||||
| uiDefButAlert(block, ALERT_ICON_WARNING, 0, 0, icon_size, icon_size); | |||||
| /* The rest of the content on the right. */ | |||||
Done Inline ActionsI would suggest something more like: "Preferences will not be saved when quitting after loading factory settings." HooglyBoogly: I would suggest something more like: "Preferences will not be saved when quitting after loading… | |||||
| layout = uiLayoutColumn(split_block, false); | |||||
| /* Title. */ | |||||
| uiItemL_ex(layout, | |||||
| load_startup_file ? | |||||
Done Inline ActionsHere I would suggest "Use \"Save Startup File\" and \"Save Preferences\" to make permanent changes to preferences." HooglyBoogly: Here I would suggest "Use \"Save Startup File\" and \"Save Preferences\" to make permanent… | |||||
| TIP_("Load Factory Startup File and Preferences?") : | |||||
| TIP_("Load Factory Preferences?"), | |||||
| ICON_NONE, | |||||
| true, | |||||
| false); | |||||
| /* Explanation text. */ | |||||
| uiLayout *col = uiLayoutColumn(layout, true); | |||||
| uiItemL( | |||||
Done Inline ActionsWhat about using the warning icon here? I think that's more common, I've never seen "WARNING" in Blender before. HooglyBoogly: What about using the warning icon here? I think that's more common, I've never seen "WARNING"… | |||||
| col, | |||||
| TIP_("Preferences will not be saved when quitting after loading factory settings."), | |||||
| ICON_NONE); | |||||
| uiItemL( | |||||
| col, | |||||
| load_startup_file ? | |||||
| TIP_("Use \"Save Startup File\" and \"Save Preferences\" to make permanent changes.") : | |||||
| TIP_("Use \"Save Preferences\" to make permanent changes to preferences."), | |||||
| ICON_NONE); | |||||
| /* The current file will not be saved before loading the factory startup file. */ | |||||
| if (load_startup_file) { | |||||
| if (U.uiflag & USER_SAVE_PROMPT && | |||||
| wm_file_or_image_is_modified(CTX_data_main(C), CTX_wm_manager(C))) { | |||||
| col = uiLayoutColumn(layout, false); /* As a separator. */ | |||||
| uiItemL_ex( | |||||
| col, TIP_("Warning: The current file will not be saved."), ICON_NONE, false, true); | |||||
| } | |||||
| } | |||||
| /* The space before the buttons. */ | |||||
| uiItemS_ex(layout, 3.0f); | |||||
| uiLayout *split = uiLayoutSplit(layout, 0.2f, false); | |||||
| uiLayoutSetScaleY(split, 1.2f); | |||||
| /* Empty space on left. */ | |||||
| uiLayoutColumn(split, false); | |||||
| #ifdef _WIN32 | |||||
| const bool windows_layout = true; | |||||
| #else | |||||
| const bool windows_layout = false; | |||||
| #endif | |||||
| /* Create buttons of different widths. */ | |||||
Done Inline ActionsI know this follows existing code, but I'd prefer logic to not depend on operator names. Severin: I know this follows existing code, but I'd prefer logic to not depend on operator names. | |||||
| uiLayout *split_right = uiLayoutSplit(split, windows_layout ? 0.6f : 0.4f, false); | |||||
| /* "Load" button (Windows standard layout). */ | |||||
| if (windows_layout) { | |||||
| uiLayoutColumn(split_right, false); | |||||
| wm_block_load_factory_load_button(block, load_startup_file); | |||||
| } | |||||
| /* "Cancel" button. */ | |||||
| uiLayoutColumn(split_right, false); | |||||
| wm_block_load_factory_cancel_button(block); | |||||
| /* "Load" button (Non-Windows layout, macOS and Linux). */ | |||||
| if (!windows_layout) { | |||||
| uiLayoutColumn(split_right, false); | |||||
| wm_block_load_factory_load_button(block, load_startup_file); | |||||
| } | |||||
| UI_block_bounds_set_centered(block, 14 * U.dpi_fac); | |||||
| return block; | |||||
| } | |||||
| static int wm_read_factory_settings_invoke( | |||||
| bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) | |||||
| { | |||||
| const bool load_startup_file = true; | |||||
| UI_popup_block_invoke( | |||||
| C, block_create_load_factory_dialog, POINTER_FROM_INT(load_startup_file), NULL); | |||||
| return OPERATOR_INTERFACE; | |||||
| } | |||||
| static int wm_read_factory_userpref_invoke( | |||||
| bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) | |||||
| { | |||||
| const bool load_startup_file = false; | |||||
| UI_popup_block_invoke( | |||||
| C, block_create_load_factory_dialog, POINTER_FROM_INT(load_startup_file), NULL); | |||||
| return OPERATOR_INTERFACE; | |||||
| } | |||||
| static int wm_userpref_read_exec(bContext *C, wmOperator *op) | static int wm_userpref_read_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const bool use_data = false; | const bool use_data = false; | ||||
| const bool use_userdef = true; | const bool use_userdef = true; | ||||
| const bool use_factory_settings = STREQ(op->type->idname, "WM_OT_read_factory_userpref"); | const bool use_factory_settings = STREQ(op->type->idname, "WM_OT_read_factory_userpref"); | ||||
| UserDef U_backup = U; | UserDef U_backup = U; | ||||
| Show All 35 Lines | |||||
| ot->invoke = WM_operator_confirm; | ot->invoke = WM_operator_confirm; | ||||
| ot->exec = wm_userpref_read_exec; | ot->exec = wm_userpref_read_exec; | ||||
| } | } | ||||
| void WM_OT_read_factory_userpref(wmOperatorType *ot) | void WM_OT_read_factory_userpref(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Load Factory Preferences"; | ot->name = "Load Factory Preferences"; | ||||
| ot->idname = "WM_OT_read_factory_userpref"; | ot->idname = "WM_OT_read_factory_userpref"; | ||||
| ot->description = | ot->description = "Load factory default preferences"; | ||||
| "Load factory default preferences. " | |||||
| "To make changes to preferences permanent, use \"Save Preferences\""; | |||||
| ot->invoke = WM_operator_confirm; | ot->invoke = wm_read_factory_userpref_invoke; | ||||
| ot->exec = wm_userpref_read_exec; | ot->exec = wm_userpref_read_exec; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Read File History Operator | /** \name Read File History Operator | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| } | } | ||||
| void WM_OT_read_homefile(wmOperatorType *ot) | void WM_OT_read_homefile(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| ot->name = "Reload Start-Up File"; | ot->name = "Reload Start-Up File"; | ||||
| ot->idname = "WM_OT_read_homefile"; | ot->idname = "WM_OT_read_homefile"; | ||||
| ot->description = "Open the default file (doesn't save the current file)"; | ot->description = "Open the default file"; | ||||
| ot->invoke = wm_homefile_read_invoke; | ot->invoke = wm_homefile_read_invoke; | ||||
| ot->exec = wm_homefile_read_exec; | ot->exec = wm_homefile_read_exec; | ||||
| prop = RNA_def_string_file_path( | prop = RNA_def_string_file_path( | ||||
| ot->srna, "filepath", NULL, FILE_MAX, "File Path", "Path to an alternative start-up file"); | ot->srna, "filepath", NULL, FILE_MAX, "File Path", "Path to an alternative start-up file"); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN); | RNA_def_property_flag(prop, PROP_HIDDEN); | ||||
| Show All 16 Lines | |||||
| /* omit poll to run in background mode */ | /* omit poll to run in background mode */ | ||||
| } | } | ||||
| void WM_OT_read_factory_settings(wmOperatorType *ot) | void WM_OT_read_factory_settings(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Load Factory Settings"; | ot->name = "Load Factory Settings"; | ||||
| ot->idname = "WM_OT_read_factory_settings"; | ot->idname = "WM_OT_read_factory_settings"; | ||||
| ot->description = | ot->description = "Load factory default startup file and preferences"; | ||||
| "Load factory default startup file and preferences. " | |||||
| "To make changes permanent, use \"Save Startup File\" and \"Save Preferences\""; | |||||
| ot->invoke = WM_operator_confirm; | ot->invoke = wm_read_factory_settings_invoke; | ||||
| ot->exec = wm_homefile_read_exec; | ot->exec = wm_homefile_read_exec; | ||||
| read_homefile_props(ot); | read_homefile_props(ot); | ||||
| /* omit poll to run in background mode */ | /* omit poll to run in background mode */ | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 192 Lines • Show Last 20 Lines | |||||
This static variable is easy to avoid I think. Just pass it as arg to UI_popup_block_invoke(), to the functions that need it, and via arg2 in UI_but_func_set() to the buttons that need it. You should use POINTER_FROM_INT()/POINTER_AS_INT() for that.