Re: Common Save Confirmation Dialogue



(Fixed broken tabs)

On 5/10/05, Marc O'Morain <marc omorain gmail com> wrote:
> Attached is some code to create a HIG-compliant save confirmation
> message box.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
/* GTK - The GIMP Toolkit
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the GTK+ Team and others 1997-2005.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
 */

#include "gtksaveconfirmationalert.h"
#include "gtkmessagedialog.h"


/**
 * gtk_save_confirmation_alert:
 * @parent: transient parent, or NULL for none
 * @last_save: The time that the last save took place
 * or the time that the document was created if it has
 * not been saved before.
 * @document_name: The name of the document that is
 * unsaved.
 *
 * Opens a message box to ask the user if they want to
 * save a document that has been changed since the last
 * save. This will usually be called when the user exits
 * a program while documents are still open.
 *
 * Return value: The users response. GTK_RESPONSE_NO to
 * discard changes, GTK_RESPONSE_CANCEL to return to
 * the program, or  GTK_RESPONSE_YES to save the changes.
 *
 * Since: 2.X?
 **/
gint
gtk_save_confirmation_alert  (	GtkWindow  	*parent,
				const GTimeVal	*last_save,
				const gchar	*document_name)
{
	GTimeVal	now;
	glong 		seconds;
	GtkWidget*	dialog;
	gint		result;

	g_get_current_time(&now);
	seconds = now.tv_sec  - last_save.tv_sec;

	dialog = gtk_message_dialog_new_with_markup  (parent,
					GTK_DIALOG_DESTROY_WITH_PARENT,
					GTK_MESSAGE_WARNING,
					GTK_BUTTONS_NONE,
					"<b>"_("Save changes to %s before closing?")"</b>",
					document_name);



	gtk_dialog_add_button	(dialog, _("Close _Without Saving"),
					GTK_RESPONSE_NO);
	gtk_dialog_add_button	(dialog, GTK_STOCK_CANCEL,
					GTK_RESPONSE_CANCEL);
	gtk_dialog_add_button	(dialog, GTK_STOCK_SAVE,
					GTK_RESPONSE_YES);

	if (seconds < 55)
	  {
		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."),
				seconds);
	  }
	else if (seconds < 75)
	  {
		gtk_message_dialog_format_secondary_text (
				GTK_MESSAGE_DIALOG(dialog),
				_("If you don't save, changes from the last "
				"minute will be permanently lost."));
	  }
	else if (seconds < 110)
	  {
		seconds -= 60;
		gtk_message_dialog_format_secondary_text (
				GTK_MESSAGE_DIALOG(dialog),
				_("If you don't save, changes from the last "
				"minute and %ld seconds will be permanently lost."),
				seconds);
	  }
	else if (seconds	< 3600)
	  {
		glong minutes = seconds / 60;
		gtk_message_dialog_format_secondary_text (
				GTK_MESSAGE_DIALOG(dialog),
				_("If you don't save, changes from the last "
				"%ld minutes will be permanently lost."),
				minutes);
	  }
	else if (seconds	< 7200)
	  {
		seconds -= 3600;
		glong minutes = seconds / 60;
		if (minutes < 5)
		  {
			gtk_message_dialog_format_secondary_text (
				GTK_MESSAGE_DIALOG(dialog),
				_("If you don't save, changes from the last "
				"hour will be permanently lost."));
		  }
		else
		  {
			gtk_message_dialog_format_secondary_text (
					GTK_MESSAGE_DIALOG(dialog),
					_("If you don't save, changes from the last "
					"hour and %ld minutes will be permanently lost."),
					minutes);
		  }
	  }
   else
   	{
            glong hours = seconds / 3600;
            gtk_message_dialog_format_secondary_text (
				GTK_MESSAGE_DIALOG(dialog),
				_("If you don't save, changes from the last "
				"%ld hours will be permanently lost."),
				hours);
		}

	result = gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (dialog);
	return result;

}

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
/* GTK - The GIMP Toolkit
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the GTK+ Team and others 1997-2005.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
 */

#ifndef __GTK_SAVE_CONFIRMATION_ALERT_H__
#define __GTK_SAVE_CONFIRMATION_ALERT_H__

#include "gtkwindow.h"

gint gtk_save_confirmation_alert (GtkWindow	 *parent,
				  const GTimeVal *last_save,
				  const gchar	 *document_name);


#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]