X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-syntax-window.c;h=a61e56e583b7a045aabdc275c1ea9ab7813a2b05;hb=292700057732bffe0808f7ed862c04321e92eacf;hp=1d78881904f3ef52239c303e419c5eea2a6f7f28;hpb=52c400a0ac67e4a43c5cae5a0d40e1452326240c;p=pspp diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 1d78881904..a61e56e583 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, 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 @@ -16,23 +16,22 @@ #include -#include -#include -#include "executor.h" -#include "helper.h" - -#include -#include +#include #include -#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 #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); - + lex_reader_set_file_name (reader, psppire_window_get_filename (win)); + execute_syntax (psppire_default_data_window (), reader); +} + /* Delete the currently selected text */ static void on_edit_delete (PsppireSyntaxWindow *sw) @@ -479,9 +483,9 @@ save_editor_to_file (PsppireSyntaxWindow *se, } -/* Callback for the File->SaveAs menuitem */ +/* PsppireWindow 'pick_Filename' callback. */ static void -syntax_save_as (PsppireWindow *se) +syntax_pick_filename (PsppireWindow *se) { GtkFileFilter *filter; gint response; @@ -511,16 +515,9 @@ syntax_save_as (PsppireWindow *se) if ( response == GTK_RESPONSE_ACCEPT ) { - GError *err = NULL; char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog) ); - - if ( ! save_editor_to_file (PSPPIRE_SYNTAX_WINDOW (se), filename, &err) ) - { - msg ( ME, "%s", err->message ); - g_error_free (err); - } - + psppire_window_set_filename (se, filename); free (filename); } @@ -528,23 +525,17 @@ syntax_save_as (PsppireWindow *se) } -/* Callback for the File->Save menuitem */ +/* PsppireWindow 'save' callback. */ static void syntax_save (PsppireWindow *se) { const gchar *filename = psppire_window_get_filename (se); - - if ( filename == NULL ) - syntax_save_as (se); - else + GError *err = NULL; + save_editor_to_file (PSPPIRE_SYNTAX_WINDOW (se), filename, &err); + if ( err ) { - GError *err = NULL; - save_editor_to_file (PSPPIRE_SYNTAX_WINDOW (se), filename, &err); - if ( err ) - { - msg (ME, "%s", err->message); - g_error_free (err); - } + msg (ME, "%s", err->message); + g_error_free (err); } } @@ -590,8 +581,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 +605,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"); @@ -651,21 +639,24 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window) g_signal_connect_swapped (get_action_assert (xml,"file_new_syntax"), "activate", G_CALLBACK (create_syntax_window), NULL); -#if 0 g_signal_connect (get_action_assert (xml,"file_new_data"), "activate", G_CALLBACK (create_data_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), + G_CALLBACK (psppire_window_save), window); g_signal_connect_swapped (get_action_assert (xml, "file_save_as"), "activate", - G_CALLBACK (syntax_save_as), + G_CALLBACK (psppire_window_save_as), window); g_signal_connect (get_action_assert (xml,"file_quit"), @@ -739,7 +730,6 @@ psppire_syntax_window_new (void) { return GTK_WIDGET (g_object_new (psppire_syntax_window_get_type (), /* TRANSLATORS: This will form a filename. Please avoid whitespace. */ - "filename", _("Syntax"), "description", _("Syntax Editor"), NULL)); } @@ -819,6 +809,7 @@ static void psppire_syntax_window_iface_init (PsppireWindowIface *iface) { iface->save = syntax_save; + iface->pick_filename = syntax_pick_filename; iface->load = syntax_load; }