X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-syntax-window.c;h=f9fe53ccc60268712d584ce981c1128baa7e4558;hb=0f8c9c6c05632de5cadc70ca5381c1d9cb46960e;hp=48e1ea44fe73d3873c4631d6e5b4bc06311e4636;hpb=9389f9870643a519cf69b84a9388a0a40315d903;p=pspp diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 48e1ea44fe..f9fe53ccc6 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -545,12 +545,26 @@ gboolean syntax_load (PsppireWindow *window, const gchar *filename) { GError *err = NULL; - gchar *text; + gchar *text_locale = NULL; + gchar *text_utf8 = NULL; + gsize len_locale = -1; + gsize len_utf8 = -1; 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, &err) ) + if ( ! g_file_get_contents (filename, &text_locale, &len_locale, &err) ) + { + error_dialog (GTK_WINDOW (window), filename, err); + g_clear_error (&err); + return FALSE; + } + + text_utf8 = g_locale_to_utf8 (text_locale, len_locale, NULL, &len_utf8, &err); + + free (text_locale); + + if ( text_utf8 == NULL ) { error_dialog (GTK_WINDOW (window), filename, err); g_clear_error (&err); @@ -559,10 +573,12 @@ syntax_load (PsppireWindow *window, const gchar *filename) gtk_text_buffer_get_iter_at_line (sw->buffer, &iter, 0); - gtk_text_buffer_insert (sw->buffer, &iter, text, -1); + gtk_text_buffer_insert (sw->buffer, &iter, text_utf8, len_utf8); gtk_text_buffer_set_modified (sw->buffer, FALSE); + free (text_utf8); + return TRUE; }