mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Add new gases to the combo box in dive plan entry
Once again Gtk does everything it can to make our lives miserable. It requires major hackery to be able to add new gases to the drop down lists "on the fly". Right now this only works if you edit the gas and then use Tab to move to the next field. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b1dc9bf26d
commit
b08f51cfc6
3 changed files with 29 additions and 11 deletions
|
@ -95,6 +95,7 @@ extern void update_progressbar(progressbar_t *progress, double value);
|
|||
extern void update_progressbar_text(progressbar_t *progress, const char *text);
|
||||
|
||||
extern GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h, GtkWidget **m);
|
||||
extern void add_string_list_entry(const char *string, GtkListStore *list);
|
||||
|
||||
extern GtkWidget *dive_profile_widget(void);
|
||||
extern GtkWidget *dive_info_frame(void);
|
||||
|
|
37
gtk-gui.c
37
gtk-gui.c
|
@ -1470,12 +1470,27 @@ static GtkWidget *add_entry_to_box(GtkWidget *box, const char *label)
|
|||
#define MAX_WAYPOINTS 8
|
||||
GtkWidget *entry_depth[MAX_WAYPOINTS], *entry_duration[MAX_WAYPOINTS], *entry_gas[MAX_WAYPOINTS];
|
||||
int nr_waypoints = 0;
|
||||
static GtkListStore *gas_model = NULL;
|
||||
|
||||
static gboolean gas_changed_cb(GtkComboBox *combo, GdkEventKey *event, gpointer data)
|
||||
{
|
||||
char *gastext;
|
||||
int o2, he;
|
||||
GtkWidget *entry;
|
||||
|
||||
if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Tab) {
|
||||
entry = gtk_bin_get_child(GTK_BIN(combo));
|
||||
gastext = strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
|
||||
if (validate_gas(gastext, &o2, &he))
|
||||
add_string_list_entry(gastext, gas_model);
|
||||
free(gastext);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label)
|
||||
{
|
||||
static GtkListStore *gas_model = NULL;
|
||||
GtkWidget *frame, *combo;
|
||||
GtkTreeIter iter;
|
||||
GtkEntryCompletion *completion;
|
||||
GtkEntry *entry;
|
||||
|
||||
|
@ -1484,14 +1499,14 @@ static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label)
|
|||
|
||||
if (!gas_model) {
|
||||
gas_model = gtk_list_store_new(1, G_TYPE_STRING);
|
||||
gtk_list_store_append(gas_model, &iter);
|
||||
gtk_list_store_set(gas_model, &iter, 0, "air", -1);
|
||||
gtk_list_store_append(gas_model, &iter);
|
||||
gtk_list_store_set(gas_model, &iter, 0, "EAN32", -1);
|
||||
gtk_list_store_append(gas_model, &iter);
|
||||
gtk_list_store_set(gas_model, &iter, 0, "EAN36 @ 1.6", -1);
|
||||
add_string_list_entry("AIR", gas_model);
|
||||
add_string_list_entry("EAN32", gas_model);
|
||||
add_string_list_entry("EAN36 @ 1.6", gas_model);
|
||||
}
|
||||
combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(gas_model), 0);
|
||||
gtk_widget_add_events(combo, GDK_FOCUS_CHANGE_MASK);
|
||||
g_signal_connect(G_OBJECT(combo), "event", G_CALLBACK(gas_changed_cb), NULL);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(frame), combo);
|
||||
entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo)));
|
||||
|
||||
|
@ -1588,13 +1603,15 @@ void input_plan()
|
|||
duration -= lasttime;
|
||||
entry = gtk_bin_get_child(GTK_BIN(entry_gas[i]));
|
||||
gastext = strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
|
||||
// still need to add pO2
|
||||
if (!validate_gas(gastext, &o2, &he)) {
|
||||
// mark error and redo?
|
||||
free(gastext);
|
||||
continue;
|
||||
}
|
||||
// still need to add pO2
|
||||
/* just in case this didn't get added by the callback */
|
||||
add_string_list_entry(gastext, gas_model);
|
||||
|
||||
// still need to handle desired pO2 and a setpoint (for CC)
|
||||
|
||||
if (duration == 0)
|
||||
break;
|
||||
|
|
2
info.c
2
info.c
|
@ -352,7 +352,7 @@ static int match_list(GtkListStore *list, const char *string)
|
|||
return found_string_entry;
|
||||
}
|
||||
|
||||
static void add_string_list_entry(const char *string, GtkListStore *list)
|
||||
void add_string_list_entry(const char *string, GtkListStore *list)
|
||||
{
|
||||
GtkTreeIter *iter, loc;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue