From 72c6b838662f1fb79a806ac2264c7215efa0aa67 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 8 Nov 2019 22:47:38 +0100 Subject: Undo: make weight editing undoable Implement the EditWeight undo command. Since there is common code (storage of the old weight), this creates a common base class for RemoveWeight and EditWeight. The model calls directly into the undo command, which is somewhat unfortunate as it feels like a layering violation. It's the easy thing to do for now. Signed-off-by: Berthold Stoeger --- core/equipment.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core/equipment.c') diff --git a/core/equipment.c b/core/equipment.c index e7ac327fd..07e468c1c 100644 --- a/core/equipment.c +++ b/core/equipment.c @@ -288,6 +288,15 @@ void remove_weightsystem(struct dive *dive, int idx) remove_from_weightsystem_table(&dive->weightsystems, idx); } +// ws is cloned. +void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws) +{ + if (idx < 0 || idx >= dive->weightsystems.nr) + return; + free_weightsystem(dive->weightsystems.weightsystems[idx]); + dive->weightsystems.weightsystems[idx] = clone_weightsystem(ws); +} + /* when planning a dive we need to make sure that all cylinders have a sane depth assigned * and if we are tracking gas consumption the pressures need to be reset to start = end = workingpressure */ void reset_cylinders(struct dive *dive, bool track_gas) -- cgit v1.2.3-70-g09d2