Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_ops.c
| Show All 15 Lines | |||||
| * The Original Code is Copyright (C) 2009 Blender Foundation. | * The Original Code is Copyright (C) 2009 Blender Foundation. | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edinterface | * \ingroup edinterface | ||||
| */ | */ | ||||
| #include <CLG_log.h> | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "DNA_object_types.h" /* for OB_DATA_SUPPORT_ID */ | #include "DNA_object_types.h" /* for OB_DATA_SUPPORT_ID */ | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_text_types.h" | #include "DNA_text_types.h" | ||||
| Show All 36 Lines | |||||
| /* for Copy As Driver */ | /* for Copy As Driver */ | ||||
| #include "ED_keyframing.h" | #include "ED_keyframing.h" | ||||
| /* 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" | ||||
| static CLG_LogRef LOG = {"interface.ops"}; | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \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; | ||||
| ▲ Show 20 Lines • Show All 1,154 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_ghash_free(ui_editsource_info->hash, NULL, MEM_freeN); | BLI_ghash_free(ui_editsource_info->hash, NULL, MEM_freeN); | ||||
| MEM_freeN(ui_editsource_info); | MEM_freeN(ui_editsource_info); | ||||
| ui_editsource_info = NULL; | ui_editsource_info = NULL; | ||||
| } | } | ||||
| static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b) | static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b) | ||||
| { | { | ||||
| # if 0 | CLOG_VERBOSE(&LOG, 1, "matching buttons: '%s' == '%s'", but_a->drawstr, but_b->drawstr); | ||||
| printf("matching buttons: '%s' == '%s'\n", but_a->drawstr, but_b->drawstr); | |||||
| # endif | |||||
| /* this just needs to be a 'good-enough' comparison so we can know beyond | /* this just needs to be a 'good-enough' comparison so we can know beyond | ||||
| * reasonable doubt that these buttons are the same between redraws. | * reasonable doubt that these buttons are the same between redraws. | ||||
| * if this fails it only means edit-source fails - campbell */ | * if this fails it only means edit-source fails - campbell */ | ||||
| if (BLI_rctf_compare(&but_a->rect, &but_b->rect, FLT_EPSILON) && (but_a->type == but_b->type) && | if (BLI_rctf_compare(&but_a->rect, &but_b->rect, FLT_EPSILON) && (but_a->type == but_b->type) && | ||||
| (but_a->rnaprop == but_b->rnaprop) && (but_a->optype == but_b->optype) && | (but_a->rnaprop == but_b->rnaprop) && (but_a->optype == but_b->optype) && | ||||
| (but_a->unit_type == but_b->unit_type) && | (but_a->unit_type == but_b->unit_type) && | ||||
| STREQLEN(but_a->drawstr, but_b->drawstr, UI_MAX_DRAW_STR)) { | STREQLEN(but_a->drawstr, but_b->drawstr, UI_MAX_DRAW_STR)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void UI_editsource_active_but_test(uiBut *but) | void UI_editsource_active_but_test(uiBut *but) | ||||
| { | { | ||||
| extern void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); | extern void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); | ||||
| struct uiEditSourceButStore *but_store = MEM_callocN(sizeof(uiEditSourceButStore), __func__); | struct uiEditSourceButStore *but_store = MEM_callocN(sizeof(uiEditSourceButStore), __func__); | ||||
| const char *fn; | const char *fn; | ||||
| int lineno = -1; | int lineno = -1; | ||||
| # if 0 | CLOG_VERBOSE(&LOG, | ||||
| printf("comparing buttons: '%s' == '%s'\n", but->drawstr, ui_editsource_info->but_orig.drawstr); | 2, | ||||
| # endif | "comparing buttons: '%s' == '%s'", | ||||
| but->drawstr, | |||||
| ui_editsource_info->but_orig.drawstr); | |||||
| PyC_FileAndNum_Safe(&fn, &lineno); | PyC_FileAndNum_Safe(&fn, &lineno); | ||||
| if (lineno != -1) { | if (lineno != -1) { | ||||
| BLI_strncpy(but_store->py_dbg_fn, fn, sizeof(but_store->py_dbg_fn)); | BLI_strncpy(but_store->py_dbg_fn, fn, sizeof(but_store->py_dbg_fn)); | ||||
| but_store->py_dbg_ln = lineno; | but_store->py_dbg_ln = lineno; | ||||
| } | } | ||||
| else { | else { | ||||
| but_store->py_dbg_fn[0] = '\0'; | but_store->py_dbg_fn[0] = '\0'; | ||||
| but_store->py_dbg_ln = -1; | but_store->py_dbg_ln = -1; | ||||
| } | } | ||||
| BLI_ghash_insert(ui_editsource_info->hash, but, but_store); | BLI_ghash_insert(ui_editsource_info->hash, but, but_store); | ||||
| } | } | ||||
| static int editsource_text_edit(bContext *C, | static int editsource_text_edit(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| const char filepath[FILE_MAX], | const char filepath[FILE_MAX], | ||||
| const int line) | const int line) | ||||
| { | { | ||||
| struct Main *bmain = CTX_data_main(C); | struct Main *bmain = CTX_data_main(C); | ||||
| Text *text = NULL; | Text *text = NULL; | ||||
| /* Developers may wish to copy-paste to an external editor. */ | /* Developers may wish to copy-paste to an external editor. */ | ||||
| printf("%s:%d\n", filepath, line); | CLOG_INFO(&LOG, "%s:%d", filepath, line); | ||||
| LISTBASE_FOREACH (Text *, text_iter, &bmain->texts) { | LISTBASE_FOREACH (Text *, text_iter, &bmain->texts) { | ||||
| if (text_iter->filepath && BLI_path_cmp(text_iter->filepath, filepath) == 0) { | if (text_iter->filepath && BLI_path_cmp(text_iter->filepath, filepath) == 0) { | ||||
| text = text_iter; | text = text_iter; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| Show All 33 Lines | if (but) { | ||||
| struct uiEditSourceButStore *but_store = NULL; | struct uiEditSourceButStore *but_store = NULL; | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = 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 */ | ||||
| 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__); | |||||
| /* 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); | ED_region_do_layout(C, region); | ||||
| ED_region_do_draw(C, region); | ED_region_do_draw(C, region); | ||||
| region->do_draw = false; | region->do_draw = false; | ||||
| Show All 19 Lines | if (but) { | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_report(op->reports, RPT_ERROR, "Active button match cannot be found"); | BKE_report(op->reports, RPT_ERROR, "Active button match cannot be found"); | ||||
| ret = OPERATOR_CANCELLED; | ret = OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ui_editsource_active_but_clear(); | ui_editsource_active_but_clear(); | ||||
| // printf("%s: end\n", __func__); | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| BKE_report(op->reports, RPT_ERROR, "Active button not found"); | BKE_report(op->reports, RPT_ERROR, "Active button not found"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| static void UI_OT_editsource(wmOperatorType *ot) | static void UI_OT_editsource(wmOperatorType *ot) | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | if (ot == NULL) { | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| "Could not find operator '%s'! Please enable ui_translate add-on " | "Could not find operator '%s'! Please enable ui_translate add-on " | ||||
| "in the User Preferences", | "in the User Preferences", | ||||
| EDTSRC_I18N_OP_NAME); | EDTSRC_I18N_OP_NAME); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* 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); */ | CLOG_VERBOSE(&LOG, 2, "po path: %s", popath); | ||||
| if (popath[0] == '\0') { | if (popath[0] == '\0') { | ||||
| BKE_reportf( | BKE_reportf( | ||||
| op->reports, RPT_ERROR, "No valid po found for language '%s' under %s", uilng, root); | op->reports, RPT_ERROR, "No valid po found for language '%s' under %s", uilng, root); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| UI_but_string_info_get(C, | UI_but_string_info_get(C, | ||||
| but, | but, | ||||
| ▲ Show 20 Lines • Show All 342 Lines • Show Last 20 Lines | |||||