diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-03-14 19:43:44 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-03-14 19:57:01 +0300 |
commit | 76ec329dd1de6b94b74abf4ee6728266b15fb31d (patch) | |
tree | d49930caf678f501ac0a47899ddd757508288a87 | |
parent | 1208792adb30f1a2a4833b0503ce240f5f349501 (diff) |
WM: add Operator.is_repeat() check for C & Py
This addresses an issue raised by D2453 -
that there was no way to check if operators are run
multiple times in a row.
Actions are still ignored that don't cause an UNDO event.
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 11 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 14 |
3 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index 1f23ab938fb..677ea92aea1 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -87,6 +87,11 @@ static void rna_Operator_report(wmOperator *op, int type, const char *msg) BKE_report(op->reports, type, msg); } +static int rna_Operator_is_repeat(wmOperator *op, bContext *C) +{ + return WM_operator_is_repeat(C, op); +} + /* since event isn't needed... */ static void rna_Operator_enum_search_invoke(bContext *C, wmOperator *op) { @@ -521,6 +526,12 @@ void RNA_api_operator(StructRNA *srna) parm = RNA_def_string(func, "message", NULL, 0, "Report Message", ""); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + /* utility, not for registering */ + func = RNA_def_function(srna, "is_repeat", "rna_Operator_is_repeat"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + /* return */ + parm = RNA_def_boolean(func, "result", 0, "result", ""); + RNA_def_function_return(func, parm); /* Registration */ diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 2b82f1becb3..a33f4277a4e 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -276,6 +276,7 @@ int WM_operator_call (struct bContext *C, struct wmOperator *op); int WM_operator_call_notest(struct bContext *C, struct wmOperator *op); int WM_operator_repeat (struct bContext *C, struct wmOperator *op); bool WM_operator_repeat_check(const struct bContext *C, struct wmOperator *op); +bool WM_operator_is_repeat(const struct bContext *C, const struct wmOperator *op); int WM_operator_name_call_ptr(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties); int WM_operator_name_call(struct bContext *C, const char *opstring, short context, struct PointerRNA *properties); int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, const bool is_undo); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 282091bb814..f26ee0e73ec 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -880,6 +880,20 @@ bool WM_operator_repeat_check(const bContext *UNUSED(C), wmOperator *op) return false; } +bool WM_operator_is_repeat(const bContext *C, const wmOperator *op) +{ + /* may be in the operators list or not */ + wmOperator *op_prev; + if (op->prev == NULL && op->next == NULL) { + wmWindowManager *wm = CTX_wm_manager(C); + op_prev = wm->operators.last; + } + else { + op_prev = op->prev; + } + return (op_prev && (op->type == op_prev->type)); +} + static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, PointerRNA *properties, ReportList *reports) { |