+ cylinder->pressure_button = gtk_check_button_new();
+ gtk_box_pack_start(GTK_BOX(hbox), cylinder->pressure_button, FALSE, FALSE, 3);
+ g_signal_connect(cylinder->pressure_button, "toggled", G_CALLBACK(pressure_cb), cylinder);
+
+ /*
+ * Cylinder gas mix: Air, Nitrox or Trimix
+ */
+ hbox = frame_box("Gasmix", vbox);
+
+ widget = labeled_spinbutton(hbox, "O"UTF8_SUBSCRIPT_2 "%", 1, 100, 0.1);
+ cylinder->o2 = widget;
+ widget = labeled_spinbutton(hbox, "He%", 0, 100, 0.1);
+ cylinder->he = widget;
+ cylinder->gasmix_button = gtk_check_button_new();
+ gtk_box_pack_start(GTK_BOX(hbox), cylinder->gasmix_button, FALSE, FALSE, 3);
+ g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(gasmix_cb), cylinder);
+}
+
+static int edit_cylinder_dialog(int index, cylinder_t *cyl)
+{
+ int success;
+ GtkWidget *dialog, *vbox;
+ struct cylinder_widget cylinder;
+ struct dive *dive;
+
+ cylinder.index = index;
+ cylinder.changed = 0;
+
+ dive = current_dive;
+ if (!dive)
+ return 0;
+ *cyl = dive->cylinder[index];
+
+ dialog = gtk_dialog_new_with_buttons("Cylinder",
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ NULL);
+
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ cylinder_widget(vbox, &cylinder, cylinder_model);
+
+ show_cylinder(cyl, &cylinder);
+
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (success) {
+ record_cylinder_changes(cyl, &cylinder);
+ dive->cylinder[index] = *cyl;
+ mark_divelist_changed(TRUE);
+ update_cylinder_related_info(dive);
+ flush_divelist(dive);
+ }
+
+ gtk_widget_destroy(dialog);
+
+ return success;
+}
+
+static int get_model_index(GtkListStore *model, GtkTreeIter *iter)
+{
+ int *p, index;
+ GtkTreePath *path;
+
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), iter);
+ p = gtk_tree_path_get_indices(path);
+ index = p ? *p : 0;
+ gtk_tree_path_free(path);
+ return index;
+}
+
+static void edit_cb(GtkButton *button, GtkTreeView *tree_view)
+{
+ int index;
+ GtkTreeIter iter;
+ GtkListStore *model = cylinder_list.model;
+ GtkTreeSelection *selection;
+ cylinder_t cyl;
+
+ selection = gtk_tree_view_get_selection(tree_view);
+
+ /* Nothing selected? This shouldn't happen, since the button should be inactive */
+ if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
+ return;
+
+ index = get_model_index(model, &iter);
+ if (!edit_cylinder_dialog(index, &cyl))
+ return;
+
+ set_one_cylinder(index, &cyl, model, &iter);
+ repaint_dive();
+}
+
+static void add_cb(GtkButton *button, GtkTreeView *tree_view)
+{
+ int index = cylinder_list.max_index;
+ GtkTreeIter iter;
+ GtkListStore *model = cylinder_list.model;
+ GtkTreeSelection *selection;
+ cylinder_t cyl;
+
+ if (!edit_cylinder_dialog(index, &cyl))
+ return;
+
+ gtk_list_store_append(model, &iter);
+ set_one_cylinder(index, &cyl, model, &iter);
+
+ selection = gtk_tree_view_get_selection(tree_view);
+ gtk_tree_selection_select_iter(selection, &iter);
+
+ cylinder_list.max_index++;
+ gtk_widget_set_sensitive(cylinder_list.add, cylinder_list.max_index < MAX_CYLINDERS);
+}
+
+static void del_cb(GtkButton *button, GtkTreeView *tree_view)
+{
+ int index, nr;
+ GtkTreeIter iter;
+ GtkListStore *model = cylinder_list.model;
+ GtkTreeSelection *selection;
+ struct dive *dive;
+ cylinder_t *cyl;
+
+ selection = gtk_tree_view_get_selection(tree_view);
+
+ /* Nothing selected? This shouldn't happen, since the button should be inactive */
+ if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
+ return;
+
+ index = get_model_index(model, &iter);
+
+ dive = current_dive;
+ if (!dive)
+ return;
+ cyl = dive->cylinder + index;
+ nr = cylinder_list.max_index - index - 1;
+
+ gtk_list_store_remove(model, &iter);
+
+ cylinder_list.max_index--;
+ memmove(cyl, cyl+1, nr*sizeof(*cyl));
+ memset(cyl+nr, 0, sizeof(*cyl));
+
+ mark_divelist_changed(TRUE);
+ flush_divelist(dive);
+
+ gtk_widget_set_sensitive(cylinder_list.edit, 0);
+ gtk_widget_set_sensitive(cylinder_list.del, 0);
+ gtk_widget_set_sensitive(cylinder_list.add, 1);