From 233ec937746ac54c25d52771bfbb9ecc475a8919 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 25 Mar 2003 15:47:45 +0000 Subject: Move this here from gal. Use e_dialog_set_transient_for so it DTRT for * e-dialog-utils.c (e_notice): Move this here from gal. Use e_dialog_set_transient_for so it DTRT for out-of-proc components. (e_notice_with_xid): Like e_notice but with an X Window ID as the parent window (e_gnome_dialog_set_parent): Remove this, since it was marked deprecated and only used in one place. (e_file_dialog_save): Make this use GtkMessageDialog instead of GnomeDialog svn path=/trunk/; revision=20498 --- e-util/e-dialog-utils.c | 102 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 22 deletions(-) (limited to 'e-util/e-dialog-utils.c') diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c index cce4d1494f..173526c46b 100644 --- a/e-util/e-dialog-utils.c +++ b/e-util/e-dialog-utils.c @@ -24,8 +24,6 @@ #include "e-dialog-utils.h" -#include -#include #include #include @@ -34,8 +32,75 @@ #include #include -#include -#include + + +/** + * e_notice: + * @parent: the dialog's parent window, or %NULL + * @type: the type of dialog (%GTK_MESSAGE_INFO, %GTK_MESSAGE_WARNING, + * or %GTK_MESSAGE_ERROR) + * @format: printf-style format string, followed by arguments + * + * Convenience function to show a dialog with a message and an "OK" + * button. + **/ +void +e_notice (gpointer parent, GtkMessageType type, const char *format, ...) +{ + GtkWidget *dialog; + va_list args; + char *str; + + va_start (args, format); + str = g_strdup_vprintf (format, args); + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + type, + GTK_BUTTONS_OK, + "%s", + str); + va_end (args); + g_free (str); + + if (parent) + e_dialog_set_transient_for (GTK_WINDOW (dialog), parent); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} + +/** + * e_notice_with_xid: + * @parent: the dialog's parent window, or %NULL + * @type: the type of dialog (%GTK_MESSAGE_INFO, %GTK_MESSAGE_WARNING, + * or %GTK_MESSAGE_ERROR) + * @format: printf-style format string, followed by arguments + * + * Like e_notice(), but takes a GdkNativeWindow for the parent + * window argument. + **/ +void +e_notice_with_xid (GdkNativeWindow parent, GtkMessageType type, const char *format, ...) +{ + GtkWidget *dialog; + va_list args; + char *str; + + va_start (args, format); + str = g_strdup_vprintf (format, args); + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + type, + GTK_BUTTONS_OK, + "%s", + str); + va_end (args); + g_free (str); + + if (parent) + e_dialog_set_transient_for_xid (GTK_WINDOW (dialog), parent); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} /* Tests whether or not an X Window is being managed by the @@ -155,26 +220,13 @@ e_dialog_set_transient_for_xid (GtkWindow *dialog, -static void -e_gnome_dialog_parent_destroyed (GnomeDialog *dialog, GObject *deadbeef) -{ - gnome_dialog_close (GNOME_DIALOG (dialog)); -} - -void -e_gnome_dialog_set_parent (GnomeDialog *dialog, GtkWindow *parent) -{ - gnome_dialog_set_parent (dialog, parent); - g_object_weak_ref ((GObject *) parent, (GWeakNotify) e_gnome_dialog_parent_destroyed, dialog); -} - static void save_ok (GtkWidget *widget, gpointer data) { GtkWidget *fs; char **filename = data; const char *path; - int btn = GNOME_YES; + int btn = GTK_RESPONSE_YES; fs = gtk_widget_get_toplevel (widget); path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)); @@ -182,12 +234,18 @@ save_ok (GtkWidget *widget, gpointer data) if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { GtkWidget *dlg; - dlg = gnome_question_dialog_modal (_("A file by that name already exists.\n" - "Overwrite it?"), NULL, NULL); - btn = gnome_dialog_run_and_close (GNOME_DIALOG (dlg)); + dlg = gtk_message_dialog_new (GTK_WINDOW (fs), 0, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + _("A file by that name already exists.\n" + "Overwrite it?")); + gtk_window_set_title (GTK_WINDOW (dlg), _("Overwrite file?")); + + btn = gtk_dialog_run (GTK_DIALOG (dlg)); + gtk_widget_destroy (dlg); } - if (btn == GNOME_YES) + if (btn == GTK_RESPONSE_YES) *filename = g_strdup (path); gtk_main_quit (); -- cgit v1.2.3