Cleanup/refactor: UndoType: Clarify `use_context` variable.
Rename it to mark it is only for `encode` callbacks, fix `encode` callback of text undo to early fail in case it gets a NULL context, add an assert to `BKE_undosys_step_push_with_type` that context is not NULL when undotype requires a valid one. Note that in practice this should not change anything, currently it seems that we always get a valid context in `BKE_undosys_step_push_with_type`?
This commit is contained in:
parent
4e23f08807
commit
bc3e38ca3a
|
@ -140,7 +140,11 @@ typedef struct UndoType {
|
|||
UndoTypeForEachIDRefFn foreach_ID_ref_fn,
|
||||
void *user_data);
|
||||
|
||||
bool use_context;
|
||||
/**
|
||||
* This undo type `encode` callback needs a valid context, it will fail otherwise.
|
||||
* \note Callback is still supposed to properly deal with a NULL context pointer.
|
||||
*/
|
||||
bool use_context_for_encode;
|
||||
|
||||
/**
|
||||
* The size of the undo struct 'inherited' from #UndoStep for that specific type. Used for
|
||||
|
|
|
@ -501,6 +501,8 @@ UndoPushReturn BKE_undosys_step_push_with_type(UndoStack *ustack,
|
|||
const char *name,
|
||||
const UndoType *ut)
|
||||
{
|
||||
BLI_assert(ut->use_context_for_encode == false || C != NULL);
|
||||
|
||||
UNDO_NESTED_ASSERT(false);
|
||||
undosys_stack_validate(ustack, false);
|
||||
bool is_not_empty = ustack->step_active != NULL;
|
||||
|
|
|
@ -249,7 +249,7 @@ void ED_armature_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = armature_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(ArmatureUndoStep);
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ void ED_curve_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = curve_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(CurveUndoStep);
|
||||
}
|
||||
|
|
|
@ -398,7 +398,7 @@ void ED_font_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = font_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(FontUndoStep);
|
||||
}
|
||||
|
|
|
@ -283,7 +283,7 @@ void ED_lattice_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = lattice_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(LatticeUndoStep);
|
||||
}
|
||||
|
|
|
@ -819,7 +819,7 @@ void ED_mesh_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = mesh_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(MeshUndoStep);
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ void ED_mball_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = mball_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(MBallUndoStep);
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ void ED_particle_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = particle_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(ParticleUndoStep);
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ void ED_paintcurve_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = paintcurve_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = false;
|
||||
ut->use_context_for_encode = false;
|
||||
|
||||
ut->step_size = sizeof(PaintCurveUndoStep);
|
||||
}
|
||||
|
|
|
@ -1576,7 +1576,7 @@ void ED_sculpt_undosys_type(UndoType *ut)
|
|||
ut->step_decode = sculpt_undosys_step_decode;
|
||||
ut->step_free = sculpt_undosys_step_free;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(SculptUndoStep);
|
||||
}
|
||||
|
|
|
@ -995,7 +995,7 @@ void ED_image_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = image_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(ImageUndoStep);
|
||||
}
|
||||
|
|
|
@ -183,11 +183,14 @@ static bool text_undosys_step_encode(struct bContext *C,
|
|||
struct Main *UNUSED(bmain),
|
||||
UndoStep *us_p)
|
||||
{
|
||||
if (C == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TextUndoStep *us = (TextUndoStep *)us_p;
|
||||
|
||||
Text *text = us->text_ref.ptr;
|
||||
BLI_assert(text == CTX_data_edit_text(C));
|
||||
UNUSED_VARS_NDEBUG(C);
|
||||
|
||||
us->step.data_size += text_undosys_step_encode_to_state(&us->states[1], text);
|
||||
|
||||
|
@ -260,7 +263,7 @@ void ED_text_undosys_type(UndoType *ut)
|
|||
|
||||
ut->step_foreach_ID_ref = text_undosys_foreach_ID_ref;
|
||||
|
||||
ut->use_context = false;
|
||||
ut->use_context_for_encode = false;
|
||||
|
||||
ut->step_size = sizeof(TextUndoStep);
|
||||
}
|
||||
|
|
|
@ -282,7 +282,7 @@ void ED_memfile_undosys_type(UndoType *ut)
|
|||
ut->step_decode = memfile_undosys_step_decode;
|
||||
ut->step_free = memfile_undosys_step_free;
|
||||
|
||||
ut->use_context = true;
|
||||
ut->use_context_for_encode = true;
|
||||
|
||||
ut->step_size = sizeof(MemFileUndoStep);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue