X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-syntax-window.c;h=48a77fc03ec21a7fa3f9cfc4a3ddc6cceedb3c4f;hb=54a782bed8c1d1c02b9d6cc192df5ec4840796df;hp=a5cc08aa93b9a711f84cca75894cef2b013b2ee4;hpb=917906bd153b0a915facd98ccf919db0150219f4;p=pspp-builds.git diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index a5cc08aa..48a77fc0 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008 Free Software Foundation + Copyright (C) 2008, 2009 Free Software Foundation 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 @@ -18,6 +18,7 @@ #include #include +#include "executor.h" #include "helper.h" #include @@ -34,6 +35,8 @@ #include "syntax-editor-source.h" #include +#include "xalloc.h" + #include #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -224,12 +227,13 @@ append_suffix (const gchar *filename) return g_strdup_printf ("%s.sps", filename); } - return strdup (filename); + return xstrdup (filename); } /* Save BUFFER to the file called FILENAME. - If successful, clears the buffer's modified flag + FILENAME must be encoded in Glib filename encoding. + If successful, clears the buffer's modified flag. */ static gboolean save_editor_to_file (PsppireSyntaxWindow *se, @@ -242,28 +246,24 @@ save_editor_to_file (PsppireSyntaxWindow *se, gchar *text; gchar *suffixedname; - gchar *glibfilename; g_assert (filename); suffixedname = append_suffix (filename); - glibfilename = g_filename_from_utf8 (suffixedname, -1, 0, 0, err); - - g_free ( suffixedname); - - if ( ! glibfilename ) - return FALSE; - gtk_text_buffer_get_iter_at_line (buffer, &start, 0); gtk_text_buffer_get_iter_at_offset (buffer, &stop, -1); text = gtk_text_buffer_get_text (buffer, &start, &stop, FALSE); - result = g_file_set_contents (glibfilename, text, -1, err); + result = g_file_set_contents (suffixedname, text, -1, err); + + g_free (suffixedname); if ( result ) { - gchar *msg = g_strdup_printf (_("Saved file \"%s\""), filename); + char *fn = g_filename_display_name (filename); + gchar *msg = g_strdup_printf (_("Saved file \"%s\""), fn); + g_free (fn); gtk_statusbar_push (GTK_STATUSBAR (se->sb), se->text_context, msg); gtk_text_buffer_set_modified (buffer, FALSE); g_free (msg); @@ -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,30 +583,23 @@ 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); - gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, NULL); - - if ( ! glibfilename ) - return FALSE; - /* FIXME: What if it's a very big file ? */ - if ( ! g_file_get_contents (glibfilename, &text, NULL, NULL) ) + 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 (sw->buffer, &iter, 0); gtk_text_buffer_insert (sw->buffer, &iter, text, -1); - psppire_window_set_filename (window, filename); - gtk_text_buffer_set_modified (sw->buffer, FALSE); return TRUE;