Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_operators.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| static struct EnumSearchMenu search_menu; | static struct EnumSearchMenu search_menu; | ||||
| search_menu.op = op; | search_menu.op = op; | ||||
| UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu, NULL); | UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu, NULL); | ||||
| return OPERATOR_INTERFACE; | return OPERATOR_INTERFACE; | ||||
| } | } | ||||
| int WM_operator_confirm_message_ex(bContext *C, | static void wm_operator_block_cancel(bContext *C, void *arg_data, void *arg_block) | ||||
| wmOperator *op, | |||||
| const char *title, | |||||
| const int icon, | |||||
| const char *message, | |||||
| const wmOperatorCallContext opcontext) | |||||
| { | { | ||||
| IDProperty *properties = op->ptr->data; | wmOperator *op = arg_data; | ||||
| uiBlock *block = arg_block; | |||||
| UI_popup_block_close(C, CTX_wm_window(C), block); | |||||
| WM_redraw_windows(C); | |||||
| if (op) { | |||||
| if (op->type->cancel) { | |||||
| op->type->cancel(C, op); | |||||
| } | |||||
| WM_operator_free(op); | |||||
| } | |||||
| } | |||||
| if (properties && properties->len) { | static void wm_operator_block_confirm(bContext *C, void *arg_data, void *arg_block) | ||||
| properties = IDP_CopyProperty(op->ptr->data); | { | ||||
| wmOperator *op = arg_data; | |||||
| uiBlock *block = arg_block; | |||||
| UI_popup_block_close(C, CTX_wm_window(C), block); | |||||
| WM_redraw_windows(C); | |||||
| if (op) { | |||||
| WM_operator_call_ex(C, op, true); | |||||
| } | } | ||||
| else { | } | ||||
| properties = NULL; | |||||
| static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *userData) | |||||
| { | |||||
| wmOperator *op = userData; | |||||
| wmWarningDetails warning = {0}; | |||||
| STRNCPY(warning.title, WM_operatortype_description(C, op->type, op->ptr)); | |||||
| STRNCPY(warning.confirm_button, WM_operatortype_name(op->type, op->ptr)); | |||||
| STRNCPY(warning.cancel_button, TIP_("Cancel")); | |||||
| warning.icon = ALERT_ICON_WARNING; | |||||
| warning.size = WM_WARNING_SIZE_SMALL; | |||||
| warning.position = WM_WARNING_POSITON_MOUSE; | |||||
| warning.confirm_default = true; | |||||
| warning.cancel_default = false; | |||||
| warning.mouse_move_quit = true; | |||||
| warning.red_alert = false; | |||||
| /* uiBlock.flag */ | |||||
| int block_flags = UI_BLOCK_KEEP_OPEN | UI_BLOCK_LOOP | UI_BLOCK_NO_WIN_CLIP | UI_BLOCK_NUMSELECT; | |||||
| if (op->type->warning) { | |||||
| op->type->warning(C, op, &warning); | |||||
| } | |||||
| if (warning.mouse_move_quit) { | |||||
| block_flags |= UI_BLOCK_MOVEMOUSE_QUIT; | |||||
| } | |||||
| if (warning.icon < ALERT_ICON_WARNING || warning.icon >= ALERT_ICON_MAX) { | |||||
| warning.icon = ALERT_ICON_QUESTION; | |||||
| } | } | ||||
| uiPopupMenu *pup = UI_popup_menu_begin(C, title, icon); | uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); | ||||
| uiLayout *layout = UI_popup_menu_layout(pup); | UI_block_flag_enable(block, block_flags); | ||||
| uiItemFullO_ptr(layout, op->type, message, ICON_NONE, properties, opcontext, 0, NULL); | UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | ||||
| UI_popup_menu_end(C, pup); | |||||
| return OPERATOR_INTERFACE; | const uiStyle *style = UI_style_get_dpi(); | ||||
| } | int text_width = MAX3(120 * U.dpi_fac, | ||||
| BLF_width(style->widget.uifont_id, warning.title, ARRAY_SIZE(warning.title)), | |||||
| BLF_width(style->widget.uifont_id, warning.message, ARRAY_SIZE(warning.message))); | |||||
| const bool small = warning.size == WM_WARNING_SIZE_SMALL; | |||||
| const int padding = (small ? 7 : 14) * U.dpi_fac; | |||||
| const short icon_size = (small ? (warning.message[0] ? 48 : 32) : 64) * U.dpi_fac; | |||||
| const int dialog_width = icon_size + text_width + (style->columnspace * 2.5); | |||||
| const float split_factor = (float)icon_size / (float)(dialog_width - style->columnspace); | |||||
| 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 on the left. */ | |||||
| uiLayout *layout = uiLayoutRow(split_block, true); | |||||
| /* Using 'align_left' with 'row' avoids stretching the icon along the width of column. */ | |||||
| uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_LEFT); | |||||
| uiDefButAlert(block, warning.icon, 0, 0, icon_size, icon_size); | |||||
| /* The rest of the content on the right. */ | |||||
| layout = uiLayoutColumn(split_block, true); | |||||
| if (warning.title[0]) { | |||||
| if (!warning.message[0]) { | |||||
| uiItemS(layout); | |||||
| } | |||||
| uiItemL_ex(layout, warning.title, ICON_NONE, true, false); | |||||
| } | |||||
| if (warning.message[0]) { | |||||
| uiItemL(layout, warning.message, ICON_NONE); | |||||
| } | |||||
| int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message) | uiItemS_ex(layout, small ? 0.5f : 4.0f); | ||||
| { | |||||
| return WM_operator_confirm_message_ex( | /* Buttons. */ | ||||
| C, op, IFACE_("OK?"), ICON_QUESTION, message, WM_OP_EXEC_REGION_WIN); | |||||
| #ifdef _WIN32 | |||||
| const bool windows_layout = true; | |||||
| #else | |||||
| const bool windows_layout = false; | |||||
| #endif | |||||
| uiBut *confirm = NULL; | |||||
| uiBut *cancel = NULL; | |||||
| int height = UI_UNIT_Y; | |||||
| uiLayout *split = uiLayoutSplit(small ? block_layout : layout, 0.0f, true); | |||||
| uiLayoutSetScaleY(split, small ? 1.1f : 1.2f); | |||||
| uiLayoutColumn(split, false); | |||||
| if (windows_layout) { | |||||
| confirm = uiDefIconTextBut( | |||||
| block, UI_BTYPE_BUT, 0, 0, warning.confirm_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); | |||||
| uiLayoutColumn(split, false); | |||||
| } | |||||
| cancel = uiDefIconTextBut( | |||||
| block, UI_BTYPE_BUT, 0, 0, warning.cancel_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); | |||||
| if (!windows_layout) { | |||||
| uiLayoutColumn(split, false); | |||||
| confirm = uiDefIconTextBut( | |||||
| block, UI_BTYPE_BUT, 0, 0, warning.confirm_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); | |||||
| } | |||||
| UI_block_func_set(block, NULL, NULL, NULL); | |||||
| UI_but_func_set(confirm, wm_operator_block_confirm, op, block); | |||||
| UI_but_func_set(cancel, wm_operator_block_cancel, op, block); | |||||
| UI_but_drawflag_disable(confirm, UI_BUT_TEXT_LEFT); | |||||
| UI_but_drawflag_disable(cancel, UI_BUT_TEXT_LEFT); | |||||
| if (warning.red_alert) { | |||||
| UI_but_flag_enable(confirm, UI_BUT_REDALERT); | |||||
| } | |||||
| else { | |||||
| if (warning.cancel_default) { | |||||
| UI_but_flag_enable(cancel, UI_BUT_ACTIVE_DEFAULT); | |||||
| } | |||||
| else if (warning.confirm_default) { | |||||
| UI_but_flag_enable(confirm, UI_BUT_ACTIVE_DEFAULT); | |||||
| } | |||||
| } | |||||
| if (warning.position == WM_WARNING_POSITON_MOUSE) { | |||||
| int x = uiLayoutGetWidth(layout) * (windows_layout ? -0.33f : -0.66f); | |||||
| int y = UI_UNIT_Y * (warning.message[0] ? 3.1 : 2.5); | |||||
| UI_block_bounds_set_popup(block, padding, (const int[2]){x, y}); | |||||
| } | |||||
| else if (warning.position == WM_WARNING_POSITON_CENTER) { | |||||
| UI_block_bounds_set_centered(block, padding); | |||||
| } | |||||
| return block; | |||||
| } | } | ||||
| int WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | int WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| return WM_operator_confirm_message(C, op, NULL); | UI_popup_block_ex(C, wm_block_confirm_create, NULL, NULL, op, op); | ||||
| return OPERATOR_RUNNING_MODAL; | |||||
| } | } | ||||
| int WM_operator_confirm_or_exec(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | int WM_operator_confirm_or_exec(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| const bool confirm = RNA_boolean_get(op->ptr, "confirm"); | if (RNA_boolean_get(op->ptr, "confirm")) { | ||||
| if (confirm) { | return WM_operator_confirm(C, op, NULL); | ||||
| return WM_operator_confirm_message(C, op, NULL); | |||||
| } | } | ||||
| return op->type->exec(C, op); | return op->type->exec(C, op); | ||||
| } | } | ||||
| int WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | int WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| if (RNA_struct_property_is_set(op->ptr, "filepath")) { | if (RNA_struct_property_is_set(op->ptr, "filepath")) { | ||||
| return WM_operator_call_notest(C, op); /* call exec direct */ | return WM_operator_call_notest(C, op); /* call exec direct */ | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||