From b6af9a9d9695ec107fd52d49639cfb4cecd92602 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 11 Jul 2014 00:34:12 +0200 Subject: [PATCH] Refactor all `gtk_message_dialog()` calls to `ag_app_message_dialog()` --- src/ag-app.c | 10 ++-------- src/ag-window.c | 51 +++++++++++++++++-------------------------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/ag-app.c b/src/ag-app.c index eac86a1..d4b2ab2 100644 --- a/src/ag-app.c +++ b/src/ag-app.c @@ -223,18 +223,12 @@ show_help(const gchar *topic, GtkWindow *parent) } if (!gtk_show_uri(screen, uri, gtk_get_current_event_time(), &err)) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new( - parent, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + ag_app_message_dialog( + GTK_WIDGET(parent), GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, "Unable to display help: %s", err->message ); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); } g_free(uri); diff --git a/src/ag-window.c b/src/ag-window.c index 0b93e65..6cb9fb8 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -107,17 +107,11 @@ ag_window_save_as(AgWindow *window, GError **err) // We should never enter here, but who knows... if (priv->chart == NULL) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + ag_app_message_dialog( + GTK_WIDGET(window), GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, _("Chart cannot be calculated.") ); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); g_set_error( err, AG_WINDOW_ERROR, AG_WINDOW_ERROR_EMPTY_CHART, @@ -130,19 +124,13 @@ ag_window_save_as(AgWindow *window, GError **err) name = ag_chart_get_name(priv->chart); if ((name == NULL) || (*name == 0)) { - GtkWidget *dialog; - g_free(name); - dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + ag_app_message_dialog( + GTK_WIDGET(window), GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, _("You must enter a name before saving a chart.") ); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); g_set_error( err, AG_WINDOW_ERROR, AG_WINDOW_ERROR_NO_NAME, @@ -243,17 +231,11 @@ ag_window_export_svg(AgWindow *window, GError **err) // We should never enter here, but who knows... if (priv->chart == NULL) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + ag_app_message_dialog( + GTK_WIDGET(window), GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, _("Chart cannot be calculated.") ); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); g_set_error( err, AG_WINDOW_ERROR, AG_WINDOW_ERROR_EMPTY_CHART, @@ -266,13 +248,13 @@ ag_window_export_svg(AgWindow *window, GError **err) name = ag_chart_get_name(priv->chart); if ((name == NULL) || (*name == 0)) { - GtkWidget *dialog; - g_free(name); - dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You must enter a name before saving a chart.")); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + ag_app_message_dialog( + GTK_WIDGET(window), + GTK_MESSAGE_ERROR, + _("You must enter a name before saving a chart.") + ); g_set_error(err, AG_WINDOW_ERROR, AG_WINDOW_ERROR_NO_NAME, "No name specified"); return; @@ -561,11 +543,12 @@ ag_window_redraw_chart(AgWindow *window) gchar *svg_content = ag_chart_create_svg(priv->chart, NULL, &err); if (svg_content == NULL) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new(GTK_WINDOW(window), 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Unable to draw chart: %s", err->message); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + ag_app_message_dialog( + GTK_WIDGET(window), + GTK_MESSAGE_WARNING, + "Unable to draw chart: %s", + err->message + ); } else { webkit_web_view_load_html( WEBKIT_WEB_VIEW(priv->chart_web_view),