Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_ops.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| static int copy_data_path_button_poll(bContext *C) | static int copy_data_path_button_poll(bContext *C) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| char *path; | char *path; | ||||
| int index; | int index; | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| if (ptr.id.data && ptr.data && prop) { | if (ptr.id.data && ptr.data && prop) { | ||||
| path = RNA_path_from_ID_to_property(&ptr, prop); | path = RNA_path_from_ID_to_property(&ptr, prop); | ||||
| if (path) { | if (path) { | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static int copy_data_path_button_exec(bContext *C, wmOperator *UNUSED(op)) | static int copy_data_path_button_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| char *path; | char *path; | ||||
| int index; | int index; | ||||
| /* try to create driver using property retrieved from UI */ | /* try to create driver using property retrieved from UI */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| if (ptr.id.data && ptr.data && prop) { | if (ptr.id.data && ptr.data && prop) { | ||||
| path = RNA_path_from_ID_to_property(&ptr, prop); | path = RNA_path_from_ID_to_property(&ptr, prop); | ||||
| if (path) { | if (path) { | ||||
| WM_clipboard_text_set(path, false); | WM_clipboard_text_set(path, false); | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| Show All 23 Lines | |||||
| static int operator_button_property_finish(bContext *C, PointerRNA *ptr, PropertyRNA *prop) | static int operator_button_property_finish(bContext *C, PointerRNA *ptr, PropertyRNA *prop) | ||||
| { | { | ||||
| ID *id = ptr->id.data; | ID *id = ptr->id.data; | ||||
| /* perform updates required for this property */ | /* perform updates required for this property */ | ||||
| RNA_property_update(C, ptr, prop); | RNA_property_update(C, ptr, prop); | ||||
| /* as if we pressed the button */ | /* as if we pressed the button */ | ||||
| uiContextActivePropertyHandle(C); | UI_context_active_but_prop_handle(C); | ||||
| /* Since we don't want to undo _all_ edits to settings, eg window | /* Since we don't want to undo _all_ edits to settings, eg window | ||||
| * edits on the screen or on operator settings. | * edits on the screen or on operator settings. | ||||
| * it might be better to move undo's inline - campbell */ | * it might be better to move undo's inline - campbell */ | ||||
| if (id && ID_CHECK_UNDO(id)) { | if (id && ID_CHECK_UNDO(id)) { | ||||
| /* do nothing, go ahead with undo */ | /* do nothing, go ahead with undo */ | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| static int reset_default_button_poll(bContext *C) | static int reset_default_button_poll(bContext *C) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| int index; | int index; | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| return (ptr.data && prop && RNA_property_editable(&ptr, prop)); | return (ptr.data && prop && RNA_property_editable(&ptr, prop)); | ||||
| } | } | ||||
| static int reset_default_button_exec(bContext *C, wmOperator *op) | static int reset_default_button_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| int index; | int index; | ||||
| const bool all = RNA_boolean_get(op->ptr, "all"); | const bool all = RNA_boolean_get(op->ptr, "all"); | ||||
| /* try to reset the nominated setting to its default value */ | /* try to reset the nominated setting to its default value */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| /* if there is a valid property that is editable... */ | /* if there is a valid property that is editable... */ | ||||
| if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { | if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { | ||||
| if (RNA_property_reset(&ptr, prop, (all) ? -1 : index)) | if (RNA_property_reset(&ptr, prop, (all) ? -1 : index)) | ||||
| return operator_button_property_finish(C, &ptr, prop); | return operator_button_property_finish(C, &ptr, prop); | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| Show All 21 Lines | |||||
| static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op)) | static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| int index; | int index; | ||||
| /* try to unset the nominated property */ | /* try to unset the nominated property */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| /* if there is a valid property that is editable... */ | /* if there is a valid property that is editable... */ | ||||
| if (ptr.data && prop && RNA_property_editable(&ptr, prop) && | if (ptr.data && prop && RNA_property_editable(&ptr, prop) && | ||||
| /* RNA_property_is_idprop(prop) && */ | /* RNA_property_is_idprop(prop) && */ | ||||
| RNA_property_is_set(&ptr, prop)) | RNA_property_is_set(&ptr, prop)) | ||||
| { | { | ||||
| RNA_property_unset(&ptr, prop); | RNA_property_unset(&ptr, prop); | ||||
| return operator_button_property_finish(C, &ptr, prop); | return operator_button_property_finish(C, &ptr, prop); | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| static bool copy_to_selected_button(bContext *C, bool all, bool poll) | static bool copy_to_selected_button(bContext *C, bool all, bool poll) | ||||
| { | { | ||||
| PointerRNA ptr, lptr, idptr; | PointerRNA ptr, lptr, idptr; | ||||
| PropertyRNA *prop, *lprop; | PropertyRNA *prop, *lprop; | ||||
| bool success = false; | bool success = false; | ||||
| int index; | int index; | ||||
| /* try to reset the nominated setting to its default value */ | /* try to reset the nominated setting to its default value */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| /* if there is a valid property that is editable... */ | /* if there is a valid property that is editable... */ | ||||
| if (ptr.data && prop) { | if (ptr.data && prop) { | ||||
| char *path = NULL; | char *path = NULL; | ||||
| bool use_path_from_id; | bool use_path_from_id; | ||||
| CollectionPointerLink *link; | CollectionPointerLink *link; | ||||
| ListBase lb; | ListBase lb; | ||||
| ▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | else { | ||||
| WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); | WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); | ||||
| } | } | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int editsource_exec(bContext *C, wmOperator *op) | static int editsource_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| uiBut *but = uiContextActiveButton(C); | uiBut *but = UI_context_active_but_get(C); | ||||
| if (but) { | if (but) { | ||||
| GHashIterator ghi; | GHashIterator ghi; | ||||
| struct uiEditSourceButStore *but_store = NULL; | struct uiEditSourceButStore *but_store = NULL; | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| int ret; | int ret; | ||||
| /* needed else the active button does not get tested */ | /* needed else the active button does not get tested */ | ||||
| uiFreeActiveButtons(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_draw(C, ar); | ED_region_do_draw(C, ar); | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | static void edittranslation_find_po_file(const char *root, const char *uilng, char *path, const size_t maxlen) | ||||
| } | } | ||||
| /* Else no po file! */ | /* Else no po file! */ | ||||
| path[0] = '\0'; | path[0] = '\0'; | ||||
| } | } | ||||
| static int edittranslation_exec(bContext *C, wmOperator *op) | static int edittranslation_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| uiBut *but = uiContextActiveButton(C); | uiBut *but = UI_context_active_but_get(C); | ||||
| int ret = OPERATOR_CANCELLED; | int ret = OPERATOR_CANCELLED; | ||||
| if (but) { | if (but) { | ||||
| wmOperatorType *ot; | wmOperatorType *ot; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| char popath[FILE_MAX]; | char popath[FILE_MAX]; | ||||
| const char *root = U.i18ndir; | const char *root = U.i18ndir; | ||||
| const char *uilng = BLF_lang_get(); | const char *uilng = BLF_lang_get(); | ||||
| Show All 23 Lines | if (but) { | ||||
| /* Try to find a valid po file for current language... */ | /* Try to find a valid po file for current language... */ | ||||
| edittranslation_find_po_file(root, uilng, popath, FILE_MAX); | edittranslation_find_po_file(root, uilng, popath, FILE_MAX); | ||||
| /* printf("po path: %s\n", popath);*/ | /* printf("po path: %s\n", popath);*/ | ||||
| if (popath[0] == '\0') { | if (popath[0] == '\0') { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "No valid po found for language '%s' under %s", uilng, root); | BKE_reportf(op->reports, RPT_ERROR, "No valid po found for language '%s' under %s", uilng, root); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| uiButGetStrInfo(C, but, &but_label, &rna_label, &enum_label, &but_tip, &rna_tip, &enum_tip, | UI_but_string_info_get(C, but, &but_label, &rna_label, &enum_label, &but_tip, &rna_tip, &enum_tip, | ||||
| &rna_struct, &rna_prop, &rna_enum, &rna_ctxt, NULL); | &rna_struct, &rna_prop, &rna_enum, &rna_ctxt, NULL); | ||||
| WM_operator_properties_create_ptr(&ptr, ot); | WM_operator_properties_create_ptr(&ptr, ot); | ||||
| RNA_string_set(&ptr, "lang", uilng); | RNA_string_set(&ptr, "lang", uilng); | ||||
| RNA_string_set(&ptr, "po_file", popath); | RNA_string_set(&ptr, "po_file", popath); | ||||
| RNA_string_set(&ptr, "but_label", but_label.strinfo); | RNA_string_set(&ptr, "but_label", but_label.strinfo); | ||||
| RNA_string_set(&ptr, "rna_label", rna_label.strinfo); | RNA_string_set(&ptr, "rna_label", rna_label.strinfo); | ||||
| RNA_string_set(&ptr, "enum_label", enum_label.strinfo); | RNA_string_set(&ptr, "enum_label", enum_label.strinfo); | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| float color[4]; | float color[4]; | ||||
| bool gamma; | bool gamma; | ||||
| RNA_float_get_array(op->ptr, "color", color); | RNA_float_get_array(op->ptr, "color", color); | ||||
| gamma = RNA_boolean_get(op->ptr, "gamma"); | gamma = RNA_boolean_get(op->ptr, "gamma"); | ||||
| /* find button under mouse, check if it has RNA color property and | /* find button under mouse, check if it has RNA color property and | ||||
| * if it does copy the data */ | * if it does copy the data */ | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| if (but && but->type == COLOR && but->rnaprop) { | if (but && but->type == UI_BTYPE_COLOR && but->rnaprop) { | ||||
| const int color_len = RNA_property_array_length(&but->rnapoin, but->rnaprop); | const int color_len = RNA_property_array_length(&but->rnapoin, but->rnaprop); | ||||
| BLI_assert(color_len <= 4); | BLI_assert(color_len <= 4); | ||||
| /* keep alpha channel as-is */ | /* keep alpha channel as-is */ | ||||
| if (color_len == 4) { | if (color_len == 4) { | ||||
| color[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3); | color[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3); | ||||
| } | } | ||||
| if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | ||||
| if (!gamma) | if (!gamma) | ||||
| ui_block_to_display_space_v3(but->block, color); | ui_block_cm_to_display_space_v3(but->block, color); | ||||
| RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color); | RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color); | ||||
| RNA_property_update(C, &but->rnapoin, but->rnaprop); | RNA_property_update(C, &but->rnapoin, but->rnaprop); | ||||
| } | } | ||||
| else if (RNA_property_subtype(but->rnaprop) == PROP_COLOR) { | else if (RNA_property_subtype(but->rnaprop) == PROP_COLOR) { | ||||
| if (gamma) | if (gamma) | ||||
| ui_block_to_scene_linear_v3(but->block, color); | ui_block_cm_to_scene_linear_v3(but->block, color); | ||||
| RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color); | RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color); | ||||
| RNA_property_update(C, &but->rnapoin, but->rnaprop); | RNA_property_update(C, &but->rnapoin, but->rnaprop); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (gamma) { | if (gamma) { | ||||
| srgb_to_linearrgb_v3_v3(color, color); | srgb_to_linearrgb_v3_v3(color, color); | ||||
| } | } | ||||
| Show All 19 Lines | static void UI_OT_drop_color(wmOperatorType *ot) | ||||
| 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 "); | ||||
| } | } | ||||
| /* ********************************************************* */ | /* ********************************************************* */ | ||||
| /* Registration */ | /* Registration */ | ||||
| void UI_buttons_operatortypes(void) | void ED_button_operatortypes(void) | ||||
| { | { | ||||
| WM_operatortype_append(UI_OT_reset_default_theme); | WM_operatortype_append(UI_OT_reset_default_theme); | ||||
| WM_operatortype_append(UI_OT_copy_data_path_button); | WM_operatortype_append(UI_OT_copy_data_path_button); | ||||
| WM_operatortype_append(UI_OT_reset_default_button); | WM_operatortype_append(UI_OT_reset_default_button); | ||||
| WM_operatortype_append(UI_OT_unset_property_button); | WM_operatortype_append(UI_OT_unset_property_button); | ||||
| WM_operatortype_append(UI_OT_copy_to_selected_button); | WM_operatortype_append(UI_OT_copy_to_selected_button); | ||||
| WM_operatortype_append(UI_OT_reports_to_textblock); /* XXX: temp? */ | WM_operatortype_append(UI_OT_reports_to_textblock); /* XXX: temp? */ | ||||
| WM_operatortype_append(UI_OT_drop_color); | WM_operatortype_append(UI_OT_drop_color); | ||||
| Show All 10 Lines | |||||