Ejemplo n.º 1
0
static int operator_button_property_finish(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
{
	ID *id = ptr->id.data;

	/* perform updates required for this property */
	RNA_property_update(C, ptr, prop);

	/* as if we pressed the button */
	uiContextActivePropertyHandle(C);

	/* Since we don't want to undo _all_ edits to settings, eg window
	 * edits on the screen or on operator settings.
	 * it might be better to move undo's inline - campbell */
	if (id && ID_CHECK_UNDO(id)) {
		/* do nothing, go ahead with undo */
		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}
Ejemplo n.º 2
0
static int reset_default_button_exec(bContext *C, wmOperator *op)
{
	PointerRNA ptr;
	PropertyRNA *prop;
	int success= 0;
	int index, all = RNA_boolean_get(op->ptr, "all");

	/* try to reset the nominated setting to its default value */
	uiContextActiveProperty(C, &ptr, &prop, &index);
	
	/* if there is a valid property that is editable... */
	if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
		if(RNA_property_reset(&ptr, prop, (all)? -1: index)) {
			/* perform updates required for this property */
			RNA_property_update(C, &ptr, prop);

			/* as if we pressed the button */
			uiContextActivePropertyHandle(C);

			success= 1;
		}
	}

	/* Since we dont want to undo _all_ edits to settings, eg window
	 * edits on the screen or on operator settings.
	 * it might be better to move undo's inline - campbell */
	if(success) {
		ID *id= ptr.id.data;
		if(id && ID_CHECK_UNDO(id)) {
			/* do nothing, go ahead with undo */
		}
		else {
			return OPERATOR_CANCELLED;
		}
	}
	/* end hack */

	return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
}