diff --git a/src/file.c b/src/file.c index f092eee..fbc0734 100644 --- a/src/file.c +++ b/src/file.c @@ -122,7 +122,7 @@ gboolean confirmbox (DenemoGUI * gui) { gboolean ret; gchar *primary = g_strdup_printf(_("The score %s has unsaved changes"), gui->filename->len?gui->filename->str:"(Untitled)"); - ret = confirm (primary, _("Discard changes?")); + ret = confirmSave (gui, primary, _("Save changes?")); g_free(primary); return ret; } diff --git a/src/utils.c b/src/utils.c index 7ff1778..7952302 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1178,6 +1178,63 @@ confirm (gchar *primary, gchar *secondary) return r; } +/** + * A clone of above written confirm function, specifically written for save. + * Display a message box asking primary & secondary messages + */ +gboolean +confirmSave (DenemoGUI *gui, gchar *primary, gchar *secondary) +{ + GtkWidget *dialog; + gboolean r = 0; + + dialog = gtk_message_dialog_new (GTK_WINDOW (Denemo.window), + (GtkDialogFlags) + (GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT), + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "%s", primary); + + GtkWidget *save = gtk_dialog_add_button( (GtkDialog*)dialog, + GTK_STOCK_SAVE_AS, + GTK_RESPONSE_YES); + + GtkWidget *cancel = gtk_dialog_add_button( (GtkDialog*)dialog, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + + GtkWidget *d_save = gtk_dialog_add_button( (GtkDialog*)dialog, + "Close without Saving", + GTK_RESPONSE_NO); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", + secondary); + gtk_widget_show_all (dialog); + gint response = gtk_dialog_run (GTK_DIALOG (dialog)); + + if(response == GTK_RESPONSE_YES) + { + gtk_widget_destroy (dialog); + file_saveas (gui, SAVE_NORMAL); + if(gui->notsaved) + r = 0; + else + r = 1; + } + else if(response == GTK_RESPONSE_NO) + { + gtk_widget_destroy (dialog); + r = 1; + } + else + { + gtk_widget_destroy (dialog); + r = 0; + } + return r; +} + /* free a GString and the string it holds, and set the pointer to it to NULL */ void nullify_gstring (GString **s) { if(*s) diff --git a/src/utils.h b/src/utils.h index 57de7e6..4144be0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -149,6 +149,8 @@ void score_status(DenemoGUI *gui, gboolean change); void write_status(DenemoGUI *gui); gboolean confirm (gchar *primary, gchar *secondary); +gboolean +confirmSave (DenemoGUI *gui, gchar *primary, gchar *secondary); void nullify_gstring (GString **s);