From 80531ec9363311042009a7a6fed41ee6b3190d84 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 25 Aug 2004 17:58:52 +0000 Subject: [PATCH] added gimp_message_box_repeat(). 2004-08-25 Sven Neumann * app/widgets/gimpmessagebox.[ch]: added gimp_message_box_repeat(). * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimperrordialog.[ch]: added new dialog that adds a new GimpMessageBox for each message added. Fixes bug #92604. * app/widgets/gimpwidgets-utils.[ch]: removed old gimp_message_box() functionality. * app/gui/gui.c (gui_abort): use a GimpMessageBox in a GimpDialog. * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.c: manage GimpErrorDialog as singleton. * app/gui/gui-vtable.c (gui_message): use the new error dialog. * app/core/gimp-gui.c (gimp_message): substitue "GIMP" for a NULL domain. * app/widgets/gimperrorconsole.c (gimp_error_console_add): fail when being called with a NULL domain. --- ChangeLog | 32 +++- app/core/gimp-gui.c | 24 +-- app/dialogs/dialogs-constructors.c | 8 + app/dialogs/dialogs-constructors.h | 3 + app/dialogs/dialogs.c | 2 + app/gui/dialogs-constructors.c | 8 + app/gui/dialogs-constructors.h | 3 + app/gui/dialogs.c | 2 + app/gui/gui-vtable.c | 60 +++++--- app/gui/gui.c | 26 +++- app/widgets/Makefile.am | 2 + app/widgets/gimperrorconsole.c | 4 +- app/widgets/gimperrordialog.c | 235 +++++++++++++++++++++++++++++ app/widgets/gimperrordialog.h | 68 +++++++++ app/widgets/gimpmessagebox.c | 40 +++++ app/widgets/gimpmessagebox.h | 5 +- app/widgets/gimpwidgets-utils.c | 199 +----------------------- app/widgets/gimpwidgets-utils.h | 6 - app/widgets/widgets-types.h | 1 + 19 files changed, 476 insertions(+), 252 deletions(-) create mode 100644 app/widgets/gimperrordialog.c create mode 100644 app/widgets/gimperrordialog.h diff --git a/ChangeLog b/ChangeLog index dcab33ab8e..4cddeefc3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,17 +1,39 @@ -2004-08-25 Bill Skaggs +2004-08-25 Sven Neumann - * devel-docs/Makefile.am: added ggr.txt to list. + * app/widgets/gimpmessagebox.[ch]: added gimp_message_box_repeat(). -2004-08-25 Bill Skaggs + * app/widgets/Makefile.am + * app/widgets/widgets-types.h + * app/widgets/gimperrordialog.[ch]: added new dialog that adds a new + GimpMessageBox for each message added. Fixes bug #92604. - * devel-docs/ggr.txt: added new file decribing the ggr - (Gimp gradient) file format. + * app/widgets/gimpwidgets-utils.[ch]: removed old gimp_message_box() + functionality. + + * app/gui/gui.c (gui_abort): use a GimpMessageBox in a GimpDialog. + + * app/gui/dialogs-constructors.[ch] + * app/gui/dialogs.c: manage GimpErrorDialog as singleton. + + * app/gui/gui-vtable.c (gui_message): use the new error dialog. + + * app/core/gimp-gui.c (gimp_message): substitue "GIMP" for a NULL + domain. + + * app/widgets/gimperrorconsole.c (gimp_error_console_add): fail + when being called with a NULL domain. 2004-08-25 DindinX * app/display/gimpnavigationeditor.[ch]: eradicate some more previews in favor of views. +2004-08-25 Bill Skaggs + + * devel-docs/Makefile.am + * devel-docs/ggr.txt: added new file decribing the ggr (Gimp + gradient) file format. + 2004-08-25 DindinX * app/display/gimpnavigationview.c diff --git a/app/core/gimp-gui.c b/app/core/gimp-gui.c index 9817802b61..f74d8abb64 100644 --- a/app/core/gimp-gui.c +++ b/app/core/gimp-gui.c @@ -144,25 +144,13 @@ gimp_message (Gimp *gimp, { g_return_if_fail (GIMP_IS_GIMP (gimp)); - if (! gimp->console_messages) - { - switch (gimp->message_handler) - { - case GIMP_MESSAGE_BOX: - case GIMP_ERROR_CONSOLE: - if (gimp->gui.message) - { - gimp->gui.message (gimp, domain, message); - return; - } - break; + if (! domain) + domain = _("GIMP"); - default: - break; - } - } - - g_printerr ("%s: %s\n\n", domain ? domain : _("GIMP"), message); + if (! gimp->console_messages && gimp->gui.message) + gimp->gui.message (gimp, domain, message); + else + g_printerr ("%s: %s\n\n", domain, message); } void diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c index e304b5aa29..3f26d804bb 100644 --- a/app/dialogs/dialogs-constructors.c +++ b/app/dialogs/dialogs-constructors.c @@ -49,6 +49,7 @@ #include "widgets/gimpdockable.h" #include "widgets/gimpdocumentview.h" #include "widgets/gimperrorconsole.h" +#include "widgets/gimperrordialog.h" #include "widgets/gimpfontview.h" #include "widgets/gimpgradienteditor.h" #include "widgets/gimphelp-ids.h" @@ -144,6 +145,13 @@ dialogs_about_get (GimpDialogFactory *factory, return about_dialog_create (); } +GtkWidget * +dialogs_error_get (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size) +{ + return gimp_error_dialog_new (_("GIMP Message"), GIMP_STOCK_WARNING); +} /***********/ /* docks */ diff --git a/app/dialogs/dialogs-constructors.h b/app/dialogs/dialogs-constructors.h index 9a72a43fdc..c0974299bd 100644 --- a/app/dialogs/dialogs-constructors.h +++ b/app/dialogs/dialogs-constructors.h @@ -37,6 +37,9 @@ GtkWidget * dialogs_tips_get (GimpDialogFactory *factory, GtkWidget * dialogs_about_get (GimpDialogFactory *factory, GimpContext *context, gint preview_size); +GtkWidget * dialogs_error_get (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size); /* docks */ diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c index be62c6b50e..f351aa7cb3 100644 --- a/app/dialogs/dialogs.c +++ b/app/dialogs/dialogs.c @@ -101,6 +101,8 @@ static const GimpDialogFactoryEntry toplevel_entries[] = { "gimp-tips-dialog", dialogs_tips_get, 0, TRUE, FALSE, FALSE, FALSE }, { "gimp-about-dialog", dialogs_about_get, + 0, TRUE, FALSE, FALSE, FALSE }, + { "gimp-error-dialog", dialogs_error_get, 0, TRUE, FALSE, FALSE, FALSE } }; diff --git a/app/gui/dialogs-constructors.c b/app/gui/dialogs-constructors.c index e304b5aa29..3f26d804bb 100644 --- a/app/gui/dialogs-constructors.c +++ b/app/gui/dialogs-constructors.c @@ -49,6 +49,7 @@ #include "widgets/gimpdockable.h" #include "widgets/gimpdocumentview.h" #include "widgets/gimperrorconsole.h" +#include "widgets/gimperrordialog.h" #include "widgets/gimpfontview.h" #include "widgets/gimpgradienteditor.h" #include "widgets/gimphelp-ids.h" @@ -144,6 +145,13 @@ dialogs_about_get (GimpDialogFactory *factory, return about_dialog_create (); } +GtkWidget * +dialogs_error_get (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size) +{ + return gimp_error_dialog_new (_("GIMP Message"), GIMP_STOCK_WARNING); +} /***********/ /* docks */ diff --git a/app/gui/dialogs-constructors.h b/app/gui/dialogs-constructors.h index 9a72a43fdc..c0974299bd 100644 --- a/app/gui/dialogs-constructors.h +++ b/app/gui/dialogs-constructors.h @@ -37,6 +37,9 @@ GtkWidget * dialogs_tips_get (GimpDialogFactory *factory, GtkWidget * dialogs_about_get (GimpDialogFactory *factory, GimpContext *context, gint preview_size); +GtkWidget * dialogs_error_get (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size); /* docks */ diff --git a/app/gui/dialogs.c b/app/gui/dialogs.c index be62c6b50e..f351aa7cb3 100644 --- a/app/gui/dialogs.c +++ b/app/gui/dialogs.c @@ -101,6 +101,8 @@ static const GimpDialogFactoryEntry toplevel_entries[] = { "gimp-tips-dialog", dialogs_tips_get, 0, TRUE, FALSE, FALSE, FALSE }, { "gimp-about-dialog", dialogs_about_get, + 0, TRUE, FALSE, FALSE, FALSE }, + { "gimp-error-dialog", dialogs_error_get, 0, TRUE, FALSE, FALSE, FALSE } }; diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c index 8b80ed5c0f..0617a5c2f4 100644 --- a/app/gui/gui-vtable.c +++ b/app/gui/gui-vtable.c @@ -48,6 +48,7 @@ #include "widgets/gimpbrushselect.h" #include "widgets/gimpdialogfactory.h" #include "widgets/gimperrorconsole.h" +#include "widgets/gimperrordialog.h" #include "widgets/gimpfontselect.h" #include "widgets/gimpgradientselect.h" #include "widgets/gimphelp.h" @@ -57,7 +58,6 @@ #include "widgets/gimppatternselect.h" #include "widgets/gimpprogressdialog.h" #include "widgets/gimpuimanager.h" -#include "widgets/gimpwidgets-utils.h" #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" @@ -199,29 +199,55 @@ gui_message (Gimp *gimp, const gchar *domain, const gchar *message) { - if (gimp->message_handler == GIMP_ERROR_CONSOLE) + switch (gimp->message_handler) { - GtkWidget *dockable; + case GIMP_ERROR_CONSOLE: + { + GtkWidget *dockable; - dockable = gimp_dialog_factory_dialog_raise (global_dock_factory, + dockable = gimp_dialog_factory_dialog_raise (global_dock_factory, + gdk_screen_get_default (), + "gimp-error-console", -1); + + if (dockable) + { + GimpErrorConsole *console; + + console = GIMP_ERROR_CONSOLE (GTK_BIN (dockable)->child); + + gimp_error_console_add (console, + GIMP_STOCK_WARNING, domain, message); + + return; + } + + gimp->message_handler = GIMP_MESSAGE_BOX; + } + /* fallthru */ + + case GIMP_MESSAGE_BOX: + { + GtkWidget *dialog; + + dialog = gimp_dialog_factory_dialog_raise (global_dialog_factory, gdk_screen_get_default (), - "gimp-error-console", -1); + "gimp-error-dialog", -1); + if (dialog) + { + gimp_error_dialog_add (GIMP_ERROR_DIALOG (dialog), + GIMP_STOCK_WARNING, domain, message); - if (dockable) - { - GimpErrorConsole *console; + return; + } - console = GIMP_ERROR_CONSOLE (GTK_BIN (dockable)->child); + gimp->message_handler = GIMP_CONSOLE; + } + /* fallthru */ - gimp_error_console_add (console, GIMP_STOCK_WARNING, domain, message); - - return; - } - - gimp->message_handler = GIMP_MESSAGE_BOX; + case GIMP_CONSOLE: + g_printerr ("%s: %s\n\n", domain, message); + break; } - - gimp_message_box (GIMP_STOCK_WARNING, domain, message, NULL, NULL); } void diff --git a/app/gui/gui.c b/app/gui/gui.c index 1858c2ef58..3d24d0a712 100644 --- a/app/gui/gui.c +++ b/app/gui/gui.c @@ -54,6 +54,7 @@ #include "widgets/gimphelp.h" #include "widgets/gimphelp-ids.h" #include "widgets/gimpmenufactory.h" +#include "widgets/gimpmessagebox.h" #include "widgets/gimpsessioninfo.h" #include "widgets/gimpuimanager.h" #include "widgets/gimpwidgets-utils.h" @@ -149,11 +150,30 @@ gui_libs_init (gint *argc, void gui_abort (const gchar *abort_message) { + GtkWidget *dialog; + GtkWidget *box; + g_return_if_fail (abort_message != NULL); - gimp_message_box (GIMP_STOCK_WILBER_EEK, NULL, abort_message, - (GtkCallback) gtk_main_quit, NULL); - gtk_main (); + dialog = gimp_dialog_new (_("GIMP Message"), "gimp-abort", + NULL, GTK_DIALOG_MODAL, NULL, NULL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + + box = g_object_new (GIMP_TYPE_MESSAGE_BOX, + "stock_id", GIMP_STOCK_WILBER_EEK, + "border_width", 12, + NULL); + + gimp_message_box_set_text (GIMP_MESSAGE_BOX (box), abort_message); + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box); + gtk_widget_show (box); + + gimp_dialog_run (GIMP_DIALOG (dialog)); + exit (EXIT_FAILURE); } diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am index 494814626e..4574e1c1f9 100644 --- a/app/widgets/Makefile.am +++ b/app/widgets/Makefile.am @@ -131,6 +131,8 @@ libappwidgets_a_sources = \ gimpenumwidgets.h \ gimperrorconsole.c \ gimperrorconsole.h \ + gimperrordialog.c \ + gimperrordialog.h \ gimpfgbgeditor.c \ gimpfgbgeditor.h \ gimpfiledialog.c \ diff --git a/app/widgets/gimperrorconsole.c b/app/widgets/gimperrorconsole.c index 0096b436fb..83a2ae967c 100644 --- a/app/widgets/gimperrorconsole.c +++ b/app/widgets/gimperrorconsole.c @@ -254,11 +254,9 @@ gimp_error_console_add (GimpErrorConsole *console, g_return_if_fail (GIMP_IS_ERROR_CONSOLE (console)); g_return_if_fail (stock_id != NULL); + g_return_if_fail (domain != NULL); g_return_if_fail (message != NULL); - if (! domain) - domain = _("GIMP"); - gtk_text_buffer_get_end_iter (console->text_buffer, &end); pixbuf = gtk_widget_render_icon (console->text_view, stock_id, diff --git a/app/widgets/gimperrordialog.c b/app/widgets/gimperrordialog.c new file mode 100644 index 0000000000..0000c47541 --- /dev/null +++ b/app/widgets/gimperrordialog.c @@ -0,0 +1,235 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimperrordialog.c + * Copyright (C) 2004 Sven Neumann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "widgets-types.h" + +#include "gimperrordialog.h" +#include "gimpmessagebox.h" + +#include "gimp-intl.h" + + +static void gimp_error_dialog_class_init (GimpErrorDialogClass *klass); +static void gimp_error_dialog_init (GimpErrorDialog *dialog); +static void gimp_error_dialog_finalize (GObject *object); +static void gimp_error_dialog_response (GtkDialog *dialog, + gint response_id); + + +static GimpDialogClass *parent_class = NULL; + + +GType +gimp_error_dialog_get_type (void) +{ + static GType dialog_type = 0; + + if (! dialog_type) + { + static const GTypeInfo dialog_info = + { + sizeof (GimpErrorDialogClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_error_dialog_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpErrorDialog), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_error_dialog_init + }; + + dialog_type = g_type_register_static (GIMP_TYPE_DIALOG, + "GimpErrorDialog", + &dialog_info, 0); + } + + return dialog_type; +} + +static void +gimp_error_dialog_class_init (GimpErrorDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = gimp_error_dialog_finalize; + + dialog_class->response = gimp_error_dialog_response; +} + +static void +gimp_error_dialog_init (GimpErrorDialog *dialog) +{ + gtk_window_set_role (GTK_WINDOW (dialog), "gimp-message"); + + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_OK, GTK_RESPONSE_CLOSE, + NULL); + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); + + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + + dialog->vbox = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), + dialog->vbox, TRUE, TRUE, 0); + gtk_widget_show (dialog->vbox); +} + +static void +gimp_error_dialog_finalize (GObject *object) +{ + GimpErrorDialog *dialog = GIMP_ERROR_DIALOG (object); + + if (dialog->last_domain) + { + g_free (dialog->last_domain); + dialog->last_domain = NULL; + } + if (dialog->last_message) + { + g_free (dialog->last_message); + dialog->last_message = NULL; + } + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +gimp_error_dialog_response (GtkDialog *dialog, + gint response_id) +{ + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + + +static void +gimp_error_dialog_set_icon (GtkWidget *dialog, + const gchar *stock_id) +{ + GtkIconSet *icon_set; + + gtk_widget_ensure_style (dialog); + + icon_set = gtk_style_lookup_icon_set (dialog->style, stock_id); + + if (icon_set) + { + GtkIconSize *sizes; + GList *icons = NULL; + gint i, n_sizes; + + gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes); + + for (i = 0; i < n_sizes; i++) + { + if (sizes[i] < GTK_ICON_SIZE_DIALOG) /* skip the large version */ + icons = g_list_prepend (icons, + gtk_widget_render_icon (dialog, + stock_id, sizes[i], + NULL)); + } + + g_free (sizes); + + if (icons) + { + gtk_window_set_icon_list (GTK_WINDOW (dialog), icons); + + g_list_foreach (icons, (GFunc) g_object_unref, NULL); + g_list_free (icons); + } + } +} + + +/* public functions */ + +GtkWidget * +gimp_error_dialog_new (const gchar *title, + const gchar *stock_id) +{ + GtkWidget *dialog; + + g_return_val_if_fail (title != NULL, NULL); + + dialog = g_object_new (GIMP_TYPE_ERROR_DIALOG, + "title", title, + NULL); + + if (stock_id) + gimp_error_dialog_set_icon (dialog, stock_id); + + return dialog; +} + +gboolean +gimp_error_dialog_add (GimpErrorDialog *dialog, + const gchar *stock_id, + const gchar *domain, + const gchar *message) +{ + g_return_val_if_fail (GIMP_IS_ERROR_DIALOG (dialog), FALSE); + g_return_val_if_fail (domain != NULL, FALSE); + g_return_val_if_fail (message != NULL, FALSE); + + if (dialog->last_box && + dialog->last_domain && strcmp (dialog->last_domain, domain) == 0 && + dialog->last_message && strcmp (dialog->last_message, message) == 0) + { + gimp_message_box_repeat (GIMP_MESSAGE_BOX (dialog->last_box)); + } + else + { + GtkWidget *box = g_object_new (GIMP_TYPE_MESSAGE_BOX, + "stock_id", GIMP_STOCK_WARNING, + "border_width", 12, + NULL); + + gimp_message_box_set_primary_text (GIMP_MESSAGE_BOX (box), + _("%s Message"), domain); + gimp_message_box_set_text (GIMP_MESSAGE_BOX (box), message); + + gtk_container_add (GTK_CONTAINER (dialog->vbox), box); + gtk_widget_show (box); + + dialog->last_box = box; + + g_free (dialog->last_domain); + dialog->last_domain = g_strdup (domain); + + g_free (dialog->last_message); + dialog->last_message = g_strdup (message); + } + + return TRUE; +} diff --git a/app/widgets/gimperrordialog.h b/app/widgets/gimperrordialog.h new file mode 100644 index 0000000000..6fa7a52c1e --- /dev/null +++ b/app/widgets/gimperrordialog.h @@ -0,0 +1,68 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimperrordialog.c + * Copyright (C) 2004 Sven Neumann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_ERROR_DIALOG_H__ +#define __GIMP_ERROR_DIALOG_H__ + +G_BEGIN_DECLS + + +#define GIMP_TYPE_ERROR_DIALOG (gimp_error_dialog_get_type ()) +#define GIMP_ERROR_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ERROR_DIALOG, GimpErrorDialog)) +#define GIMP_ERROR_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ERROR_DIALOG, GimpErrorDialogClass)) +#define GIMP_IS_ERROR_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ERROR_DIALOG)) +#define GIMP_IS_ERROR_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ERROR_DIALOG)) +#define GIMP_ERROR_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ERROR_DIALOG, GimpErrorDialogClass)) + + +typedef struct _GimpErrorDialogClass GimpErrorDialogClass; + +struct _GimpErrorDialog +{ + GimpDialog parent_instance; + + GtkWidget *vbox; + + GtkWidget *last_box; + gchar *last_domain; + gchar *last_message; +}; + +struct _GimpErrorDialogClass +{ + GimpDialogClass parent_class; +}; + + +GType gimp_error_dialog_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_error_dialog_new (const gchar *title, + const gchar *stock_id); +gboolean gimp_error_dialog_add (GimpErrorDialog *dialog, + const gchar *stock_id, + const gchar *domain, + const gchar *message); + + + +G_END_DECLS + +#endif /* __GIMP_ERROR_DIALOG_H__ */ diff --git a/app/widgets/gimpmessagebox.c b/app/widgets/gimpmessagebox.c index 395e62a0d3..39706fb240 100644 --- a/app/widgets/gimpmessagebox.c +++ b/app/widgets/gimpmessagebox.c @@ -29,6 +29,8 @@ #include "gimpmessagebox.h" +#include "gimp-intl.h" + #define GIMP_MESSAGE_BOX_SPACING 12 @@ -154,6 +156,9 @@ gimp_message_box_init (GimpMessageBox *box) box->label[i] = label; } + + box->repeat = 0; + box->label[2] = NULL; } static void @@ -438,3 +443,38 @@ gimp_message_box_set_markup (GimpMessageBox *box, gimp_message_box_set_label_markup (box, 1,format, args); va_end (args); } + +gint +gimp_message_box_repeat (GimpMessageBox *box) +{ + gchar *message; + + g_return_val_if_fail (GIMP_IS_MESSAGE_BOX (box), 0); + + box->repeat++; + + if (box->repeat > 1) + message = g_strdup_printf (_("Message repeated %d times."), box->repeat); + else + message = g_strdup (_("Message repeated once.")); + + if (box->label[2]) + { + gtk_label_set_text (GTK_LABEL (box->label[2]), message); + } + else + { + GtkWidget *label = box->label[2] = gtk_label_new (message); + + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0); + gimp_label_set_attributes (GTK_LABEL (label), + PANGO_ATTR_STYLE, PANGO_STYLE_OBLIQUE, + -1); + gtk_box_pack_end (GTK_BOX (box), label, FALSE, FALSE, 0); + gtk_widget_show (label); + } + + g_free (message); + + return box->repeat; +} diff --git a/app/widgets/gimpmessagebox.h b/app/widgets/gimpmessagebox.h index 8d8a935966..503c7c8635 100644 --- a/app/widgets/gimpmessagebox.h +++ b/app/widgets/gimpmessagebox.h @@ -40,8 +40,8 @@ struct _GimpMessageBox GtkVBox parent_instance; gchar *stock_id; - - GtkWidget *label[2]; + gint repeat; + GtkWidget *label[3]; GtkWidget *image; }; @@ -63,6 +63,7 @@ void gimp_message_box_set_text (GimpMessageBox *box, void gimp_message_box_set_markup (GimpMessageBox *box, const gchar *format, ...); +gint gimp_message_box_repeat (GimpMessageBox *box); G_END_DECLS diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c index cdc4d1421b..82e5e48ecd 100644 --- a/app/widgets/gimpwidgets-utils.c +++ b/app/widgets/gimpwidgets-utils.c @@ -31,209 +31,12 @@ #include "widgets-types.h" -#include "gimpmessagebox.h" +#include "gimperrordialog.h" #include "gimpwidgets-utils.h" #include "gimp-intl.h" -/* - * Message Boxes... - */ - -typedef struct _MessageBox MessageBox; - -struct _MessageBox -{ - GtkWidget *dialog; - GtkWidget *box; - GtkWidget *repeat_label; - gchar *domain; - gchar *message; - gint repeat_count; - GtkCallback callback; - gpointer data; -}; - -/* the maximum number of concurrent dialog boxes */ -#define MESSAGE_BOX_MAXIMUM 4 - - -static void gimp_message_box_set_icons (GtkWidget *dialog, - const gchar *stock_id); -static void gimp_message_box_response (GtkWidget *widget, - gint response_id, - MessageBox *msg_box); - - -static GList *message_boxes = NULL; - - -void -gimp_message_box (const gchar *stock_id, - const gchar *domain, - const gchar *message, - GtkCallback callback, - gpointer data) -{ - MessageBox *msg_box; - GtkWidget *dialog; - GtkWidget *box; - GList *list; - - g_return_if_fail (stock_id != NULL); - g_return_if_fail (message != NULL); - - if (! domain) - domain = _("GIMP"); - - if (g_list_length (message_boxes) > MESSAGE_BOX_MAXIMUM) - { - g_printerr ("%s: %s\n\n", domain, message); - return; - } - - for (list = message_boxes; list; list = list->next) - { - msg_box = list->data; - - if (strcmp (msg_box->message, message) == 0 && - strcmp (msg_box->domain, domain) == 0) - { - msg_box->repeat_count++; - - if (msg_box->repeat_count > 1) - { - gchar *text = g_strdup_printf (_("Message repeated %d times."), - msg_box->repeat_count); - gtk_label_set_text (GTK_LABEL (msg_box->repeat_label), text); - g_free (text); - } - else - { - GtkWidget *label; - - label = gtk_label_new (_("Message repeated once.")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gimp_label_set_attributes (GTK_LABEL (label), - PANGO_ATTR_STYLE, PANGO_STYLE_OBLIQUE, - -1); - gtk_box_pack_end (GTK_BOX (msg_box->box), label, FALSE, FALSE, 0); - gtk_widget_show (label); - - msg_box->repeat_label = label; - } - - gtk_window_present (GTK_WINDOW (msg_box->dialog)); - return; - } - } - - if (g_list_length (message_boxes) == MESSAGE_BOX_MAXIMUM) - { - g_printerr ("%s: %s\n\n", domain, message); - message = _("WARNING:\n" - "Too many open message dialogs.\n" - "Messages are redirected to stderr."); - } - - msg_box = g_new0 (MessageBox, 1); - - dialog = gimp_dialog_new (_("GIMP Message"), "gimp-message", - NULL, 0, - NULL, NULL, - - GTK_STOCK_OK, GTK_RESPONSE_CLOSE, - - NULL); - - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - - gimp_message_box_set_icons (dialog, stock_id); - - g_signal_connect (dialog, "response", - G_CALLBACK (gimp_message_box_response), - msg_box); - - box = gimp_message_box_new (stock_id); - gimp_message_box_set_primary_text (GIMP_MESSAGE_BOX (box), - _("%s Message"), domain); - gimp_message_box_set_text (GIMP_MESSAGE_BOX (box), message); - - gtk_container_set_border_width (GTK_CONTAINER (box), 12); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box); - gtk_widget_show (box); - - msg_box->dialog = dialog; - msg_box->box = box; - msg_box->domain = g_strdup (domain); - msg_box->message = g_strdup (message); - msg_box->callback = callback; - msg_box->data = data; - - message_boxes = g_list_prepend (message_boxes, msg_box); - - gtk_widget_show (dialog); -} - -static void -gimp_message_box_set_icons (GtkWidget *dialog, - const gchar *stock_id) -{ - GtkIconSet *icon_set; - GtkIconSize *sizes; - GList *icons = NULL; - gint i, n_sizes; - - gtk_widget_ensure_style (dialog); - - icon_set = gtk_style_lookup_icon_set (dialog->style, stock_id); - - if (icon_set == NULL) - return; - - gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes); - - for (i = 0; i < n_sizes; i++) - { - if (sizes[i] < GTK_ICON_SIZE_DIALOG) /* skip the large version */ - icons = g_list_prepend (icons, - gtk_widget_render_icon (dialog, - stock_id, sizes[i], - NULL)); - } - - g_free (sizes); - - if (icons) - { - gtk_window_set_icon_list (GTK_WINDOW (dialog), icons); - - g_list_foreach (icons, (GFunc) g_object_unref, NULL); - g_list_free (icons); - } -} - -static void -gimp_message_box_response (GtkWidget *widget, - gint resonse_id, - MessageBox *msg_box) -{ - /* If there is a valid callback, invoke it */ - if (msg_box->callback) - (* msg_box->callback) (widget, msg_box->data); - - /* Destroy the box */ - gtk_widget_destroy (msg_box->dialog); - - /* make this box available again */ - message_boxes = g_list_remove (message_boxes, msg_box); - - g_free (msg_box->domain); - g_free (msg_box->message); - g_free (msg_box); -} - /** * gimp_menu_position: * @menu: a #GtkMenu widget diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h index df2af53dd1..8dce61fe6d 100644 --- a/app/widgets/gimpwidgets-utils.h +++ b/app/widgets/gimpwidgets-utils.h @@ -23,12 +23,6 @@ #define __GIMP_WIDGETS_UTILS_H__ -void gimp_message_box (const gchar *stock_id, - const gchar *domain, - const gchar *message, - GtkCallback callback, - gpointer data); - void gimp_menu_position (GtkMenu *menu, gint *x, gint *y); diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h index 1fa4d551d8..ad4b70c1dd 100644 --- a/app/widgets/widgets-types.h +++ b/app/widgets/widgets-types.h @@ -122,6 +122,7 @@ typedef struct _GimpUIManager GimpUIManager; /* misc dialogs */ +typedef struct _GimpErrorDialog GimpErrorDialog; typedef struct _GimpFileDialog GimpFileDialog; typedef struct _GimpProgressDialog GimpProgressDialog; typedef struct _GimpTextEditor GimpTextEditor;