summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-10 14:32:55 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-10 14:32:55 -0700
commita8fd77865c3e3e0a547b8e06a047c44732fe92f2 (patch)
treeed7c615537b766a7c3376937df3fe9060b9a5454
parent78c5aa9f071ab56e56bf760e3e7fc7f0f0d1b1ff (diff)
downloadsubsurface-a8fd77865c3e3e0a547b8e06a047c44732fe92f2.tar.gz
Implement Close menu option that allows closing the data file
This requires some helper routines that allow us to clear out all the widgets. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h2
-rw-r--r--equipment.c6
-rw-r--r--gtk-gui.c37
-rw-r--r--info.c11
-rw-r--r--statistics.c29
5 files changed, 83 insertions, 2 deletions
diff --git a/dive.h b/dive.h
index af141bbde..227de387c 100644
--- a/dive.h
+++ b/dive.h
@@ -390,8 +390,10 @@ extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
extern void show_dive_info(struct dive *);
extern void show_dive_equipment(struct dive *, int w_idx);
+extern void clear_equipment_widgets(void);
extern void show_dive_stats(struct dive *);
+extern void clear_stats_widgets(void);
extern void update_dive(struct dive *new_dive);
extern void save_dives(const char *filename);
diff --git a/equipment.c b/equipment.c
index d676fc05d..e81302c92 100644
--- a/equipment.c
+++ b/equipment.c
@@ -1612,3 +1612,9 @@ GtkWidget *equipment_widget(int w_idx)
return vbox;
}
+
+void clear_equipment_widgets()
+{
+ gtk_list_store_clear(cylinder_list[W_IDX_PRIMARY].model);
+ gtk_list_store_clear(weightsystem_list[W_IDX_PRIMARY].model);
+}
diff --git a/gtk-gui.c b/gtk-gui.c
index 6666f5560..a6a124fde 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -277,11 +277,11 @@ static gboolean ask_save_changes()
if (!existing_filename){
label = gtk_label_new (
- "You have unsaved changes\nWould you like to save those before exiting the program?");
+ "You have unsaved changes\nWould you like to save those before closing the datafile?");
} else {
char *label_text = (char*) malloc(sizeof(char) * (93 + strlen(existing_filename)));
sprintf(label_text,
- "You have unsaved changes to file: %s \nWould you like to save those before exiting the program?",
+ "You have unsaved changes to file: %s \nWould you like to save those before closing the datafile?",
existing_filename);
label = gtk_label_new (label_text);
g_free(label_text);
@@ -299,6 +299,37 @@ static gboolean ask_save_changes()
return quit;
}
+static void file_close(GtkWidget *w, gpointer data)
+{
+ int i;
+
+ if (unsaved_changes())
+ if (ask_save_changes() == FALSE)
+ return;
+ existing_filename = NULL;
+
+ /* free the dives and trips */
+ for (i = 0; i < dive_table.nr; i++)
+ free(get_dive(i));
+ dive_table.nr = 0;
+ dive_table.preexisting = 0;
+ g_list_free_full(dive_trip_list, free);
+ dive_trip_list = NULL;
+
+ /* clear the selection and the statistics */
+ amount_selected = 0;
+ selected_dive = 0;
+ process_selected_dives();
+ clear_stats_widgets();
+
+ /* clear the equipment page */
+ clear_equipment_widgets();
+
+ /* redraw the screen */
+ dive_list_update_dives();
+ show_dive_info(NULL);
+}
+
static gboolean on_delete(GtkWidget* w, gpointer data)
{
/* Make sure to flush any modified dive data */
@@ -842,6 +873,7 @@ static GtkActionEntry menu_items[] = {
{ "OpenFile", GTK_STOCK_OPEN, NULL, CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
{ "SaveFile", GTK_STOCK_SAVE, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
{ "SaveAsFile", GTK_STOCK_SAVE_AS, NULL, SHIFTCHAR CTRLCHAR "S", NULL, G_CALLBACK(file_save_as) },
+ { "CloseFile", GTK_STOCK_CLOSE, NULL, NULL, NULL, G_CALLBACK(file_close) },
{ "Print", GTK_STOCK_PRINT, NULL, CTRLCHAR "P", NULL, G_CALLBACK(do_print) },
{ "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
{ "AddDive", GTK_STOCK_ADD, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) },
@@ -870,6 +902,7 @@ static const gchar* ui_string = " \
<menuitem name=\"Open\" action=\"OpenFile\" /> \
<menuitem name=\"Save\" action=\"SaveFile\" /> \
<menuitem name=\"Save As\" action=\"SaveAsFile\" /> \
+ <menuitem name=\"Close\" action=\"CloseFile\" /> \
<menuitem name=\"Print\" action=\"Print\" /> \
<separator name=\"Separator1\"/> \
<menuitem name=\"Preferences\" action=\"Preferences\" /> \
diff --git a/info.c b/info.c
index 3efb40cf8..34ddfa923 100644
--- a/info.c
+++ b/info.c
@@ -113,6 +113,17 @@ void show_dive_info(struct dive *dive)
const char *text;
char buffer[80];
+ if (!dive) {
+ gtk_window_set_title(GTK_WINDOW(main_window), "Subsurface");
+ SET_TEXT_VALUE(divemaster);
+ SET_TEXT_VALUE(buddy);
+ SET_TEXT_VALUE(location);
+ SET_TEXT_VALUE(suit);
+ gtk_entry_set_text(rating, star_strings[0]);
+ gtk_text_buffer_set_text(gtk_text_view_get_buffer(notes), "", -1);
+ return;
+ }
+
/* dive number and location (or lacking that, the date) go in the window title */
text = dive->location;
if (!text)
diff --git a/statistics.c b/statistics.c
index a53617337..674efbb94 100644
--- a/statistics.c
+++ b/statistics.c
@@ -416,3 +416,32 @@ GtkWidget *single_stats_widget(void)
return vbox;
}
+
+void clear_stats_widgets(void)
+{
+ set_label(single_w.date, "");
+ set_label(single_w.dive_time, "");
+ set_label(single_w.surf_intv, "");
+ set_label(single_w.max_depth, "");
+ set_label(single_w.avg_depth, "");
+ set_label(single_w.water_temp, "");
+ set_label(single_w.sac, "");
+ set_label(single_w.sac, "");
+ set_label(single_w.otu, "");
+ set_label(single_w.o2he, "");
+ set_label(single_w.gas_used, "");
+ set_label(stats_w.total_time,"");
+ set_label(stats_w.avg_time,"");
+ set_label(stats_w.shortest_time,"");
+ set_label(stats_w.longest_time,"");
+ set_label(stats_w.max_overall_depth,"");
+ set_label(stats_w.min_overall_depth,"");
+ set_label(stats_w.avg_overall_depth,"");
+ set_label(stats_w.min_sac,"");
+ set_label(stats_w.avg_sac,"");
+ set_label(stats_w.max_sac,"");
+ set_label(stats_w.selection_size,"");
+ set_label(stats_w.max_temp,"");
+ set_label(stats_w.avg_temp,"");
+ set_label(stats_w.min_temp,"");
+}