[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52641] trunk/blender/source/blender/ windowmanager/intern/wm_operators.c: Move to Layer: optimization so that the first change in the popup menu does

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Nov 28 17:42:39 CET 2012


Revision: 52641
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52641
Author:   blendix
Date:     2012-11-28 16:42:39 +0000 (Wed, 28 Nov 2012)
Log Message:
-----------
Move to Layer: optimization so that the first change in the popup menu does
not do an undo push & undo step, there's no reason this is needed.

In principle this particular operator doesn't ever need an undo on changes,
even for further steps, but that's harder to solve.

Modified Paths:
--------------
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-11-28 16:42:32 UTC (rev 52640)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-11-28 16:42:39 UTC (rev 52641)
@@ -1025,6 +1025,23 @@
 	return op;
 }
 
+static void wm_block_redo_cb(bContext *C, void *arg_op, int UNUSED(arg_event))
+{
+	wmOperator *op = arg_op;
+
+	if (op == WM_operator_last_redo(C)) {
+		/* operator was already executed once? undo & repeat */
+		ED_undo_operator_repeat(C, op);
+	}
+	else {
+		/* operator not executed yet, call it */
+		ED_undo_push_op(C, op);
+		wm_operator_register(C, op);
+
+		WM_operator_repeat(C, op);
+	}
+}
+
 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
 {
 	wmOperator *op = arg_op;
@@ -1032,7 +1049,6 @@
 	uiLayout *layout;
 	uiStyle *style = UI_GetStyle();
 	int width = 300;
-	
 
 	block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
 	uiBlockClearFlag(block, UI_BLOCK_LOOP);
@@ -1042,11 +1058,12 @@
 	 * ui_apply_but_funcs_after calls ED_undo_operator_repeate_cb and crashes */
 	assert(op->type->flag & OPTYPE_REGISTER);
 
-	uiBlockSetHandleFunc(block, ED_undo_operator_repeat_cb_evt, arg_op);
+	uiBlockSetHandleFunc(block, wm_block_redo_cb, arg_op);
 	layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, UI_UNIT_Y, style);
 
-	if (!WM_operator_check_ui_enabled(C, op->type->name))
-		uiLayoutSetEnabled(layout, FALSE);
+	if (op == WM_operator_last_redo(C))
+		if (!WM_operator_check_ui_enabled(C, op->type->name))
+			uiLayoutSetEnabled(layout, FALSE);
 
 	if (op->type->flag & OPTYPE_MACRO) {
 		for (op = op->macro.first; op; op = op->next) {
@@ -1058,7 +1075,6 @@
 		uiLayoutOperatorButs(C, layout, op, NULL, 'H', UI_LAYOUT_OP_SHOW_TITLE);
 	}
 	
-
 	uiPopupBoundsBlock(block, 4, 0, 0);
 	uiEndBlock(C, block);
 
@@ -1218,15 +1234,10 @@
 	if (!(U.uiflag & USER_GLOBALUNDO))
 		return WM_operator_props_dialog_popup(C, op, 300, UI_UNIT_Y);
 
-	ED_undo_push_op(C, op);
-
-	wm_operator_register(C, op);
-
 	uiPupBlock(C, wm_block_create_redo, op);
 
-	if (do_call) {
-		WM_operator_repeat(C, op);
-	}
+	if (do_call)
+		wm_block_redo_cb(C, op, 0);
 
 	return OPERATOR_RUNNING_MODAL;
 }




More information about the Bf-blender-cvs mailing list