diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-21 12:28:20 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-21 12:28:20 -0700 |
commit | d94fb7ca6b4fc17dacd069522d7fad00aa69e088 (patch) | |
tree | 06afae13d3b894aa835b78af88d270aabd2c4c5f /gtk-gui.c | |
parent | 51486040686592965bd7a70cf52767350cfde5f6 (diff) | |
parent | a817f4b547b4193d31154fd0ff7f5190ccae76a5 (diff) | |
download | subsurface-d94fb7ca6b4fc17dacd069522d7fad00aa69e088.tar.gz |
Merge branch 'quit-handling' of git://github.com/dirkhh/subsurface
* 'quit-handling' of git://github.com/dirkhh/subsurface:
Use the last (or only) filename on command line as default for saving
Show the "save changes" dialog before the main window is destroyed
Check for changes at regular 'quit' events as well
Catch changes to the info of the current dive when quitting
Tracking changes to tanks is trivial
Simplistic first attempt to get changes saved when quitting subsurface
Diffstat (limited to 'gtk-gui.c')
-rw-r--r-- | gtk-gui.c | 55 |
1 files changed, 50 insertions, 5 deletions
@@ -31,11 +31,6 @@ struct units output_units; #define GCONF_NAME(x) "/apps/subsurface/" #x -void on_destroy(GtkWidget* w, gpointer data) -{ - gtk_main_quit(); -} - static GtkWidget *dive_profile; void repaint_dive(void) @@ -146,12 +141,53 @@ static void file_save(GtkWidget *w, gpointer data) filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); save_dives(filename); g_free(filename); + mark_divelist_changed(FALSE); + } + gtk_widget_destroy(dialog); +} + +static void ask_save_changes() +{ + GtkWidget *dialog, *label, *content; + dialog = gtk_dialog_new_with_buttons("Save Changes?", + GTK_WINDOW(main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + NULL); + content = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + label = gtk_label_new ("You have unsaved changes\nWould you like to save those before exiting the program?"); + gtk_container_add (GTK_CONTAINER (content), label); + gtk_widget_show_all (dialog); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + file_save(NULL,NULL); } gtk_widget_destroy(dialog); } +static gboolean on_delete(GtkWidget* w, gpointer data) +{ + /* Make sure to flush any modified dive data */ + update_dive(NULL); + + if (unsaved_changes()) + ask_save_changes(); + + return FALSE; /* go ahead, kill the program, we're good now */ +} + +static void on_destroy(GtkWidget* w, gpointer data) +{ + gtk_main_quit(); +} + static void quit(GtkWidget *w, gpointer data) { + /* Make sure to flush any modified dive data */ + update_dive(NULL); + + if (unsaved_changes()) + ask_save_changes(); gtk_main_quit(); } @@ -387,6 +423,7 @@ void init_ui(int argc, char **argv) error_info_bar = NULL; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL); + g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK (on_delete), NULL); g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL); main_window = win; @@ -614,3 +651,11 @@ void update_progressbar(progressbar_t *progress, double value) { gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value); } + + +void set_filename(const char *filename) +{ + if (filename) + existing_filename = strdup(filename); + return; +} |