From 4b5a63caf26768a28d69a6b937dbb8372ce491b8 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 23 Mar 2009 17:22:18 +0900 Subject: [PATCH] Show error dialog if syntax file is not readable. Popup a dialog box, if a syntax file cannot be opened for any reason. --- src/ui/gui/psppire-syntax-window.c | 33 ++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 03b4093bbb..053dc227f0 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -552,6 +552,30 @@ psppire_syntax_window_new (void) NULL)); } +static void +error_dialog (GtkWindow *w, const gchar *filename, GError *err) +{ + gchar *fn = g_filename_display_basename (filename); + + GtkWidget *dialog = + gtk_message_dialog_new (w, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Cannot load syntax file '%s'"), + fn); + + g_free (fn); + + g_object_set (dialog, "icon-name", "psppicon", NULL); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + err->message); + + gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); +} /* Loads the buffer from the file called FILENAME @@ -559,13 +583,18 @@ psppire_syntax_window_new (void) static gboolean syntax_load (PsppireWindow *window, const gchar *filename) { + GError *err = NULL; gchar *text; GtkTextIter iter; PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window); /* FIXME: What if it's a very big file ? */ - if ( ! g_file_get_contents (filename, &text, NULL, NULL) ) - return FALSE; + if ( ! g_file_get_contents (filename, &text, NULL, &err) ) + { + error_dialog (GTK_WINDOW (window), filename, err); + g_clear_error (&err); + return FALSE; + } gtk_text_buffer_get_iter_at_line (sw->buffer, &iter, 0); -- 2.30.2