Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_ops.c
| Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| /* only for UI_OT_editsource */ | /* only for UI_OT_editsource */ | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_text.h" | #include "ED_text.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Immediate redraw helper | |||||
| * | |||||
| * Generally handlers shouldn't do any redrawing, that includes the layout/button definitions. That | |||||
| * violates the Model-View-Controller pattern. | |||||
| * | |||||
| * But there are some operators which really need to re-run the layout definitions for various | |||||
| * reasons. For example, "Edit Source" does it to find out which exact Python code added a button. | |||||
| * Other operators may need to access buttons that aren't currently visible. In Blender's UI code | |||||
| * design that typically means just not adding the button in the first place, for a particular | |||||
| * redraw. So the operator needs to change context and re-create the layout, so the button becomes | |||||
| * available to act on. | |||||
| * | |||||
| * \{ */ | |||||
| static void ui_region_redraw_immediately(bContext *C, ARegion *region) | |||||
| { | |||||
| ED_region_do_layout(C, region); | |||||
| WM_draw_region_viewport_bind(region); | |||||
| ED_region_do_draw(C, region); | |||||
| WM_draw_region_viewport_unbind(region); | |||||
| region->do_draw = false; | |||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Copy Data Path Operator | /** \name Copy Data Path Operator | ||||
| * \{ */ | * \{ */ | ||||
| static bool copy_data_path_button_poll(bContext *C) | static bool copy_data_path_button_poll(bContext *C) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| char *path; | char *path; | ||||
| ▲ Show 20 Lines • Show All 558 Lines • ▼ Show 20 Lines | static int override_remove_button_exec(bContext *C, wmOperator *op) | ||||
| const bool is_template = ID_IS_OVERRIDE_LIBRARY_TEMPLATE(id); | const bool is_template = ID_IS_OVERRIDE_LIBRARY_TEMPLATE(id); | ||||
| /* We need source (i.e. linked data) to restore values of deleted overrides... | /* We need source (i.e. linked data) to restore values of deleted overrides... | ||||
| * If this is an override template, we obviously do not need to restore anything. */ | * If this is an override template, we obviously do not need to restore anything. */ | ||||
| if (!is_template) { | if (!is_template) { | ||||
| PropertyRNA *src_prop; | PropertyRNA *src_prop; | ||||
| RNA_id_pointer_create(id->override_library->reference, &id_refptr); | RNA_id_pointer_create(id->override_library->reference, &id_refptr); | ||||
| if (!RNA_path_resolve_property(&id_refptr, oprop->rna_path, &src, &src_prop)) { | if (!RNA_path_resolve_property(&id_refptr, oprop->rna_path, &src, &src_prop)) { | ||||
| BLI_assert(0 && "Failed to create matching source (linked data) RNA pointer"); | BLI_assert_msg(0, "Failed to create matching source (linked data) RNA pointer"); | ||||
| } | } | ||||
| } | } | ||||
| if (!all && index != -1) { | if (!all && index != -1) { | ||||
| bool is_strict_find; | bool is_strict_find; | ||||
| /* Remove override operation for given item, | /* Remove override operation for given item, | ||||
| * add singular operations for the other items as needed. */ | * add singular operations for the other items as needed. */ | ||||
| IDOverrideLibraryPropertyOperation *opop = BKE_lib_override_library_property_operation_find( | IDOverrideLibraryPropertyOperation *opop = BKE_lib_override_library_property_operation_find( | ||||
| ▲ Show 20 Lines • Show All 713 Lines • ▼ Show 20 Lines | if (but) { | ||||
| UI_screen_free_active_but(C, CTX_wm_screen(C)); | UI_screen_free_active_but(C, CTX_wm_screen(C)); | ||||
| // printf("%s: begin\n", __func__); | // printf("%s: begin\n", __func__); | ||||
| /* take care not to return before calling ui_editsource_active_but_clear */ | /* take care not to return before calling ui_editsource_active_but_clear */ | ||||
| ui_editsource_active_but_set(but); | ui_editsource_active_but_set(but); | ||||
| /* redraw and get active button python info */ | /* redraw and get active button python info */ | ||||
| ED_region_do_layout(C, region); | ui_region_redraw_immediately(C, region); | ||||
| WM_draw_region_viewport_bind(region); | |||||
| ED_region_do_draw(C, region); | |||||
| WM_draw_region_viewport_unbind(region); | |||||
| region->do_draw = false; | |||||
| for (BLI_ghashIterator_init(&ghi, ui_editsource_info->hash); | for (BLI_ghashIterator_init(&ghi, ui_editsource_info->hash); | ||||
| BLI_ghashIterator_done(&ghi) == false; | BLI_ghashIterator_done(&ghi) == false; | ||||
| BLI_ghashIterator_step(&ghi)) { | BLI_ghashIterator_step(&ghi)) { | ||||
| uiBut *but_key = BLI_ghashIterator_getKey(&ghi); | uiBut *but_key = BLI_ghashIterator_getKey(&ghi); | ||||
| if (but_key && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but_key)) { | if (but_key && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but_key)) { | ||||
| but_store = BLI_ghashIterator_getValue(&ghi); | but_store = BLI_ghashIterator_getValue(&ghi); | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 436 Lines • ▼ Show 20 Lines | static void UI_OT_drop_color(wmOperatorType *ot) | ||||
| RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, FLT_MAX, "Color", "Source color", 0.0, 1.0); | RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, FLT_MAX, "Color", "Source color", 0.0, 1.0); | ||||
| RNA_def_boolean(ot->srna, "gamma", 0, "Gamma Corrected", "The source color is gamma corrected"); | RNA_def_boolean(ot->srna, "gamma", 0, "Gamma Corrected", "The source color is gamma corrected"); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name UI List Search Operator | |||||
| * \{ */ | |||||
| static bool ui_list_focused_poll(bContext *C) | |||||
| { | |||||
| const ARegion *region = CTX_wm_region(C); | |||||
| const wmWindow *win = CTX_wm_window(C); | |||||
| const uiList *list = UI_list_find_mouse_over(region, win->eventstate); | |||||
| return list != NULL; | |||||
| } | |||||
| /** | |||||
| * Ensure the filter options are set to be visible in the UI list. | |||||
| * \return if the visibility changed, requiring a redraw. | |||||
| */ | |||||
| static bool ui_list_unhide_filter_options(uiList *list) | |||||
| { | |||||
| if (list->filter_flag & UILST_FLT_SHOW) { | |||||
| /* Nothing to be done. */ | |||||
| return false; | |||||
| } | |||||
| list->filter_flag |= UILST_FLT_SHOW; | |||||
| return true; | |||||
| } | |||||
| static int ui_list_start_filter_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) | |||||
| { | |||||
| ARegion *region = CTX_wm_region(C); | |||||
| uiList *list = UI_list_find_mouse_over(region, event); | |||||
| /* Poll should check. */ | |||||
| BLI_assert(list != NULL); | |||||
| if (ui_list_unhide_filter_options(list)) { | |||||
| ui_region_redraw_immediately(C, region); | |||||
| } | |||||
| if (!UI_textbutton_activate_rna(C, region, list, "filter_name")) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void UI_OT_list_start_filter(wmOperatorType *ot) | |||||
| { | |||||
| ot->name = "List Filter"; | |||||
| ot->idname = "UI_OT_list_start_filter"; | |||||
| ot->description = "Start entering filter text for the list in focus"; | |||||
| ot->invoke = ui_list_start_filter_invoke; | |||||
| ot->poll = ui_list_focused_poll; | |||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Operator & Keymap Registration | /** \name Operator & Keymap Registration | ||||
| * \{ */ | * \{ */ | ||||
| void ED_operatortypes_ui(void) | void ED_operatortypes_ui(void) | ||||
| { | { | ||||
| WM_operatortype_append(UI_OT_copy_data_path_button); | WM_operatortype_append(UI_OT_copy_data_path_button); | ||||
| WM_operatortype_append(UI_OT_copy_as_driver_button); | WM_operatortype_append(UI_OT_copy_as_driver_button); | ||||
| WM_operatortype_append(UI_OT_copy_python_command_button); | WM_operatortype_append(UI_OT_copy_python_command_button); | ||||
| WM_operatortype_append(UI_OT_reset_default_button); | WM_operatortype_append(UI_OT_reset_default_button); | ||||
| WM_operatortype_append(UI_OT_assign_default_button); | WM_operatortype_append(UI_OT_assign_default_button); | ||||
| WM_operatortype_append(UI_OT_unset_property_button); | WM_operatortype_append(UI_OT_unset_property_button); | ||||
| WM_operatortype_append(UI_OT_override_type_set_button); | WM_operatortype_append(UI_OT_override_type_set_button); | ||||
| WM_operatortype_append(UI_OT_override_remove_button); | WM_operatortype_append(UI_OT_override_remove_button); | ||||
| WM_operatortype_append(UI_OT_copy_to_selected_button); | WM_operatortype_append(UI_OT_copy_to_selected_button); | ||||
| WM_operatortype_append(UI_OT_jump_to_target_button); | WM_operatortype_append(UI_OT_jump_to_target_button); | ||||
| WM_operatortype_append(UI_OT_drop_color); | WM_operatortype_append(UI_OT_drop_color); | ||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| WM_operatortype_append(UI_OT_editsource); | WM_operatortype_append(UI_OT_editsource); | ||||
| WM_operatortype_append(UI_OT_edittranslation_init); | WM_operatortype_append(UI_OT_edittranslation_init); | ||||
| #endif | #endif | ||||
| WM_operatortype_append(UI_OT_reloadtranslation); | WM_operatortype_append(UI_OT_reloadtranslation); | ||||
| WM_operatortype_append(UI_OT_button_execute); | WM_operatortype_append(UI_OT_button_execute); | ||||
| WM_operatortype_append(UI_OT_button_string_clear); | WM_operatortype_append(UI_OT_button_string_clear); | ||||
| WM_operatortype_append(UI_OT_list_start_filter); | |||||
| /* external */ | /* external */ | ||||
| WM_operatortype_append(UI_OT_eyedropper_color); | WM_operatortype_append(UI_OT_eyedropper_color); | ||||
| WM_operatortype_append(UI_OT_eyedropper_colorramp); | WM_operatortype_append(UI_OT_eyedropper_colorramp); | ||||
| WM_operatortype_append(UI_OT_eyedropper_colorramp_point); | WM_operatortype_append(UI_OT_eyedropper_colorramp_point); | ||||
| WM_operatortype_append(UI_OT_eyedropper_id); | WM_operatortype_append(UI_OT_eyedropper_id); | ||||
| WM_operatortype_append(UI_OT_eyedropper_depth); | WM_operatortype_append(UI_OT_eyedropper_depth); | ||||
| WM_operatortype_append(UI_OT_eyedropper_driver); | WM_operatortype_append(UI_OT_eyedropper_driver); | ||||
| WM_operatortype_append(UI_OT_eyedropper_gpencil_color); | WM_operatortype_append(UI_OT_eyedropper_gpencil_color); | ||||
| Show All 14 Lines | |||||