From 6ce4d29f4907ec26486d9a16fee29edf1637b543 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 18 Feb 2013 16:56:28 -0800 Subject: [PATCH] Clear statistics and equipment when no dive is selected This all seems very strange forward. The reason for the check whether the stats_w widget has been populated is that at the very beginning, when the UI is still being assembled, a first call to switch_page() happens as the notebook pages are assembled. At that point the stats_w widget is still empty which tells us that we aren't ready to display anything. Signed-off-by: Dirk Hohndel --- equipment.c | 1 + main.c | 6 ++---- statistics.c | 8 +++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/equipment.c b/equipment.c index f28050949..f0a9df478 100644 --- a/equipment.c +++ b/equipment.c @@ -573,6 +573,7 @@ static void show_equipment(struct dive *dive, int max, gtk_widget_set_sensitive(equipment_list->edit, 0); gtk_widget_set_sensitive(equipment_list->del, 0); gtk_widget_set_sensitive(equipment_list->add, 0); + clear_equipment_widgets(); return; } gtk_list_store_clear(model); diff --git a/main.c b/main.c index 1ddcb3b64..fd5c78e82 100644 --- a/main.c +++ b/main.c @@ -247,10 +247,8 @@ void update_dive(struct dive *new_dive) flush_divelist(old_dive); } show_dive_info(new_dive); - if (new_dive) { - show_dive_equipment(new_dive, W_IDX_PRIMARY); - show_dive_stats(new_dive); - } + show_dive_equipment(new_dive, W_IDX_PRIMARY); + show_dive_stats(new_dive); buffered_dive = new_dive; } diff --git a/statistics.c b/statistics.c index fdea8bdba..73c771804 100644 --- a/statistics.c +++ b/statistics.c @@ -439,7 +439,7 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive) * are in chronological order */ for (idx = 0; idx < dive_table.nr; idx++) { dp = dive_table.dives[idx]; - if (dp->when == dive->when) { + if (dive && dp->when == dive->when) { /* that's the one we are showing */ if (idx > 0) *prev_dive = dive_table.dives[idx-1]; @@ -699,7 +699,7 @@ static void get_selected_dives_text(char *buffer, int size) } } -static void show_total_dive_stats(struct dive *dive) +static void show_total_dive_stats(void) { double value; int decimals, seconds; @@ -707,6 +707,8 @@ static void show_total_dive_stats(struct dive *dive) char buffer[60]; stats_t *stats_ptr; + if (!stats_w.framelabel) + return; stats_ptr = &stats_selection; get_selected_dives_text(buffer, sizeof(buffer)); @@ -752,7 +754,7 @@ void show_dive_stats(struct dive *dive) /* they have to be called in this order, as 'total' depends on * calculations done in 'single' */ show_single_dive_stats(dive); - show_total_dive_stats(dive); + show_total_dive_stats(); } static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label)