mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 00:43:24 +00:00
Fix two bugs with the gas entry code in the dive planner
First, I forgot to pass in the idx into the gas callback function - this way for the dynamically created dives we always used air for anything but the first segment. Second, when selecting a gas from the drop down (with the mouse or by typing), the GtkEntry doesn't receive that text and therfore we never picked up those gases. We now also track the 'changed' event for the GtkComboBox, but never add the text we get their to the completions (as by definition they are already there). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
d396f4afd8
commit
e6afd055d8
1 changed files with 23 additions and 5 deletions
28
planner.c
28
planner.c
|
@ -559,6 +559,24 @@ static gboolean gas_focus_out_cb(GtkWidget *entry, GdkEvent *event, gpointer dat
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void gas_changed_cb(GtkWidget *combo, gpointer data)
|
||||
{
|
||||
char *gastext;
|
||||
int o2, he;
|
||||
int idx = data - NULL;
|
||||
|
||||
gastext = strdup(gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo)));
|
||||
if (validate_gas(gastext, &o2, &he)) {
|
||||
add_gas_to_nth_dp(&diveplan, idx, o2, he);
|
||||
show_planned_dive();
|
||||
} else {
|
||||
/* this should never happen as only validated texts should be
|
||||
* in the dropdown */
|
||||
printf("invalid gas for row %d\n",idx);
|
||||
}
|
||||
free(gastext);
|
||||
}
|
||||
|
||||
static gboolean depth_focus_out_cb(GtkWidget *entry, GdkEvent *event, gpointer data)
|
||||
{
|
||||
char *depthtext;
|
||||
|
@ -612,7 +630,7 @@ static gboolean starttime_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpoin
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label)
|
||||
static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label, int idx)
|
||||
{
|
||||
GtkWidget *frame, *combo;
|
||||
GtkEntryCompletion *completion;
|
||||
|
@ -626,8 +644,8 @@ static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label)
|
|||
}
|
||||
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(gtk_bin_get_child(GTK_BIN(combo)), "focus-out-event", G_CALLBACK(gas_focus_out_cb), NULL);
|
||||
|
||||
g_signal_connect(gtk_bin_get_child(GTK_BIN(combo)), "focus-out-event", G_CALLBACK(gas_focus_out_cb), NULL + idx);
|
||||
g_signal_connect(combo, "changed", G_CALLBACK(gas_changed_cb), NULL + idx);
|
||||
if (label) {
|
||||
frame = gtk_frame_new(label);
|
||||
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
|
||||
|
@ -657,11 +675,11 @@ static void add_waypoint_widgets(GtkWidget *box, int idx)
|
|||
if (idx == 0) {
|
||||
entry_depth[idx] = add_entry_to_box(hbox, _("Ending Depth"));
|
||||
entry_duration[idx] = add_entry_to_box(hbox, _("Segment Time"));
|
||||
entry_gas[idx] = add_gas_combobox_to_box(hbox, _("Gas Used"));
|
||||
entry_gas[idx] = add_gas_combobox_to_box(hbox, _("Gas Used"), idx);
|
||||
} else {
|
||||
entry_depth[idx] = add_entry_to_box(hbox, NULL);
|
||||
entry_duration[idx] = add_entry_to_box(hbox, NULL);
|
||||
entry_gas[idx] = add_gas_combobox_to_box(hbox, NULL);
|
||||
entry_gas[idx] = add_gas_combobox_to_box(hbox, NULL, idx);
|
||||
}
|
||||
gtk_widget_add_events(entry_depth[idx], GDK_FOCUS_CHANGE_MASK);
|
||||
g_signal_connect(entry_depth[idx], "focus-out-event", G_CALLBACK(depth_focus_out_cb), NULL + idx);
|
||||
|
|
Loading…
Add table
Reference in a new issue