+ widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+ gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
+
+ cylinder->description = GTK_COMBO_BOX(widget);
+ g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
+
+ entry = GTK_ENTRY(GTK_BIN(widget)->child);
+ g_signal_connect(entry, "activate", G_CALLBACK(cylinder_activate_cb), cylinder);
+
+ completion = gtk_entry_completion_new();
+ gtk_entry_completion_set_text_column(completion, 0);
+ gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
+ g_signal_connect(completion, "match-selected", G_CALLBACK(completion_cb), cylinder);
+ gtk_entry_set_completion(entry, completion);
+
+ hbox = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
+
+ widget = create_spinbutton(hbox, "Size", 0, 300, 0.1);
+ cylinder->size = GTK_SPIN_BUTTON(widget);
+
+ widget = create_spinbutton(hbox, "Pressure", 0, 5000, 1);
+ cylinder->pressure = GTK_SPIN_BUTTON(widget);
+
+ /*
+ * Cylinder start/end pressures
+ */
+ hbox = frame_box("Pressure", vbox);
+
+ widget = labeled_spinbutton(hbox, "Start", 0, 5000, 1);
+ cylinder->start = widget;
+
+ widget = labeled_spinbutton(hbox, "End", 0, 5000, 1);
+ cylinder->end = widget;
+
+ 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(&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;