summaryrefslogtreecommitdiffstats
path: root/equipment.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 /equipment.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 'equipment.c')
-rw-r--r--equipment.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/equipment.c b/equipment.c
index d676fc05d..89e95ef59 100644
--- a/equipment.c
+++ b/equipment.c
@@ -46,6 +46,7 @@ struct equipment_list {
static struct equipment_list cylinder_list[2], weightsystem_list[2];
+struct dive edit_dive;
struct cylinder_widget {
int index, changed;
@@ -1047,7 +1048,7 @@ static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore
ws_widget->weight = GTK_SPIN_BUTTON(widget);
}
-static int edit_cylinder_dialog(int index, cylinder_t *cyl)
+static int edit_cylinder_dialog(int index, cylinder_t *cyl, int w_idx)
{
int success;
GtkWidget *dialog, *vbox;
@@ -1057,7 +1058,10 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl)
cylinder.index = index;
cylinder.changed = 0;
- dive = current_dive;
+ if (w_idx == W_IDX_PRIMARY)
+ dive = current_dive;
+ else
+ dive = &edit_dive;
if (!dive)
return 0;
*cyl = dive->cylinder[index];
@@ -1079,9 +1083,11 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl)
if (success) {
record_cylinder_changes(cyl, &cylinder);
dive->cylinder[index] = *cyl;
- mark_divelist_changed(TRUE);
- update_cylinder_related_info(dive);
- flush_divelist(dive);
+ if (w_idx == W_IDX_PRIMARY) {
+ mark_divelist_changed(TRUE);
+ update_cylinder_related_info(dive);
+ flush_divelist(dive);
+ }
}
gtk_widget_destroy(dialog);
@@ -1089,7 +1095,7 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl)
return success;
}
-static int edit_weightsystem_dialog(int index, weightsystem_t *ws)
+static int edit_weightsystem_dialog(int index, weightsystem_t *ws, int w_idx)
{
int success;
GtkWidget *dialog, *vbox;
@@ -1099,7 +1105,10 @@ static int edit_weightsystem_dialog(int index, weightsystem_t *ws)
weightsystem_widget.index = index;
weightsystem_widget.changed = 0;
- dive = current_dive;
+ if (w_idx == W_IDX_PRIMARY)
+ dive = current_dive;
+ else
+ dive = &edit_dive;
if (!dive)
return 0;
*ws = dive->weightsystem[index];
@@ -1121,8 +1130,10 @@ static int edit_weightsystem_dialog(int index, weightsystem_t *ws)
if (success) {
record_weightsystem_changes(ws, &weightsystem_widget);
dive->weightsystem[index] = *ws;
- mark_divelist_changed(TRUE);
- flush_divelist(dive);
+ if (w_idx == W_IDX_PRIMARY) {
+ mark_divelist_changed(TRUE);
+ flush_divelist(dive);
+ }
}
gtk_widget_destroy(dialog);
@@ -1158,7 +1169,7 @@ static void edit_cb(GtkButton *button, int w_idx)
return;
index = get_model_index(model, &iter);
- if (!edit_cylinder_dialog(index, &cyl))
+ if (!edit_cylinder_dialog(index, &cyl, w_idx))
return;
set_one_cylinder(&cyl, model, &iter);
@@ -1174,7 +1185,7 @@ static void add_cb(GtkButton *button, int w_idx)
GtkTreeSelection *selection;
cylinder_t cyl;
- if (!edit_cylinder_dialog(index, &cyl))
+ if (!edit_cylinder_dialog(index, &cyl, w_idx))
return;
gtk_list_store_append(model, &iter);
@@ -1241,7 +1252,7 @@ static void ws_edit_cb(GtkButton *button, int w_idx)
return;
index = get_model_index(model, &iter);
- if (!edit_weightsystem_dialog(index, &ws))
+ if (!edit_weightsystem_dialog(index, &ws, w_idx))
return;
set_one_weightsystem(&ws, model, &iter);
@@ -1257,7 +1268,7 @@ static void ws_add_cb(GtkButton *button, int w_idx)
GtkTreeSelection *selection;
weightsystem_t ws;
- if (!edit_weightsystem_dialog(index, &ws))
+ if (!edit_weightsystem_dialog(index, &ws, w_idx))
return;
gtk_list_store_append(model, &iter);