Re: [PATCH] Alert dialogs should not have window title according to the HIG



Il giorno sab, 03/12/2005 alle 19.42 +0100, Jaap Haitsma ha scritto:
> Patches attached at http://bugzilla.gnome.org/show_bug.cgi?id=323134

I was writing a light replacement for ell alert functions, based on
GtkMessageDialog and following HIG rules.

It's not yet finished, and I don't know if it's better to ask for
inclusion in GTK+ or keep it as cut-and-paste code. Do you think it
could be useful for Nautilus alerts, so we can test the code before
suggest it for gtk?

------

Please note that I removed the ability to add icons to confirmation and
alternate button in warning alerts. Moreover I don't know if it's better
provide a single function for warning alerts (as well as currently
implemented):

        gtk_message_dialog_warning_new (GtkWindow *parent,
        			const gchar *primary_text,
        			const gchar *secondary_text,
        			const gchar *primary_button,
        			const gchar *secondary_button);

forcing developer to use something like this:

        gtk_message_dialog_warning_net (parent, primary, secondary.
        				"_Delete", NULL);
        
to open a warning alert with a single confirmation button, or maybe
split this function in 

        gtk_message_dialog_simple warning_new (GtkWindow *parent,
        			const gchar *primary_text,
        			const gchar *secondary_text,
        			const gchar *confirm_button);
        
        gtk_message_dialog_full_warning_new (GtkWindow *parent,
        			const gchar *primary_text,
        			const gchar *secondary_text,
        			const gchar *confirm_button,
        			const gchar *alternate_button);
        
        

You can use 

        gcc -o message `pkg-config --cflags --libs gtk+-2.0` \
        gtkstockmessagedialogs.c gtkstockmessagedialogs.h message.c
        
to test it.
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* gtkstockmessagedialogs.h: various HIG-compliant message dialogs.
 *
 * Copyright (C) 2005 Luca Ferretti <elle uca libero it>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.
 */

#include "gtkstockmessagedialogs.h"

/* a private function */
GtkMessageDialog*
simple_message_dialog_new (GtkWindow     *parent,
			   const gchar   *primary_text,
			   const gchar   *secondary_text,
			   GtkMessageType type,
			   GtkButtonsType buttons)
{
  GtkMessageDialog *dialog;

  dialog = gtk_message_dialog_new (parent,
				   GTK_DIALOG_DESTROY_WITH_PARENT,
				   type,
				   buttons,
				   primary_text);

  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
					    secondary_text);

  gtk_window_set_title (GTK_WINDOW (dialog), ""); 
  gtk_window_set_focus_on_map (GTK_WINDOW (dialog), TRUE);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (dialog), TRUE);

  gtk_window_present (GTK_WINDOW (dialog)); 

  return dialog;
}

/**
 * gtk_message_dialog_info_new:
 * @parent: transient parent, or %NULL for none
 * @primary_text: the primary text for message dialog
 * @secondary_text: the secondary (explanatory) text for message dialog
 *
 * Create a new message dialog following the GNOME HIG suggestion for
 * information alerts: just one "OK" button (GTK_RESPONSE_OK) and
 * gtk-dialog-info stock icon.
 *
 * Return value: a new #GtkMessageDialog
 *
 * Since: 2.10
 **/
GtkMessageDialog*
gtk_message_dialog_info_new (GtkWindow   *parent,
			     const gchar *primary_text,
			     const gchar *secondary_text)
{
  return simple_message_dialog_new (parent,
				    primary_text,
				    secondary_text,
				    GTK_MESSAGE_INFO,
				    GTK_BUTTONS_OK);
}

/**
 * gtk_message_dialog_error_new:
 * @parent: transient parent, or %NULL for none
 * @primary_text: the primary text for message dialog
 * @secondary_text: the secondary (explanatory) text for message dialog
 *
 * Create a new message dialog following the GNOME HIG suggestion for
 * error alerts: just one "OK" button (GTK_RESPONSE_OK) and
 * gtk-dialog-error stock icon.
 *
 * Return value: a new #GtkMessageDialog
 *
 * Since: 2.10
 **/
GtkMessageDialog*
gtk_message_dialog_error_new (GtkWindow   *parent,
			     const gchar *primary_text,
			     const gchar *secondary_text)
{
  return simple_message_dialog_new (parent,
				    primary_text,
				    secondary_text,
				    GTK_MESSAGE_ERROR,
				    GTK_BUTTONS_OK);
}

/**
 * gtk_message_dialog_warning_new:
 * @parent: transient parent, or %NULL for none
 * @primary_text: the primary text for message dialog
 * @secondary_text: the secondary (explanatory) text for message dialog
 * @primary_button: the label for primary action button
 * @secondary_button: the label for alternate button, or NULL
 *
 * Create a new message dialog following the GNOME HIG suggestion for
 * warning alerts. A "Cancel" button is present (GTK_RESPONSE_CANCEL) and
 * the dialog can provide a confirmation button (label using @primary_button,
 * response is GTK_RESPONSE_OK) and eventually an alternate action button
 * (label using @secondary_button, response is GTK_RESPONSE_APPLY).
 *
 * Of course the dialog shows a gtk-dialog-warning stock icon.
 *
 * By now you can't set any icon for confirmation and/or alternate action button.
 * I don't know if it's needed in a simple alert.
 *
 * Return value: a new #GtkMessageDialog
 *
 * Since: 2.10
 **/
GtkMessageDialog*
gtk_message_dialog_warning_new (GtkWindow   *parent,
				const gchar *primary_text,
				const gchar *secondary_text,
				const gchar *primary_button,
				const gchar *secondary_button)
{
  GtkMessageDialog *dialog;

  dialog = gtk_message_dialog_new (parent,
				   GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_WARNING,
				   GTK_BUTTONS_NONE,
				   primary_text);

  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
					    secondary_text);

  if (secondary_button != NULL) 
      gtk_dialog_add_button (GTK_DIALOG (dialog),
			 secondary_button, GTK_RESPONSE_APPLY);
  gtk_dialog_add_button (GTK_DIALOG (dialog),
			 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
  gtk_dialog_add_button (GTK_DIALOG (dialog),
			 primary_button, GTK_RESPONSE_OK);

  gtk_window_set_title (GTK_WINDOW (dialog), "");
  gtk_window_set_focus_on_map (GTK_WINDOW (dialog), TRUE);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (dialog), TRUE);
  gtk_window_set_icon_name  (GTK_WINDOW (dialog), "gtk-dialog-warning");


  gtk_window_present (GTK_WINDOW (dialog)); 

  return dialog;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* gtkstockmessagedialogs.h: various HIG-compliant message dialogs.
 *
 * Copyright (C) 2005 Luca Ferretti <elle uca libero it>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.
 */

#ifndef GTK_STOCK_MESSAGE_DIALOGS_H
#define GTK_STOCK_MESSAGE_DIALOGS_H

#include <gtk/gtkdialog.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtk.h>

G_BEGIN_DECLS

GtkMessageDialog* gtk_message_dialog_info_new (GtkWindow *parent,
					       const gchar *primary_text,
					       const gchar *secondary_text);

GtkMessageDialog* gtk_message_dialog_error_new (GtkWindow *parent,
						const gchar *primary_text,
						const gchar *secondary_text);

GtkMessageDialog* gtk_message_dialog_warning_new (GtkWindow *parent,
						  const gchar *primary_text,
						  const gchar *secondary_text,
						  const gchar *primary_button,
						  const gchar *secondary_button);

G_END_DECLS

#endif /* __GTK_STOCK_MESSAGE_DIALOGS_H */
#include <gtk/gtk.h>

#include "gtkstockmessagedialogs.h"

int
main (int argc, char **argv)
{
	GtkMessageDialog *dialog;

	gtk_init (&argc, &argv);

	dialog = gtk_message_dialog_warning_new (NULL,
					      "Really delete all your files?",
					      "This is justa fake window. But a real message should be able to delete all your file in your home directrory",
					      "_Delete All",
					      "_Move to Trash");
	
	g_signal_connect (dialog, "destroy",
			G_CALLBACK (gtk_main_quit), NULL);

	gtk_widget_show_all (GTK_WIDGET (dialog));

	gtk_main ();
}


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