WM: operator flag to check repeat/redo execution

This commit is contained in:
Campbell Barton 2018-01-19 21:07:43 +11:00
parent 53e062da94
commit 0cddc7e300
3 changed files with 19 additions and 4 deletions

View File

@ -398,13 +398,15 @@ enum {
/* low level flag so exec() operators can tell if they were invoked, use with care.
* typically this shouldn't make any difference, but it rare cases its needed (see smooth-view) */
OP_IS_INVOKE = (1 << 0),
/* So we can detect if an operators exec() call is activated from an interactive repeat. */
OP_IS_REPEAT = (1 << 1),
/* When the cursor is grabbed */
OP_IS_MODAL_GRAB_CURSOR = (1 << 1),
OP_IS_MODAL_GRAB_CURSOR = (1 << 2),
/* allow modal operators to have the region under the cursor for their context
* (the regiontype is maintained to prevent errors) */
OP_IS_MODAL_CURSOR_REGION = (1 << 2),
OP_IS_MODAL_CURSOR_REGION = (1 << 3),
};
#endif /* __DNA_WINDOWMANAGER_TYPES_H__ */

View File

@ -1443,6 +1443,11 @@ static void rna_def_operator_options_runtime(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Invoke", "True when invoked (even if only the execute callbacks available)");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_repeat", PROP_BOOLEAN, PROP_BOOLEAN);
RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_REPEAT);
RNA_def_property_ui_text(prop, "Repeat", "True when run from the redo panel");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_cursor_region", PROP_BOOLEAN, PROP_BOOLEAN);
RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_MODAL_CURSOR_REGION);
RNA_def_property_ui_text(prop, "Focus Region", "Enable to use the region under the cursor for modal execution");

View File

@ -802,14 +802,22 @@ static int wm_operator_exec(bContext *C, wmOperator *op, const bool repeat, cons
return retval;
if (op->type->exec) {
if (op->type->flag & OPTYPE_UNDO)
if (op->type->flag & OPTYPE_UNDO) {
wm->op_undo_depth++;
}
if (repeat) {
op->flag |= OP_IS_REPEAT;
}
retval = op->type->exec(C, op);
OPERATOR_RETVAL_CHECK(retval);
if (repeat) {
op->flag &= ~OP_IS_REPEAT;
}
if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm)
if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
wm->op_undo_depth--;
}
}
/* XXX Disabled the repeat check to address part 2 of #31840.