Exemplo n.º 1
0
static int undo_stack_step(bContext *C, UndoStack *stack, int step, const char *name)
{
	UndoElem *undo;

	if(step==1) {
		if(stack->current==NULL);
		else {
			if(!name || strcmp(stack->current->name, name) == 0) {
				if(G.f & G_DEBUG) printf("undo %s\n", stack->current->name);
				undo_restore(C, stack, stack->current);
				stack->current= stack->current->prev;
				return 1;
			}
		}
	}
	else if(step==-1) {
		if((stack->current!=NULL && stack->current->next==NULL) || stack->elems.first==NULL);
		else {
			if(!name || strcmp(stack->current->name, name) == 0) {
				undo= (stack->current && stack->current->next)? stack->current->next: stack->elems.first;
				undo_restore(C, stack, undo);
				stack->current= undo;
				if(G.f & G_DEBUG) printf("redo %s\n", undo->name);
				return 1;
			}
		}
	}

	return 0;
}
Exemplo n.º 2
0
/* 1 = an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */
void undo_editmode_step(bContext *C, int step)
{
	Object *obedit = CTX_data_edit_object(C);
	
	/* prevent undo to happen on wrong object, stack can be a mix */
	undo_clean_stack(C);
	
	if (step == 0) {
		undo_restore(curundo, curundo->getdata(C), obedit->data);
	}
	else if (step == 1) {
		
		if (curundo == NULL || curundo->prev == NULL) {
			error("No more steps to undo");
		}
		else {
			if (G.debug & G_DEBUG) printf("undo %s\n", curundo->name);
			curundo = curundo->prev;
			undo_restore(curundo, curundo->getdata(C), obedit->data);
		}
	}
	else {
		/* curundo has to remain current situation! */
		
		if (curundo == NULL || curundo->next == NULL) {
			error("No more steps to redo");
		}
		else {
			undo_restore(curundo->next, curundo->getdata(C), obedit->data);
			curundo = curundo->next;
			if (G.debug & G_DEBUG) printf("redo %s\n", curundo->name);
		}
	}
	
	/* special case for editmesh, mode must be copied back to the scene */
	if (obedit->type == OB_MESH) {
		EDBM_selectmode_to_scene(C);
	}

	DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);

	/* XXX notifiers */
}
Exemplo n.º 3
0
static int undo_stack_step(bContext *C, UndoStack *stack, int step, const char *name)
{
	UndoElem *undo;

	if (step == 1) {
		if (stack->current == NULL) {
			/* pass */
		}
		else {
			if (!name || strcmp(stack->current->name, name) == 0) {
				if (G.debug & G_DEBUG_WM) {
					printf("%s: undo '%s'\n", __func__, stack->current->name);
				}
				undo_restore(C, stack, stack->current);
				stack->current = stack->current->prev;
				return 1;
			}
		}
	}
	else if (step == -1) {
		if ((stack->current != NULL && stack->current->next == NULL) || stack->elems.first == NULL) {
			/* pass */
		}
		else {
			if (!name || strcmp(stack->current->name, name) == 0) {
				undo = (stack->current && stack->current->next) ? stack->current->next : stack->elems.first;
				undo_restore(C, stack, undo);
				stack->current = undo;
				if (G.debug & G_DEBUG_WM) {
					printf("%s: redo %s\n", __func__, undo->name);
				}
				return 1;
			}
		}
	}

	return 0;
}