/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2012, 2014 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
#include <gtksourceview/gtksourcelanguagemanager.h>
#include <gtksourceview/gtksourceprintcompositor.h>
-
#include "language/lexer/lexer.h"
#include "libpspp/encoding-guesser.h"
#include "libpspp/i18n.h"
#include "ui/gui/executor.h"
#include "ui/gui/help-menu.h"
#include "ui/gui/helper.h"
+#include "ui/gui/builder-wrapper.h"
#include "ui/gui/psppire-data-window.h"
#include "ui/gui/psppire-encoding-selector.h"
-#include "ui/gui/psppire-syntax-window.h"
+#include "ui/gui/psppire-lex-reader.h"
#include "ui/gui/psppire-syntax-window.h"
#include "ui/gui/psppire-window-register.h"
#include "ui/gui/psppire.h"
-#include "ui/gui/psppire.h"
#include "gl/localcharset.h"
#include "gl/xalloc.h"
GtkTextIter stop)
{
PsppireWindow *win = PSPPIRE_WINDOW (sw);
- struct lex_reader *reader;
- gchar *text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (sw->buffer), &start, &stop, FALSE);
- reader = lex_reader_for_string (text);
- g_free (text);
+ struct lex_reader *reader = lex_reader_for_gtk_text_buffer (GTK_TEXT_BUFFER (sw->buffer), start, stop);
lex_reader_set_file_name (reader, psppire_window_get_filename (win));
GtkSelectionData *sd,
gpointer data)
{
- gchar *c;
PsppireSyntaxWindow *syntax_window = data;
if ( sd->length < 0 )
if ( sd->type != gdk_atom_intern ("UTF8_STRING", FALSE))
return;
- c = (gchar *) sd->data;
-
gtk_text_buffer_insert_at_cursor (GTK_TEXT_BUFFER (syntax_window->buffer),
(gchar *) sd->data,
sd->length);
static void
-load_and_show_syntax_window (GtkWidget *se, const gchar *filename)
+load_and_show_syntax_window (GtkWidget *se, const gchar *filename,
+ const gchar *encoding)
{
gboolean ok;
gtk_source_buffer_begin_not_undoable_action (PSPPIRE_SYNTAX_WINDOW (se)->buffer);
- ok = psppire_window_load (PSPPIRE_WINDOW (se), filename);
+ ok = psppire_window_load (PSPPIRE_WINDOW (se), filename, encoding, NULL);
gtk_source_buffer_end_not_undoable_action (PSPPIRE_SYNTAX_WINDOW (se)->buffer);
if (ok )
void
open_syntax_window (const char *file_name, const gchar *encoding)
{
- GtkWidget *se = psppire_syntax_window_new (encoding);
+ GtkWidget *se = psppire_syntax_window_new (NULL);
if ( file_name)
- load_and_show_syntax_window (se, file_name);
+ load_and_show_syntax_window (se, file_name, encoding);
}
g_free (fn);
- g_object_set (dialog, "icon-name", "psppicon", NULL);
+ g_object_set (dialog, "icon-name", "pspp", NULL);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", err->message);
Loads the buffer from the file called FILENAME
*/
gboolean
-syntax_load (PsppireWindow *window, const gchar *filename)
+syntax_load (PsppireWindow *window, const gchar *filename,
+ const gchar *encoding, gpointer not_used)
{
GError *err = NULL;
gchar *text_locale = NULL;
GtkTextIter iter;
PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window);
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (sw->buffer);
- gchar *encoding;
- char *mime_type;
/* FIXME: What if it's a very big file ? */
if ( ! g_file_get_contents (filename, &text_locale, &len_locale, &err) )
return FALSE;
}
- /* Determine the file's encoding and update sw->encoding. (The ordering is
- important here because encoding_guess_whole_file() often returns its
- argument instead of a copy of it.) */
- encoding = g_strdup (encoding_guess_whole_file (sw->encoding, text_locale,
- len_locale));
- g_free (sw->encoding);
- sw->encoding = encoding;
+ if (!encoding || !encoding[0])
+ {
+ /* Determine the file's encoding and update sw->encoding. (The ordering
+ is important here because encoding_guess_whole_file() often returns
+ its argument instead of a copy of it.) */
+ char *guessed_encoding;
+
+ guessed_encoding = g_strdup (encoding_guess_whole_file (sw->encoding,
+ text_locale,
+ len_locale));
+ g_free (sw->encoding);
+ sw->encoding = guessed_encoding;
+ }
+ else
+ {
+ g_free (sw->encoding);
+ sw->encoding = g_strdup (encoding);
+ }
text_utf8 = recode_substring_pool ("UTF-8", encoding,
ss_buffer (text_locale, len_locale),
free (text_utf8);
- mime_type = xasprintf ("text/x-spss-syntax; charset=%s", sw->encoding);
- add_most_recent (filename, mime_type);
- free (mime_type);
+ add_most_recent (filename, "text/x-spss-syntax", sw->encoding);
return TRUE;
}