diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 46 | ||||
-rw-r--r-- | source/blender/python/BPY_extern.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 16 |
3 files changed, 39 insertions, 25 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 10c98a06511..effe2d6be1a 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -565,35 +565,45 @@ static int run_script_poll(bContext *C) return (CTX_data_edit_text(C) != NULL); } -static int run_script_exec(bContext *C, wmOperator *op) +static int run_script(bContext *C, ReportList *reports) { -#ifndef WITH_PYTHON - (void)C; /* unused */ - - BKE_report(op->reports, RPT_ERROR, "Python disabled in this build"); - - return OPERATOR_CANCELLED; -#else Text *text= CTX_data_edit_text(C); - SpaceText *st= CTX_wm_space_text(C); + const short is_live= (reports == NULL); /* only for comparison */ void *curl_prev= text->curl; int curc_prev= text->curc; - if (BPY_text_exec(C, text, op->reports)) + if (BPY_text_exec(C, text, reports, !is_live)) { + if(is_live) { + /* for nice live updates */ + WM_event_add_notifier(C, NC_WINDOW|NA_EDITED, NULL); + } return OPERATOR_FINISHED; + } /* Dont report error messages while live editing */ - if(!(st && st->live_edit)) { + if(!is_live) { if(text->curl != curl_prev || curc_prev != text->curc) { text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); } - - BKE_report(op->reports, RPT_ERROR, "Python script fail, look in the console for now..."); + + BKE_report(reports, RPT_ERROR, "Python script fail, look in the console for now..."); } return OPERATOR_CANCELLED; +} + +static int run_script_exec(bContext *C, wmOperator *op) +{ +#ifndef WITH_PYTHON + (void)C; /* unused */ + + BKE_report(op->reports, RPT_ERROR, "Python disabled in this build"); + + return OPERATOR_CANCELLED; +#else + return run_script(C, op->reports); #endif } @@ -776,7 +786,7 @@ static int paste_exec(bContext *C, wmOperator *op) /* run the script while editing, evil but useful */ if(CTX_wm_space_text(C)->live_edit) - run_script_exec(C, op); + run_script(C, NULL); return OPERATOR_FINISHED; } @@ -833,7 +843,7 @@ void TEXT_OT_copy(wmOperatorType *ot) /******************* cut operator *********************/ -static int cut_exec(bContext *C, wmOperator *op) +static int cut_exec(bContext *C, wmOperator *UNUSED(op)) { Text *text= CTX_data_edit_text(C); @@ -847,7 +857,7 @@ static int cut_exec(bContext *C, wmOperator *op) /* run the script while editing, evil but useful */ if(CTX_wm_space_text(C)->live_edit) - run_script_exec(C, op); + run_script(C, NULL); return OPERATOR_FINISHED; } @@ -1983,7 +1993,7 @@ static int delete_exec(bContext *C, wmOperator *op) /* run the script while editing, evil but useful */ if(CTX_wm_space_text(C)->live_edit) - run_script_exec(C, op); + run_script(C, NULL); return OPERATOR_FINISHED; } @@ -2776,7 +2786,7 @@ static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event) /* run the script while editing, evil but useful */ if(ret==OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit) - run_script_exec(C, op); + run_script(C, NULL); return ret; } diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 2abe6044ca3..f4899849702 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -78,7 +78,7 @@ void BPY_python_end( void ); /* 2.5 UI Scripts */ int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports); -int BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports); +int BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports, const short do_jump); void BPY_text_free_code(struct Text *text); void BPY_modules_update(struct bContext *C); // XXX - annoying, need this for pointers that get out of date void BPY_modules_load_user(struct bContext *C); diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 4f59467a9d6..60ada6e983b 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -353,7 +353,7 @@ typedef struct { } PyModuleObject; #endif -static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports) +static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports, const short do_jump) { PyObject *main_mod= NULL; PyObject *py_dict= NULL, *py_result= NULL; @@ -382,7 +382,9 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st MEM_freeN( buf ); if(PyErr_Occurred()) { - python_script_error_jump_text(text); + if(do_jump) { + python_script_error_jump_text(text); + } BPY_text_free_code(text); } } @@ -429,7 +431,9 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st if (!py_result) { if(text) { - python_script_error_jump_text(text); + if(do_jump) { + python_script_error_jump_text(text); + } } BPy_errors_to_report(reports); } else { @@ -459,13 +463,13 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st /* Can run a file or text block */ int BPY_filepath_exec(bContext *C, const char *filepath, struct ReportList *reports) { - return python_script_exec(C, filepath, NULL, reports); + return python_script_exec(C, filepath, NULL, reports, FALSE); } -int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports) +int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, const short do_jump) { - return python_script_exec(C, NULL, text, reports); + return python_script_exec(C, NULL, text, reports, do_jump); } void BPY_DECREF(void *pyob_ptr) |