From 69470e36d6b17042260b06f26ca3c2f702747324 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 15 Nov 2016 11:50:11 +0100 Subject: Implement grouped undo option for operators This option makes an operator to not push a task to the undo stack if the previous stored elemen is the same operator or part of the same undo group. The main usage is for animation, so you can change frames to inspect the poses, and revert the previous pose without having to roll back tons of "change frame" operator, or even see the undo stack full. This complements rB13ee9b8e Design with help by Sergey Sharybin. Reviewers: sergey, mont29 Reviewed By: mont29, sergey Subscribers: pyc0d3r, hjalti, Severin, lowercase, brecht, monio, aligorith, hadrien, jbakker Differential Revision: https://developer.blender.org/D2330 --- source/blender/editors/util/undo.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index ee6700666c0..4a9311416b3 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -217,6 +217,19 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) return OPERATOR_FINISHED; } +void ED_undo_grouped_push(bContext *C, const char *str) +{ + /* do nothing if previous undo task is the same as this one (or from the same undo group) */ + const char *last_undo = BKE_undo_get_name_last(); + + if (last_undo && STREQ(str, last_undo)) { + return; + } + + /* push as usual */ + ED_undo_push(C, str); +} + void ED_undo_pop(bContext *C) { ed_undo_step(C, 1, NULL); @@ -232,6 +245,16 @@ void ED_undo_push_op(bContext *C, wmOperator *op) ED_undo_push(C, op->type->name); } +void ED_undo_grouped_push_op(bContext *C, wmOperator *op) +{ + if (op->type->undo_group[0] != '\0') { + ED_undo_grouped_push(C, op->type->undo_group); + } + else { + ED_undo_grouped_push(C, op->type->name); + } +} + void ED_undo_pop_op(bContext *C, wmOperator *op) { /* search back a couple of undo's, in case something else added pushes */ -- cgit v1.2.3