From: John Darrington Date: Sat, 7 Mar 2009 11:24:21 +0000 (+0900) Subject: Made the save-before-quit dialog more HIG compliant. X-Git-Tag: v0.7.3~246 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26763488cfe4213eb1dfdc5966a3659a0e89887f;p=pspp-builds.git Made the save-before-quit dialog more HIG compliant. Thanks to jeff for the suggestion. Closes patch #6749 --- diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 4543dc72..c735d05b 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -448,14 +448,15 @@ name_has_suffix (const gchar *name) /* Save DE to file */ static void -save_file (PsppireDataWindow *de) +save_file (PsppireWindow *w) { gchar *fn = NULL; GString *fnx; struct getl_interface *sss; struct string file_name ; + PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (w); - g_object_get (de, "filename", &fn, NULL); + g_object_get (w, "filename", &fn, NULL); fnx = g_string_new (fn); @@ -576,7 +577,7 @@ data_save_as_dialog (PsppireDataWindow *de) psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str); - save_file (de); + save_file (PSPPIRE_WINDOW (de)); g_string_free (filename, TRUE); } @@ -597,7 +598,7 @@ data_save (PsppireWindow *de) const gchar *fn = psppire_window_get_filename (de); if ( NULL != fn) - save_file (PSPPIRE_DATA_WINDOW (de)); + psppire_window_save (de); else data_save_as_dialog (PSPPIRE_DATA_WINDOW (de)); } @@ -1791,6 +1792,6 @@ psppire_data_window_new (void) static void psppire_data_window_iface_init (PsppireWindowIface *iface) { - iface->save = data_save; + iface->save = save_file; iface->load = load_file; } diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 7a4f8cef..3124fb47 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -382,12 +382,17 @@ on_delete (PsppireWindow *w, GdkEvent *event, gpointer user_data) { gint response = psppire_window_query_save (w); - if ( response == GTK_RESPONSE_CANCEL) - return TRUE; - - if ( response == GTK_RESPONSE_ACCEPT) + switch (response) { + case GTK_RESPONSE_CANCEL: + return TRUE; + break; + case GTK_RESPONSE_APPLY: psppire_window_save (w); + break; + case GTK_RESPONSE_REJECT: + default: + break; } } @@ -433,8 +438,7 @@ psppire_window_init (PsppireWindow *window) } - -/* +/* Ask the user if the buffer should be saved. Return the response. */ @@ -443,34 +447,47 @@ psppire_window_query_save (PsppireWindow *se) { gint response; GtkWidget *dialog; + GtkWidget *cancel_button; const gchar *description; const gchar *filename = psppire_window_get_filename (se); + GTimeVal time; + + g_get_current_time (&time); + g_object_get (se, "description", &description, NULL); g_return_val_if_fail (filename != NULL, GTK_RESPONSE_NONE); + dialog = gtk_message_dialog_new (GTK_WINDOW (se), GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, + GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, - _("Save contents of %s to \"%s\"?"), - description, + _("Save the changes to \"%s\" before closing?"), filename); - gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_YES, - GTK_RESPONSE_ACCEPT); + g_object_set (dialog, "icon-name", "psppicon", NULL); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("If you don't save, changes from the last %ld seconds will be permanently lost."), + time.tv_sec - se->savetime.tv_sec); gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_NO, + _("Close _without saving"), GTK_RESPONSE_REJECT); + cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); + GTK_STOCK_SAVE, + GTK_RESPONSE_APPLY); + + gtk_widget_grab_focus (cancel_button); response = gtk_dialog_run (GTK_DIALOG (dialog)); @@ -480,6 +497,7 @@ psppire_window_query_save (PsppireWindow *se) } + const gchar * psppire_window_get_filename (PsppireWindow *w) { @@ -498,9 +516,10 @@ psppire_window_set_filename (PsppireWindow *w, const gchar *filename) void psppire_window_set_unsaved (PsppireWindow *w) { - w->dirty = TRUE; + if ( w->dirty == FALSE) + g_get_current_time (&w->savetime); - g_get_current_time (&w->savetime); + w->dirty = TRUE; psppire_window_set_title (w); } @@ -576,6 +595,9 @@ psppire_window_save (PsppireWindow *w) g_return_if_fail (i->save); i->save (w); + + w->dirty = FALSE; + psppire_window_set_title (w); } extern GtkRecentManager *the_recent_mgr; @@ -627,7 +649,7 @@ add_most_recent (const char *file_name, GtkRecentManager *rm) -/* +/* If FILE_NAME exists in the recent list, then delete it. */ static void @@ -639,6 +661,5 @@ delete_recent (const char *file_name, GtkRecentManager *rm) gtk_recent_manager_remove_item (rm, uri, NULL); g_free (uri); - }