Show error dialog if syntax file is not readable.
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 23 Mar 2009 08:22:18 +0000 (17:22 +0900)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 23 Mar 2009 08:22:18 +0000 (17:22 +0900)
Popup a dialog box, if a syntax file cannot be
opened for any reason.

src/ui/gui/psppire-syntax-window.c

index 03b4093bbba6eb930b3c5e3f27efc7b44b7e6e3e..053dc227f0a733f40db3208d16d7aef4495b3bdc 100644 (file)
@@ -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);