gui: Fix File|Open in syntax editor.
[pspp-builds.git] / src / ui / gui / psppire-syntax-window.c
index 1d78881904f3ef52239c303e419c5eea2a6f7f28..2e90ba76535ac69733731a4207aaf69f38d23cc5 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2010  Free Software Foundation
+   Copyright (C) 2008, 2009, 2010, 2011  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 <config.h>
 
-#include <gtk/gtksignal.h>
-#include <gtk/gtkbox.h>
-#include "executor.h"
-#include "helper.h"
-
-#include <language/lexer/lexer.h>
-#include <libpspp/message.h>
+#include <gtk/gtk.h>
 #include <stdlib.h>
 
-#include "help-menu.h"
-#include "psppire.h"
-#include "psppire-data-window.h"
-#include "psppire-window-register.h"
-#include "psppire-syntax-window.h"
-#include "syntax-editor-source.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/message.h"
+#include "ui/gui/executor.h"
+#include "ui/gui/help-menu.h"
+#include "ui/gui/helper.h"
+#include "ui/gui/psppire-data-window.h"
+#include "ui/gui/psppire-syntax-window.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 "xalloc.h"
+#include "gl/xalloc.h"
 
 #include <gettext.h>
 #define _(msgid) gettext (msgid)
@@ -156,13 +155,18 @@ editor_execute_syntax (const PsppireSyntaxWindow *sw, GtkTextIter start,
                       GtkTextIter stop)
 {
   PsppireWindow *win = PSPPIRE_WINDOW (sw);
-  const gchar *name = psppire_window_get_filename (win);
-  execute_syntax (create_syntax_editor_source (sw->buffer, start, stop, name));
-}
+  struct lex_reader *reader;
+  gchar *text;
 
+  text = gtk_text_buffer_get_text (sw->buffer, &start, &stop, FALSE);
+  reader = lex_reader_for_string (text);
+  g_free (text);
 
-\f
+  lex_reader_set_file_name (reader, psppire_window_get_filename (win));
 
+  execute_syntax (psppire_default_data_window (), reader);
+}
+\f
 /* Delete the currently selected text */
 static void
 on_edit_delete (PsppireSyntaxWindow *sw)
@@ -590,8 +594,6 @@ on_modified_changed (GtkTextBuffer *buffer, PsppireWindow *window)
     psppire_window_set_unsaved (window);
 }
 
-extern struct source_stream *the_source_stream ;
-
 static void
 psppire_syntax_window_init (PsppireSyntaxWindow *window)
 {
@@ -616,7 +618,6 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window)
   window->edit_paste = get_action_assert (xml, "edit_paste");
 
   window->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
-  window->lexer = lex_create (the_source_stream);
 
   window->sb = get_widget_assert (xml, "statusbar2");
   window->text_context = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->sb), "Text Context");
@@ -658,6 +659,11 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window)
                    window);
 #endif
 
+  g_signal_connect_swapped (get_action_assert (xml, "file_open"),
+                   "activate",
+                   G_CALLBACK (psppire_window_open),
+                   window);
+
   g_signal_connect_swapped (get_action_assert (xml, "file_save"),
                    "activate",
                    G_CALLBACK (syntax_save),