[Bf-blender-cvs] [76ec329dd1] master: WM: add Operator.is_repeat() check for C & Py

Campbell Barton noreply at git.blender.org
Tue Mar 14 17:52:25 CET 2017


Commit: 76ec329dd1de6b94b74abf4ee6728266b15fb31d
Author: Campbell Barton
Date:   Wed Mar 15 03:43:44 2017 +1100
Branches: master
https://developer.blender.org/rB76ec329dd1de6b94b74abf4ee6728266b15fb31d

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.

===================================================================

M	source/blender/makesrna/intern/rna_wm_api.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index 1f23ab938f..677ea92aea 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 2b82f1becb..a33f4277a4 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 282091bb81..f26ee0e73e 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)
 {




More information about the Bf-blender-cvs mailing list