From: Jim Evins Date: Tue, 3 Sep 2002 04:22:55 +0000 (+0000) Subject: Replaced gtk_message_dialogs with a custom dialog based on the HIG. X-Git-Tag: glabels-2_3_0~805 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6b512fc87989f66f777aed61540f7116ab6f7f99;p=glabels Replaced gtk_message_dialogs with a custom dialog based on the HIG. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@79 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/src/file.c b/glabels2/src/file.c index f607b0a2..50c44491 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -322,6 +322,7 @@ gl_file_open_real (const gchar *filename, GtkWidget *dlg; GnomeRecentModel *recent; gint ret; + gchar *primary_msg; gl_debug (DEBUG_FILE, "START"); @@ -331,12 +332,17 @@ gl_file_open_real (const gchar *filename, gl_debug (DEBUG_FILE, "couldn't open file"); - dlg = gtk_message_dialog_new (GTK_WINDOW(win), + primary_msg = g_strdup_printf (_("Could not open file \"%s\""), + filename); + + dlg = gl_util_hig_dialog_new (GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("Cannot open file '%s'"), - filename); + primary_msg, ""); + + g_free (primary_msg); + gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); @@ -419,15 +425,21 @@ gl_file_save (glMDIChild *child) if (status != XML_LABEL_OK) { GtkWidget *dialog; + gchar *primary_msg; gl_debug (DEBUG_FILE, "FAILED"); - dialog = gtk_message_dialog_new (GTK_WINDOW(glabels_get_active_window()), + primary_msg = g_strdup_printf (_("Could not save file \"%s\""), + filename); + + dialog = gl_util_hig_dialog_new (GTK_WINDOW(glabels_get_active_window()), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("Error saving file '%s'"), - filename); + primary_msg, ""); + + g_free (primary_msg); + gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); @@ -522,6 +534,7 @@ save_as_ok_cb (GtkWidget * widget, glXMLLabelStatus status; GnomeRecentModel *recent; gboolean *saved_flag; + gchar *primary_msg; gl_debug (DEBUG_FILE, "START"); @@ -543,11 +556,11 @@ save_as_ok_cb (GtkWidget * widget, if (!raw_filename || (raw_filename[strlen (raw_filename) - 1] == '/')) { - dlg = gtk_message_dialog_new (GTK_WINDOW(fsel), + dlg = gl_util_hig_dialog_new (GTK_WINDOW(fsel), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, - _("Must supply file name")); + _("Must supply file name"), ""); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); } else { @@ -562,12 +575,17 @@ save_as_ok_cb (GtkWidget * widget, if ( status != XML_LABEL_OK ) { - dlg = gtk_message_dialog_new (GTK_WINDOW(fsel), + primary_msg = g_strdup_printf (_("Could not save file \"%s\""), + filename); + + dlg = gl_util_hig_dialog_new (GTK_WINDOW(fsel), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("Error writing file '%s'"), - filename); + primary_msg, ""); + + g_free (primary_msg); + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); } else { diff --git a/glabels2/src/mdi.c b/glabels2/src/mdi.c index 3e0dc58f..8d746a5d 100644 --- a/glabels2/src/mdi.c +++ b/glabels2/src/mdi.c @@ -46,6 +46,7 @@ #include "view.h" #include "debug.h" #include "gnome-recent-view.h" +#include "util.h" #include #include @@ -572,18 +573,19 @@ gl_mdi_remove_child_cb (BonoboMDI *mdi, BonoboMDIChild *child) fname = gl_label_get_short_name (doc); - msgbox = gtk_message_dialog_new (GTK_WINDOW (bonobo_mdi_get_active_window (mdi)), + msg = g_strdup_printf (_("Save changes to document \"%s\" before closing?"), + fname); + + msgbox = gl_util_hig_dialog_new (GTK_WINDOW (bonobo_mdi_get_active_window (mdi)), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, + GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, - _("Do you want to save the changes you made to the document \"%s\"? \n\n" - "Your changes will be lost if you don't save them."), - fname); + msg, + _("Your changes will be lost if you don't save them.")); - gl_util_dialog_add_button (GTK_DIALOG (msgbox), - _("Do_n't save"), - GTK_STOCK_NO, - GTK_RESPONSE_NO); + gtk_dialog_add_button (GTK_DIALOG (msgbox), + _("Close without saving"), + GTK_RESPONSE_NO); if (glabels_close_x_button_pressed) exiting = FALSE; @@ -598,18 +600,6 @@ gl_mdi_remove_child_cb (BonoboMDI *mdi, BonoboMDIChild *child) exiting = FALSE; } -#if 0 - if (exiting) - gl_util_dialog_add_button (GTK_DIALOG (msgbox), - _("_Don't quit"), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - else - gl_util_dialog_add_button (GTK_DIALOG (msgbox), - _("_Don't close"), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); -#endif gtk_dialog_add_button (GTK_DIALOG (msgbox), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); diff --git a/glabels2/src/util.c b/glabels2/src/util.c index d762a7cb..bec67e03 100644 --- a/glabels2/src/util.c +++ b/glabels2/src/util.c @@ -250,3 +250,123 @@ gl_util_string_to_weight (const gchar * string) } } + +/****************************************************************************/ +/* Create a message dialog that attempts to be HIG compliant. */ +/****************************************************************************/ +GtkWidget* gl_util_hig_dialog_new (GtkWindow *parent, + GtkDialogFlags flags, + GtkMessageType type, + GtkButtonsType buttons, + const gchar *primary_text, + const gchar *secondary_text) +{ + GtkWidget *dialog, *hbox, *image, *label; + gchar *label_text; + const gchar *stock_id = NULL; + GtkStockItem item; + + /* Create bare dialog */ + dialog = gtk_dialog_new_with_buttons ("", parent, flags, NULL); + + /* Create HBOX */ + hbox = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), + hbox, FALSE, FALSE, 0); + + /* Create image */ + switch (type) { + case GTK_MESSAGE_INFO: + stock_id = GTK_STOCK_DIALOG_INFO; + break; + case GTK_MESSAGE_QUESTION: + stock_id = GTK_STOCK_DIALOG_QUESTION; + break; + case GTK_MESSAGE_WARNING: + stock_id = GTK_STOCK_DIALOG_WARNING; + break; + case GTK_MESSAGE_ERROR: + stock_id = GTK_STOCK_DIALOG_ERROR; + break; + default: + stock_id = GTK_STOCK_DIALOG_INFO; + g_warning ("Unknown GtkMessageType %d", type); + break; + } + if (gtk_stock_lookup (stock_id, &item)) { + image = gtk_image_new_from_stock (stock_id, + GTK_ICON_SIZE_DIALOG); + } else { + image = gtk_image_new_from_stock (NULL, + GTK_ICON_SIZE_DIALOG); + g_warning ("Stock dialog ID doesn't exist?"); + } + gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0); + + /* Create label containing primary and secondary text */ + label_text = g_strdup_printf ("%s\n\n%s", + primary_text, secondary_text); + label = gtk_label_new (label_text); + g_free (label_text); + gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0); + + /* Adjust dialog properties */ + gtk_window_set_title (GTK_WINDOW(dialog), ""); + gtk_container_set_border_width (GTK_CONTAINER(dialog), 6); + gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE); + + /* Adjust VBOX properties */ + gtk_box_set_spacing (GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); + + /* Adjust HBOX properties */ + gtk_box_set_spacing (GTK_BOX(hbox), 12); + gtk_container_set_border_width (GTK_CONTAINER(hbox), 6); + + /* Adjust IMAGE properties */ + gtk_misc_set_alignment (GTK_MISC(image), 0.5, 0.0); + + /* Adjust LABEL properties */ + gtk_label_set_line_wrap (GTK_LABEL(label), TRUE); + gtk_label_set_use_markup (GTK_LABEL(label), TRUE); + gtk_misc_set_alignment (GTK_MISC(image), 0.5, 0.0); + + /* Add buttons */ + switch (buttons) { + case GTK_BUTTONS_NONE: + /* nothing */ + break; + case GTK_BUTTONS_OK: + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_OK, GTK_RESPONSE_OK); + break; + case GTK_BUTTONS_CLOSE: + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); + break; + case GTK_BUTTONS_CANCEL: + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + break; + case GTK_BUTTONS_YES_NO: + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_NO, GTK_RESPONSE_NO); + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_YES, GTK_RESPONSE_YES); + break; + case GTK_BUTTONS_OK_CANCEL: + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG(dialog), + GTK_STOCK_OK, GTK_RESPONSE_OK); + break; + default: + g_warning ("Unknown GtkButtonsType"); + break; + } + + /* Show dialog widgets */ + gtk_widget_show_all (hbox); + + return dialog; +} + diff --git a/glabels2/src/util.h b/glabels2/src/util.h index 33f5867a..159754e7 100644 --- a/glabels2/src/util.h +++ b/glabels2/src/util.h @@ -46,4 +46,11 @@ extern GtkJustification gl_util_string_to_just (const gchar * string); extern const gchar *gl_util_weight_to_string (GnomeFontWeight weight); extern GnomeFontWeight gl_util_string_to_weight (const gchar * string); +GtkWidget* gl_util_hig_dialog_new (GtkWindow *parent, + GtkDialogFlags flags, + GtkMessageType type, + GtkButtonsType buttons, + const gchar *primary_text, + const gchar *secondary_text); + #endif /* __UTIL_H__ */