summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
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 /gtk-gui.c
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>
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c37
1 files changed, 35 insertions, 2 deletions
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\" /> \