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.
This commit is contained in:
2017-03-15 03:43:44 +11:00
parent 1208792adb
commit 76ec329dd1
3 changed files with 26 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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);

View File

@@ -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)
{