Allow non-ascii characters to be entered as variable names.
[pspp-builds.git] / src / ui / gui / psppire-syntax-window.c
index b735f35cb241088b58a5ebb5fe1b120d3d0cd524..053dc227f0a733f40db3208d16d7aef4495b3bdc 100644 (file)
@@ -395,12 +395,10 @@ open_syntax_window (GtkMenuItem *menuitem, gpointer parent)
 
       GtkWidget *se = psppire_syntax_window_new ();
 
-      if ( psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file_name, NULL) )
-       {
-         add_most_recent (file_name, the_recent_mgr);
-       }
-
-      gtk_widget_show (se);
+      if ( psppire_window_load (PSPPIRE_WINDOW (se), file_name) ) 
+       gtk_widget_show (se);
+      else
+       gtk_widget_destroy (se);
     }
 
   gtk_widget_destroy (dialog);
@@ -416,10 +414,10 @@ on_text_changed (GtkTextBuffer *buffer, PsppireSyntaxWindow *window)
 static void
 on_modified_changed (GtkTextBuffer *buffer, PsppireWindow *window)
 {
-  psppire_window_set_unsaved (window, gtk_text_buffer_get_modified (buffer));
+  if (gtk_text_buffer_get_modified (buffer))
+    psppire_window_set_unsaved (window);
 }
 
-
 extern struct source_stream *the_source_stream ;
 
 static void
@@ -478,10 +476,15 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window)
                    window);
 #endif
 
-  g_signal_connect (get_action_assert (xml,"help_about"),
-                   "activate",
-                   G_CALLBACK (about_new),
-                   window);
+  {
+    GtkAction *abt = get_action_assert (xml, "help_about");
+    g_object_set (abt, "stock-id", "gtk-about", NULL);
+
+    g_signal_connect (abt,
+                     "activate",
+                     G_CALLBACK (about_new),
+                     window);
+  }
 
   g_signal_connect (get_action_assert (xml,"help_reference"),
                    "activate",
@@ -549,38 +552,55 @@ 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
 */
-gboolean
-psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se,
-                                     const gchar *filename,
-                                     GError **err)
+static gboolean
+syntax_load (PsppireWindow *window, const gchar *filename)
 {
+  GError *err = NULL;
   gchar *text;
   GtkTextIter iter;
-
-  gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err);
-
-  if ( ! glibfilename )
-    return FALSE;
+  PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window);
 
   /* FIXME: What if it's a very big file ? */
-  if ( ! g_file_get_contents (glibfilename, &text, NULL, err) )
+  if ( ! g_file_get_contents (filename, &text, NULL, &err) )
     {
-      g_free (glibfilename);
+      error_dialog (GTK_WINDOW (window), filename, err);
+      g_clear_error (&err);
       return FALSE;
     }
-  g_free (glibfilename);
-
-  gtk_text_buffer_get_iter_at_line (se->buffer, &iter, 0);
 
-  gtk_text_buffer_insert (se->buffer, &iter, text, -1);
+  gtk_text_buffer_get_iter_at_line (sw->buffer, &iter, 0);
 
-  psppire_window_set_filename (PSPPIRE_WINDOW (se), filename);
+  gtk_text_buffer_insert (sw->buffer, &iter, text, -1);
 
-  gtk_text_buffer_set_modified (se->buffer, FALSE);
+  gtk_text_buffer_set_modified (sw->buffer, FALSE);
 
   return TRUE;
 }
@@ -591,4 +611,5 @@ static void
 psppire_syntax_window_iface_init (PsppireWindowIface *iface)
 {
   iface->save = syntax_save;
+  iface->load = syntax_load;
 }