diff options
Diffstat (limited to 'equipment.c')
-rw-r--r-- | equipment.c | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/equipment.c b/equipment.c index e81302c92..adfb02989 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; @@ -55,6 +56,7 @@ struct cylinder_widget { GtkSpinButton *size, *pressure; GtkWidget *start, *end, *pressure_button; GtkWidget *o2, *he, *gasmix_button; + int w_idx; }; struct ws_widget { @@ -63,6 +65,7 @@ struct ws_widget { GtkWidget *hbox; GtkComboBox *description; GtkSpinButton *weight; + int w_idx; }; /* we want bar - so let's not use our unit functions */ @@ -206,7 +209,14 @@ static void cylinder_cb(GtkComboBox *combo_box, gpointer data) GtkTreeModel *model = gtk_combo_box_get_model(combo_box); int ml, mbar; struct cylinder_widget *cylinder = data; - cylinder_t *cyl = current_dive->cylinder + cylinder->index; + struct dive *dive; + cylinder_t *cyl; + + if (cylinder->w_idx == W_IDX_PRIMARY) + dive = current_dive; + else + dive = &edit_dive; + cyl = dive->cylinder + cylinder->index; /* Did the user set it to some non-standard value? */ if (!get_active_item(combo_box, &iter, cylinder_model)) { @@ -244,7 +254,13 @@ static void weight_cb(GtkComboBox *combo_box, gpointer data) GtkTreeModel *model = gtk_combo_box_get_model(combo_box); int weight; struct ws_widget *ws_widget = data; - weightsystem_t *ws = current_dive->weightsystem + ws_widget->index; + struct dive *dive; + weightsystem_t *ws; + if (ws_widget->w_idx == W_IDX_PRIMARY) + dive = current_dive; + else + dive = &edit_dive; + ws = dive->weightsystem + ws_widget->index; /* Did the user set it to some non-standard value? */ if (!get_active_item(combo_box, &iter, weightsystem_model)) { @@ -1047,7 +1063,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; @@ -1055,9 +1071,13 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl) struct dive *dive; cylinder.index = index; + cylinder.w_idx = w_idx; 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 +1099,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 +1111,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; @@ -1097,9 +1119,13 @@ static int edit_weightsystem_dialog(int index, weightsystem_t *ws) struct dive *dive; weightsystem_widget.index = index; + weightsystem_widget.w_idx = w_idx; 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 +1147,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 +1186,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 +1202,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); @@ -1205,7 +1233,10 @@ static void del_cb(GtkButton *button, int w_idx) index = get_model_index(model, &iter); - dive = current_dive; + if (w_idx == W_IDX_PRIMARY) + dive = current_dive; + else + dive = &edit_dive; if (!dive) return; cyl = dive->cylinder + index; @@ -1241,7 +1272,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 +1288,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); @@ -1288,7 +1319,10 @@ static void ws_del_cb(GtkButton *button, int w_idx) index = get_model_index(model, &iter); - dive = current_dive; + if (w_idx == W_IDX_PRIMARY) + dive = current_dive; + else + dive = &edit_dive; if (!dive) return; ws = dive->weightsystem + index; |