summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-11 13:37:06 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-11 13:37:06 -0700
commit41d3a11ee3d793e7a20a85baf66c18b3dca431a4 (patch)
tree3ed1fd27093cd1aaf63a044d1908c37e9cbd2e4b /info.c
parent0fceb1c9070eb2b1c65f26e665d49ee54cc4e17e (diff)
downloadsubsurface-41d3a11ee3d793e7a20a85baf66c18b3dca431a4.tar.gz
Fix a long standing bug when editing dives
Calling edit from the context menu creates a combined editing widget that contains both dive info and equipment. When editing cylinders or weightsystems from that widget and confirming those edits with OK those changes were already committed to the current_dive - regardless on which dive the user clicked. Worse, even when the user clicked Cancel in the edit widget, any changes to the equipment stayed in effect. This had especially confusing consequences when editing multiple dives. As a workaround this commit adds a global edit_dive variable. This fake dive is edited by the secondary editing widgets and if the user accepts changes with OK then they are copied over to the current dive (or all selected dives in multi dive editing mode). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'info.c')
-rw-r--r--info.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/info.c b/info.c
index 3efb40cf8..e9cd3c812 100644
--- a/info.c
+++ b/info.c
@@ -481,7 +481,7 @@ static weightsystem_t remember_ws[MAX_WEIGHTSYSTEMS];
#define CYL_BYTES sizeof(cylinder_t) * MAX_CYLINDERS
#define WS_BYTES sizeof(weightsystem_t) * MAX_WEIGHTSYSTEMS
-void save_equipment_data(struct dive *dive)
+static void save_equipment_data(struct dive *dive)
{
if (dive) {
memcpy(remember_cyl, dive->cylinder, CYL_BYTES);
@@ -583,13 +583,19 @@ int edit_multi_dive_info(struct dive *single_dive)
}
}
}
-
- dive_info_widget(vbox, master, &info, multi);
- show_dive_equipment(master, W_IDX_SECONDARY);
- save_equipment_data(master);
+ /* edit a temporary copy of the master dive;
+ * edit_dive is a global dive structure that is modified by the
+ * cylinder / weightsystem dialogs if we open W_IDX_SECONDARY
+ * edit widgets as we do here */
+ memcpy(&edit_dive, master, sizeof(struct dive));
+
+ dive_info_widget(vbox, &edit_dive, &info, multi);
+ show_dive_equipment(&edit_dive, W_IDX_SECONDARY);
+ save_equipment_data(&edit_dive);
gtk_widget_show_all(dialog);
success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
if (success) {
+ mark_divelist_changed(TRUE);
/* Update the non-current selected dives first */
if (!single_dive) {
int i;
@@ -599,19 +605,23 @@ int edit_multi_dive_info(struct dive *single_dive)
if (dive == master || !dive->selected)
continue;
/* copy all "info" fields */
- save_dive_info_changes(dive, master, &info);
+ save_dive_info_changes(dive, &edit_dive, &info);
/* copy the cylinders / weightsystems */
- update_equipment_data(dive, master);
+ update_equipment_data(dive, &edit_dive);
/* this is extremely inefficient... it loops through all
dives to find the right one - but we KNOW the index already */
+ update_cylinder_related_info(dive);
flush_divelist(dive);
}
}
/* Update the master dive last! */
- save_dive_info_changes(master, master, &info);
- update_equipment_data(master, master);
+ save_dive_info_changes(master, &edit_dive, &info);
+ update_equipment_data(master, &edit_dive);
+ update_cylinder_related_info(master);
flush_divelist(master);
+ process_selected_dives();
+ update_dive(master);
}
gtk_widget_destroy(dialog);