From: Jim Evins Date: Wed, 18 May 2005 02:47:19 +0000 (+0000) Subject: 2005-05-17 Jim Evins X-Git-Tag: glabels-2_3_0~415 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b75ae61753d37cd5b74f393cfb8a207d0e0ae3bc;p=glabels 2005-05-17 Jim Evins * src/hig.h: * src/hig.c: Removed HigAlert class since it is obsoleted by the GtkMessageDialog class. * src/file.c: (open_response), (gl_file_open_real), (gl_file_save), (save_as_response), (gl_file_close): Replaced all instances of HigAlert widgets with GtkMessageDialog widgets. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@534 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 4c2b9504..dd825c0e 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,12 @@ +2005-05-17 Jim Evins + + * src/hig.h: + * src/hig.c: + Removed HigAlert class since it is obsoleted by the GtkMessageDialog class. + * src/file.c: (open_response), (gl_file_open_real), (gl_file_save), + (save_as_response), (gl_file_close): + Replaced all instances of HigAlert widgets with GtkMessageDialog widgets. + 2005-05-15 Jim Evins * src/ui-commands.h: diff --git a/glabels2/src/file.c b/glabels2/src/file.c index 56494e9d..cd8ac652 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -490,12 +491,14 @@ open_response (GtkDialog *chooser, !filename || g_file_test (raw_filename, G_FILE_TEST_IS_DIR)) { - dlg = gl_hig_alert_new (GTK_WINDOW(chooser), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - _("Empty file name selection"), - _("Please select a file or supply a valid file name")); + dlg = gtk_message_dialog_new (GTK_WINDOW(chooser), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_CLOSE, + _("Empty file name selection")); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("Please select a file or supply a valid file name")); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); @@ -504,12 +507,14 @@ open_response (GtkDialog *chooser, if (!g_file_test (raw_filename, G_FILE_TEST_IS_REGULAR)) { - dlg = gl_hig_alert_new (GTK_WINDOW(chooser), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - _("File does not exist"), - _("Please select a file or supply a valid file name")); + dlg = gtk_message_dialog_new (GTK_WINDOW(chooser), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_CLOSE, + _("File does not exist")); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("Please select a file or supply a valid file name")); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); @@ -575,21 +580,17 @@ gl_file_open_real (const gchar *filename, label = gl_xml_label_open (abs_filename, &status); if (!label) { GtkWidget *dlg; - gchar *primary_msg; gl_debug (DEBUG_FILE, "couldn't open file"); - primary_msg = g_strdup_printf (_("Could not open file \"%s\""), - filename); - - dlg = gl_hig_alert_new (GTK_WINDOW (window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - primary_msg, - _("Not a supported file format")); - - g_free (primary_msg); + dlg = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Could not open file \"%s\""), + filename); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg), + _("Not a supported file format")); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); @@ -660,25 +661,22 @@ gl_file_save (glLabel *label, if (status != XML_LABEL_OK) { - GtkWidget *dialog; - gchar *primary_msg; + GtkWidget *dlg; gl_debug (DEBUG_FILE, "FAILED"); - primary_msg = g_strdup_printf (_("Could not save file \"%s\""), - filename); - - dialog = gl_hig_alert_new (GTK_WINDOW (window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - primary_msg, - _("Error encountered during save. The file is still not saved.")); + dlg = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Could not save file \"%s\""), + filename); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("Error encountered during save. The file is still not saved.")); - g_free (primary_msg); - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + gtk_dialog_run (GTK_DIALOG (dlg)); + gtk_widget_destroy (dlg); g_free (filename); @@ -777,7 +775,6 @@ save_as_response (GtkDialog *chooser, glXMLLabelStatus status; EggRecentModel *recent; gboolean *saved_flag; - gchar *primary_msg; gboolean cancel_flag = FALSE; gl_debug (DEBUG_FILE, "START"); @@ -796,12 +793,14 @@ save_as_response (GtkDialog *chooser, if (!raw_filename || g_file_test (raw_filename, G_FILE_TEST_IS_DIR)) { - dlg = gl_hig_alert_new (GTK_WINDOW(chooser), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - _("Empty file name selection"), - _("Please supply a valid file name")); + dlg = gtk_message_dialog_new (GTK_WINDOW(chooser), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_CLOSE, + _("Empty file name selection")); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("Please supply a valid file name")); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); @@ -818,17 +817,15 @@ save_as_response (GtkDialog *chooser, if (g_file_test (full_filename, G_FILE_TEST_IS_REGULAR)) { gint ret; - primary_msg = g_strdup_printf (_("Overwrite file \"%s\"?"), + dlg = gtk_message_dialog_new (GTK_WINDOW(chooser), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + _("Overwrite file \"%s\"?"), filename); - - dlg = gl_hig_alert_new (GTK_WINDOW(chooser), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - primary_msg, - _("File already exists.")); - - g_free (primary_msg); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("File already exists.")); ret = gtk_dialog_run (GTK_DIALOG (dlg)); if ( ret == GTK_RESPONSE_NO ) { @@ -845,17 +842,16 @@ save_as_response (GtkDialog *chooser, if ( status != XML_LABEL_OK ) { - primary_msg = g_strdup_printf (_("Could not save file \"%s\""), - filename); - - dlg = gl_hig_alert_new (GTK_WINDOW(chooser), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - primary_msg, - _("Error encountered during save. The file is still not saved.")); - - g_free (primary_msg); + dlg = gtk_message_dialog_new ( + GTK_WINDOW(chooser), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Could not save file \"%s\""), + filename); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("Error encountered during save. The file is still not saved.")); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); @@ -915,43 +911,42 @@ gl_file_close (glWindow *window) label = view->label; if (gl_label_is_modified (label)) { - GtkWidget *msgbox, *w; - gchar *fname = NULL, *msg = NULL; + GtkWidget *dlg, *w; + gchar *fname = NULL; gint ret; gboolean exiting; fname = gl_label_get_short_name (label); - msg = g_strdup_printf (_("Save changes to document \"%s\" before closing?"), - fname); - - msgbox = gl_hig_alert_new (GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, - msg, - _("Your changes will be lost if you don't save them.")); - - gtk_dialog_add_button (GTK_DIALOG (msgbox), + dlg = gtk_message_dialog_new (GTK_WINDOW(window), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + _("Save changes to document \"%s\" before closing?"), + fname); + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dlg), + _("Your changes will be lost if you don't save them.")); + + gtk_dialog_add_button (GTK_DIALOG (dlg), _("Close without saving"), GTK_RESPONSE_NO); - gtk_dialog_add_button (GTK_DIALOG (msgbox), + gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (GTK_DIALOG (msgbox), + gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_SAVE, GTK_RESPONSE_YES); - gtk_dialog_set_default_response (GTK_DIALOG (msgbox), GTK_RESPONSE_YES); + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_YES); - gtk_window_set_resizable (GTK_WINDOW (msgbox), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); - ret = gtk_dialog_run (GTK_DIALOG (msgbox)); + ret = gtk_dialog_run (GTK_DIALOG (dlg)); - gtk_widget_destroy (msgbox); + gtk_widget_destroy (dlg); g_free (fname); - g_free (msg); switch (ret) { diff --git a/glabels2/src/hig.c b/glabels2/src/hig.c index 44ae8b01..4140520e 100644 --- a/glabels2/src/hig.c +++ b/glabels2/src/hig.c @@ -34,9 +34,6 @@ /*========================================================*/ /* Private macros and constants. */ /*========================================================*/ -#define HIG_ALERT_BORDER 6 -#define HIG_ALERT_SPACING 12 - #define HIG_DIALOG_BORDER 12 #define HIG_DIALOG_VBOX_SPACING 18 #define HIG_DIALOG_OUTER_VBOX_SPACING 12 @@ -51,7 +48,6 @@ /*===========================================*/ /* Private globals */ /*===========================================*/ -static GtkDialogClass *hig_alert_parent_class; static GtkDialogClass *hig_dialog_parent_class; static GtkVBoxClass *hig_category_parent_class; static GtkVBoxClass *hig_vbox_parent_class; @@ -62,10 +58,6 @@ static GtkHBoxClass *hig_hbox_parent_class; /* Local function prototypes */ /*===========================================*/ -static void gl_hig_alert_class_init (glHigAlertClass *class); -static void gl_hig_alert_init (glHigAlert *hig_alert); -static void gl_hig_alert_finalize (GObject *object); - static void gl_hig_dialog_class_init (glHigDialogClass *class); static void gl_hig_dialog_init (glHigDialog *hig_dialog); static void gl_hig_dialog_finalize (GObject *object); @@ -86,200 +78,6 @@ static void gl_hig_hbox_class_init (glHigHBoxClass *class); static void gl_hig_hbox_init (glHigHBox *hig_hbox); static void gl_hig_hbox_finalize (GObject *object); - -/****************************************************************************/ -/****************************************************************************/ -/* Boilerplate Alert Object stuff. */ -/****************************************************************************/ -/****************************************************************************/ -GType -gl_hig_alert_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (glHigAlertClass), - NULL, - NULL, - (GClassInitFunc) gl_hig_alert_class_init, - NULL, - NULL, - sizeof (glHigAlert), - 0, - (GInstanceInitFunc) gl_hig_alert_init, - NULL - }; - - type = g_type_register_static (GTK_TYPE_DIALOG, - "glHigAlert", &info, 0); - } - - return type; -} - -static void -gl_hig_alert_class_init (glHigAlertClass *class) -{ - GObjectClass *object_class = (GObjectClass *) class; - - hig_alert_parent_class = g_type_class_peek_parent (class); - - object_class->finalize = gl_hig_alert_finalize; -} - -static void -gl_hig_alert_init (glHigAlert *hig_alert) -{ -} - -static void -gl_hig_alert_finalize (GObject *object) -{ - glHigAlert *hig_alert; - - g_return_if_fail (object != NULL); - g_return_if_fail (GL_IS_HIG_ALERT (object)); - - hig_alert = GL_HIG_ALERT (object); - - G_OBJECT_CLASS (hig_alert_parent_class)->finalize (object); -} - - -/****************************************************************************/ -/* Create a message dialog that attempts to be HIG compliant. */ -/****************************************************************************/ -GtkWidget* gl_hig_alert_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; - - /* Bare dialog */ - dialog = g_object_new (gl_hig_alert_get_type (), NULL); - - /* Parent */ - gtk_window_set_transient_for (GTK_WINDOW(dialog), parent); - - /* Flags */ - if ( flags & GTK_DIALOG_MODAL ) { - gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); - } - if ( flags & GTK_DIALOG_DESTROY_WITH_PARENT ) { - gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE); - } - - /* Create HBOX */ - hbox = gtk_hbox_new (FALSE, HIG_ALERT_SPACING); - 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), - HIG_ALERT_BORDER); - gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE); - - /* Adjust VBOX properties */ - gtk_box_set_spacing (GTK_BOX(GTK_DIALOG(dialog)->vbox), - HIG_ALERT_SPACING); - - /* Adjust HBOX properties */ - gtk_box_set_spacing (GTK_BOX(hbox), HIG_ALERT_SPACING); - gtk_container_set_border_width (GTK_CONTAINER(hbox), HIG_ALERT_BORDER); - - /* 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; -} - - /****************************************************************************/ /****************************************************************************/ /* Boilerplate Dialog Object stuff. */ diff --git a/glabels2/src/hig.h b/glabels2/src/hig.h index 8f41fd79..1f5bed8c 100644 --- a/glabels2/src/hig.h +++ b/glabels2/src/hig.h @@ -33,41 +33,6 @@ G_BEGIN_DECLS #define GL_HIG_PAD2 12 -/*===========================================================================*/ -/* HIG inspired alert. */ -/*===========================================================================*/ - -#define GL_TYPE_HIG_ALERT (gl_hig_alert_get_type ()) -#define GL_HIG_ALERT(obj) \ - (GTK_CHECK_CAST((obj), GL_TYPE_HIG_ALERT, glHigAlert )) -#define GL_HIG_ALERT_CLASS(klass) \ - (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_HIG_ALERT, glHigAlertClass)) -#define GL_IS_HIG_ALERT(obj) \ - (GTK_CHECK_TYPE ((obj), GL_TYPE_HIG_ALERT)) -#define GL_IS_HIG_ALERT_CLASS(klass) \ - (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_HIG_ALERT)) - -typedef struct _glHigAlert glHigAlert; -typedef struct _glHigAlertClass glHigAlertClass; - -struct _glHigAlert { - GtkDialog parent_widget; -}; - -struct _glHigAlertClass { - GtkDialogClass parent_class; -}; - -GType gl_hig_alert_get_type (void) G_GNUC_CONST; - -GtkWidget *gl_hig_alert_new (GtkWindow *parent, - GtkDialogFlags flags, - GtkMessageType type, - GtkButtonsType buttons, - const gchar *primary_text, - const gchar *secondary_text); - - /*===========================================================================*/ /* HIG Dialog wrapper. */ /*===========================================================================*/