So far, when trying to quit while the data was changed the offer
was "Save" or "Don't save". Now, you can also "Cancel" which will
bring you back to the main window.
This allows you to re-save the data in another file.
Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
-static void ask_save_changes()
+static gboolean ask_save_changes()
{
GtkWidget *dialog, *label, *content;
{
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_NO, GTK_RESPONSE_NO,
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_NO, GTK_RESPONSE_NO,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
NULL);
content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
gtk_container_add (GTK_CONTAINER (content), label);
gtk_widget_show_all (dialog);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
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) {
+ gint *outcode = gtk_dialog_run(GTK_DIALOG(dialog));
+ if (outcode == GTK_RESPONSE_ACCEPT) {
+ } else if (outcode == GTK_RESPONSE_CANCEL) {
+ quit = FALSE;
}
gtk_widget_destroy(dialog);
}
gtk_widget_destroy(dialog);
}
static gboolean on_delete(GtkWidget* w, gpointer data)
}
static gboolean on_delete(GtkWidget* w, gpointer data)
/* Make sure to flush any modified dive data */
update_dive(NULL);
/* Make sure to flush any modified dive data */
update_dive(NULL);
+ quit = ask_save_changes();
- return FALSE; /* go ahead, kill the program, we're good now */
+ if (quit){
+ return FALSE; /* go ahead, kill the program, we're good now */
+ } else {
+ return TRUE; /* We are not leaving */
+ }
}
static void on_destroy(GtkWidget* w, gpointer data)
}
static void on_destroy(GtkWidget* w, gpointer data)
/* Make sure to flush any modified dive data */
update_dive(NULL);
/* Make sure to flush any modified dive data */
update_dive(NULL);
- ask_save_changes();
- gtk_main_quit();
+ quit = ask_save_changes();
+
+ if (quit){
+ gtk_main_quit();
+ }
}
GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
}
GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,