From: John Darrington Date: Sun, 17 Dec 2006 00:01:04 +0000 (+0000) Subject: Added the ability to run syntax from the syntax editor. X-Git-Tag: v0.6.0~630 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8a5c3b5634a6255d1e0a057fc47c5a931b8492a;p=pspp-builds.git Added the ability to run syntax from the syntax editor. --- diff --git a/po/de.po b/po/de.po index 1f761366..1232884e 100644 --- a/po/de.po +++ b/po/de.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: PSPP 0.4.2\n" "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n" -"POT-Creation-Date: 2006-12-16 13:22+0900\n" +"POT-Creation-Date: 2006-12-16 15:49+0900\n" "PO-Revision-Date: 2006-05-26 17:49+0800\n" "Last-Translator: John Darrington \n" "Language-Team: German \n" @@ -4165,8 +4165,8 @@ msgstr "" msgid "Style of bevel around the custom entry button" msgstr "" -#: src/ui/gui/menu-actions.c:63 src/ui/gui/syntax-editor.c:60 -#: src/ui/gui/syntax-editor.c:82 +#: src/ui/gui/menu-actions.c:63 src/ui/gui/syntax-editor.c:64 +#: src/ui/gui/syntax-editor.c:86 msgid "Untitled" msgstr "Unbetitelt" @@ -4186,8 +4186,8 @@ msgstr "Systemedatein (*.sav)" msgid "Portable Files (*.por) " msgstr "Tragbardatein (*.por)" -#: src/ui/gui/menu-actions.c:239 src/ui/gui/syntax-editor.c:121 -#: src/ui/gui/syntax-editor.c:377 +#: src/ui/gui/menu-actions.c:239 src/ui/gui/syntax-editor.c:125 +#: src/ui/gui/syntax-editor.c:416 msgid "All Files" msgstr "Alle Datei" @@ -4211,6 +4211,11 @@ msgstr "Datei Fehler" msgid "PSPP Error" msgstr "PSPP Fehler" +#: src/ui/gui/message-dialog.c:149 +#, c-format +msgid "%s (line %d) %s" +msgstr "" + #: src/ui/gui/missing-val-dialog.c:117 src/ui/gui/missing-val-dialog.c:162 msgid "Incorrect value for variable type" msgstr "Unpassend Wert für Variable" @@ -4219,7 +4224,7 @@ msgstr "Unpassend Wert für Variable" msgid "Incorrect range specification" msgstr "Falshe Spannweitebeschreibung" -#: src/ui/gui/psppire.c:71 +#: src/ui/gui/psppire.c:74 msgid "Sorry. The help system hasn't yet been implemented." msgstr "Es gibt noch nicht kein Helpsysteme. Schade!" @@ -4566,27 +4571,27 @@ msgstr "" msgid "Criteria" msgstr "" -#: src/ui/gui/syntax-editor.c:59 +#: src/ui/gui/syntax-editor.c:63 #, c-format msgid "Save contents of syntax editor to %s?" msgstr "" -#: src/ui/gui/syntax-editor.c:107 +#: src/ui/gui/syntax-editor.c:111 #, fuzzy msgid "Save Syntax" msgstr "Speichern unter" -#: src/ui/gui/syntax-editor.c:115 src/ui/gui/syntax-editor.c:371 +#: src/ui/gui/syntax-editor.c:119 src/ui/gui/syntax-editor.c:410 #, fuzzy msgid "Syntax Files (*.sps) " msgstr "Systemedatein (*.sav)" -#: src/ui/gui/syntax-editor.c:276 +#: src/ui/gui/syntax-editor.c:312 #, fuzzy, c-format msgid "%s --- PSPP Syntax Editor" msgstr "PSPP Dateiaufbereiter" -#: src/ui/gui/syntax-editor.c:363 +#: src/ui/gui/syntax-editor.c:402 msgid "Open Syntax" msgstr "" diff --git a/po/pspp.pot b/po/pspp.pot index 707b5310..63c5b73d 100644 --- a/po/pspp.pot +++ b/po/pspp.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n" -"POT-Creation-Date: 2006-12-16 13:22+0900\n" +"POT-Creation-Date: 2006-12-16 15:49+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4160,8 +4160,8 @@ msgstr "" msgid "Style of bevel around the custom entry button" msgstr "" -#: src/ui/gui/menu-actions.c:63 src/ui/gui/syntax-editor.c:60 -#: src/ui/gui/syntax-editor.c:82 +#: src/ui/gui/menu-actions.c:63 src/ui/gui/syntax-editor.c:64 +#: src/ui/gui/syntax-editor.c:86 msgid "Untitled" msgstr "" @@ -4181,8 +4181,8 @@ msgstr "" msgid "Portable Files (*.por) " msgstr "" -#: src/ui/gui/menu-actions.c:239 src/ui/gui/syntax-editor.c:121 -#: src/ui/gui/syntax-editor.c:377 +#: src/ui/gui/menu-actions.c:239 src/ui/gui/syntax-editor.c:125 +#: src/ui/gui/syntax-editor.c:416 msgid "All Files" msgstr "" @@ -4206,6 +4206,11 @@ msgstr "" msgid "PSPP Error" msgstr "" +#: src/ui/gui/message-dialog.c:149 +#, c-format +msgid "%s (line %d) %s" +msgstr "" + #: src/ui/gui/missing-val-dialog.c:117 src/ui/gui/missing-val-dialog.c:162 msgid "Incorrect value for variable type" msgstr "" @@ -4214,7 +4219,7 @@ msgstr "" msgid "Incorrect range specification" msgstr "" -#: src/ui/gui/psppire.c:71 +#: src/ui/gui/psppire.c:74 msgid "Sorry. The help system hasn't yet been implemented." msgstr "" @@ -4552,25 +4557,25 @@ msgstr "" msgid "Criteria" msgstr "" -#: src/ui/gui/syntax-editor.c:59 +#: src/ui/gui/syntax-editor.c:63 #, c-format msgid "Save contents of syntax editor to %s?" msgstr "" -#: src/ui/gui/syntax-editor.c:107 +#: src/ui/gui/syntax-editor.c:111 msgid "Save Syntax" msgstr "" -#: src/ui/gui/syntax-editor.c:115 src/ui/gui/syntax-editor.c:371 +#: src/ui/gui/syntax-editor.c:119 src/ui/gui/syntax-editor.c:410 msgid "Syntax Files (*.sps) " msgstr "" -#: src/ui/gui/syntax-editor.c:276 +#: src/ui/gui/syntax-editor.c:312 #, c-format msgid "%s --- PSPP Syntax Editor" msgstr "" -#: src/ui/gui/syntax-editor.c:363 +#: src/ui/gui/syntax-editor.c:402 msgid "Open Syntax" msgstr "" diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index daa4de7d..70931061 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,15 @@ +Sun Dec 17 08:26:10 WST 2006 John Darrington + + * syntax-editor-source.c syntax-editor-source.h syntax-editor.h: + New files. + + * message-dialog.c : Now reports the filename and line number in + error messages. + + * psppire.c psppire.glade syntax-editor.c: Added the ability to run + syntax from the syntax editor. + + Sat Dec 16 14:13:07 2006 Ben Pfaff * psppire-data-store.c (geometry_get_justification): Don't assume diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 2e537cfd..53738069 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -8,13 +8,19 @@ src_ui_gui_psppire_LDFLAGS = \ -export-dynamic src_ui_gui_psppire_LDADD = \ + lib/gtksheet/libgtksheet.a \ + src/language/liblanguage.a \ + src/ui/libuicommon.a \ + src/output/charts/libcharts.a \ + src/output/liboutput.a \ + src/math/libpspp_math.a \ + src/math/linreg/libpspp_linreg.a \ + lib/linreg/liblinreg.a \ + lib/gsl-extras/libgsl-extras.a \ + src/data/libdata.a \ + src/libpspp/libpspp.a \ $(GTK_LIBS) \ $(GLADE_LIBS) \ - $(top_builddir)/lib/gtksheet/libgtksheet.a \ - $(top_builddir)/src/ui/libuicommon.a \ - $(top_builddir)/src/math/libpspp_math.a \ - $(top_builddir)/src/data/libdata.a \ - $(top_builddir)/src/libpspp/libpspp.a \ $(top_builddir)/gl/libgl.a \ @LIBINTL@ @LIBREADLINE@ @@ -60,6 +66,9 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/sort-cases-dialog.c \ src/ui/gui/sort-cases-dialog.h \ src/ui/gui/syntax-editor.c \ + src/ui/gui/syntax-editor.h \ + src/ui/gui/syntax-editor-source.c \ + src/ui/gui/syntax-editor-source.h \ src/ui/gui/val-labs-dialog.c \ src/ui/gui/val-labs-dialog.h \ src/ui/gui/var-sheet.c \ diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index 1a4a00a0..8b910ce2 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -136,7 +136,7 @@ popup_message(const struct msg *m) msg = _("PSPP Error"); break; }; - + parent = GTK_WINDOW(get_widget_assert(xml, "data_editor")); dialog = gtk_message_dialog_new(parent, @@ -144,10 +144,13 @@ popup_message(const struct msg *m) message_type, GTK_BUTTONS_CLOSE, msg); - + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), - "%s", m->text); - + _("%s (line %d) %s"), + m->where.file_name, + m->where.line_number, + m->text); + gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); gtk_dialog_run(GTK_DIALOG(dialog)); diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 59378fc9..ae047d31 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -200,26 +200,9 @@ static const struct dict_callbacks gui_callbacks = static void psppire_dict_init (PsppireDict *psppire_dict) { - psppire_dict->dict = dict_create (); - - dict_set_callbacks (psppire_dict->dict, &gui_callbacks, psppire_dict); - psppire_dict->stamp = g_random_int(); } -/** - * psppire_dict_new: - * @returns: a new #PsppireDict object - * - * Creates a new #PsppireDict. - */ -PsppireDict* -psppire_dict_new (void) -{ - return g_object_new (G_TYPE_PSPPIRE_DICT, NULL); -} - - /** * psppire_dict_new_from_dict: * @returns: a new #PsppireDict object @@ -232,6 +215,8 @@ psppire_dict_new_from_dict (struct dictionary *d) PsppireDict *new_dict = g_object_new (G_TYPE_PSPPIRE_DICT, NULL); new_dict->dict = d; + dict_set_callbacks (new_dict->dict, &gui_callbacks, new_dict); + return new_dict; } diff --git a/src/ui/gui/psppire-dict.h b/src/ui/gui/psppire-dict.h index 3aac1ced..5d24198f 100644 --- a/src/ui/gui/psppire-dict.h +++ b/src/ui/gui/psppire-dict.h @@ -66,7 +66,6 @@ struct _PsppireDictClass /* -- PsppireDict --- */ GType psppire_dict_get_type (void); -PsppireDict* psppire_dict_new (void); PsppireDict* psppire_dict_new_from_dict (struct dictionary *d); void psppire_dict_set_name (PsppireDict* s, gint idx, const gchar *name); void psppire_dict_delete_var (PsppireDict *s, gint idx); diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index 19a2eabe..36142245 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -24,10 +24,13 @@ #include #include +#include #include #include #include +#include #include +#include #include #include @@ -77,7 +80,10 @@ PsppireVarStore *var_store = 0; void create_icon_factory (void); -static struct source_stream *the_source_stream ; +struct source_stream *the_source_stream ; +struct lexer *the_lexer; +struct dataset * the_dataset = NULL; + int main(int argc, char *argv[]) @@ -118,13 +124,21 @@ main(int argc, char *argv[]) fmt_init(); settings_init(); + fh_init (); the_source_stream = create_source_stream ( fn_getenv_default ("STAT_INCLUDE_PATH", include_path) ); + the_lexer = lex_create (the_source_stream); + + the_dataset = create_dataset (); + message_dialog_init (the_source_stream); - the_dictionary = psppire_dict_new(); + the_dictionary = + psppire_dict_new_from_dict ( + dataset_dict (the_dataset) + ); bind_textdomain_codeset(PACKAGE, "UTF-8"); diff --git a/src/ui/gui/psppire.glade b/src/ui/gui/psppire.glade index b7a49bee..b0f99727 100644 --- a/src/ui/gui/psppire.glade +++ b/src/ui/gui/psppire.glade @@ -3138,7 +3138,7 @@ - + True All True @@ -3146,7 +3146,7 @@ - + True Selection True @@ -3154,7 +3154,7 @@ - + True Current Line True @@ -3162,7 +3162,7 @@ - + True To End True diff --git a/src/ui/gui/syntax-editor-source.c b/src/ui/gui/syntax-editor-source.c new file mode 100644 index 00000000..53478d20 --- /dev/null +++ b/src/ui/gui/syntax-editor-source.c @@ -0,0 +1,130 @@ +/* + PSPPIRE --- A Graphical User Interface for PSPP + Copyright (C) 2006 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + + +#include +#include +#include +#include + +#include + +#include + +#include "syntax-editor-source.h" +#include "syntax-editor.h" + +struct syntax_editor_source + { + struct getl_interface parent; + const struct syntax_editor *se; + GtkTextIter i; + GtkTextIter end; + }; + + +static bool +always_false (const struct getl_interface *i UNUSED) +{ + return false; +} + +/* Returns the name of the source */ +static const char * +name (const struct getl_interface *i) +{ + const struct syntax_editor_source *ses = + (const struct syntax_editor_source *) i; + + return ses->se->name; +} + + +/* Returns the location within the source */ +static int +location (const struct getl_interface *i) +{ + const struct syntax_editor_source *ses = (const struct syntax_editor_source *) i; + + return gtk_text_iter_get_line (&ses->i); +} + + +static bool +read_line_from_buffer (struct getl_interface *i, + struct string *line, + enum getl_syntax *syntax_rules) +{ + gchar *text; + GtkTextIter next_line; + + struct syntax_editor_source *ses = (struct syntax_editor_source *) i; + + if ( gtk_text_iter_compare (&ses->i, &ses->end) >= 0) + return false; + + gtk_text_buffer_get_iter_at_line ( ses->se->buffer, + &next_line, + 1 + gtk_text_iter_get_line (&ses->i) + ); + + text = gtk_text_buffer_get_text (ses->se->buffer, + &ses->i, &next_line, + FALSE); + g_strchomp (text); + + ds_assign_cstr (line, text); + + g_free (text); + + gtk_text_iter_forward_line (&ses->i); + + return true; +} + + +static void +close (struct getl_interface *i ) +{ + free (i); +} + +struct getl_interface * +create_syntax_editor_source (const struct syntax_editor *se, + GtkTextIter start, + GtkTextIter stop + ) +{ + struct syntax_editor_source *ses = xzalloc (sizeof *ses); + + ses->se = se; + ses->i = start; + ses->end = stop; + + + ses->parent.interactive = always_false; + ses->parent.read = read_line_from_buffer; + ses->parent.close = close; + + ses->parent.name = name; + ses->parent.location = location; + + + return (struct getl_interface *) ses; +} diff --git a/src/ui/gui/syntax-editor-source.h b/src/ui/gui/syntax-editor-source.h new file mode 100644 index 00000000..9b1f4556 --- /dev/null +++ b/src/ui/gui/syntax-editor-source.h @@ -0,0 +1,36 @@ +/* + PSPPIRE --- A Graphical User Interface for PSPP + Copyright (C) 2006 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#ifndef SYNTAX_EDITOR_SOURCE_H +#define SYNTAX_EDITOR_SOURCE_H + +#include +struct getl_interface; + +struct syntax_editor; + +struct getl_interface * +create_syntax_editor_source (const struct syntax_editor *se, + GtkTextIter start, + GtkTextIter stop + ); + + + +#endif diff --git a/src/ui/gui/syntax-editor.c b/src/ui/gui/syntax-editor.c index fe880cbe..20f6e1b0 100644 --- a/src/ui/gui/syntax-editor.c +++ b/src/ui/gui/syntax-editor.c @@ -26,17 +26,21 @@ #include #include #include - +#include #include "helper.h" -extern GladeXML *xml; -struct syntax_editor -{ - GtkWidget *window; /* The top level window of the editor */ - GtkTextBuffer *buffer; /* The buffer which contains the text */ - gchar *name; /* The name of this syntax buffer/editor */ -}; + +#include +#include +#include "syntax-editor.h" +#include "syntax-editor-source.h" + +extern struct source_stream *the_source_stream ; +extern struct lexer *the_lexer; +extern struct dataset *the_dataset; + +extern GladeXML *xml; static gboolean save_editor_to_file (struct syntax_editor *se, const gchar *filename, @@ -188,6 +192,29 @@ on_quit (GtkMenuItem *menuitem, gpointer user_data) return FALSE; } +static void +on_run_all (GtkMenuItem *menuitem, gpointer user_data) +{ + GtkTextIter begin, end; + struct syntax_editor *se = user_data; + + gtk_text_buffer_get_iter_at_line (se->buffer, &begin, 0); + gtk_text_buffer_get_iter_at_line (se->buffer, &end, -1); + + getl_append_source (the_source_stream, + create_syntax_editor_source (se, begin, end)); + for (;;) + { + int result = cmd_parse (the_lexer, the_dataset, + proc_has_source (the_dataset) + ? CMD_STATE_DATA : CMD_STATE_INITIAL); + + if (result == CMD_EOF || result == CMD_FINISH) + break; + } +} + + void new_syntax_window (GtkMenuItem *menuitem, gpointer user_data); @@ -198,8 +225,9 @@ static void open_syntax_window (GtkMenuItem *menuitem, gpointer user_data); -/* Create a new syntax editor with NAME. - If NAME is NULL, a name will be automatically assigned +/* + Create a new syntax editor with NAME. + If NAME is NULL, a name will be automatically assigned */ static struct syntax_editor * new_syntax_editor (const gchar *name) @@ -245,6 +273,12 @@ new_syntax_editor (const gchar *name) G_CALLBACK(on_syntax_save_as), se); + + g_signal_connect (get_widget_assert (new_xml,"run_all"), + "activate", + G_CALLBACK(on_run_all), + se); + g_object_unref (new_xml); g_signal_connect (se->window, "delete-event", @@ -253,7 +287,9 @@ new_syntax_editor (const gchar *name) return se; } -/* Callback for the File->New->Syntax menuitem */ +/* + Callback for the File->New->Syntax menuitem +*/ void new_syntax_window (GtkMenuItem *menuitem, gpointer user_data) @@ -280,8 +316,10 @@ set_window_title_from_filename (struct syntax_editor *se, } -/* Save BUFFER to the file called FILENAME. - If successful, clears the buffer's modified flag */ +/* + Save BUFFER to the file called FILENAME. + If successful, clears the buffer's modified flag +*/ static gboolean save_editor_to_file (struct syntax_editor *se, const gchar *filename, @@ -317,7 +355,8 @@ save_editor_to_file (struct syntax_editor *se, } -/* Loads the buffer from the file called FILENAME +/* + Loads the buffer from the file called FILENAME */ static gboolean load_editor_from_file (struct syntax_editor *se, @@ -423,3 +462,7 @@ on_syntax1_activate (GtkMenuItem *menuitem, } #endif + + + + diff --git a/src/ui/gui/syntax-editor.h b/src/ui/gui/syntax-editor.h new file mode 100644 index 00000000..038e1062 --- /dev/null +++ b/src/ui/gui/syntax-editor.h @@ -0,0 +1,36 @@ +/* + PSPPIRE --- A Graphical User Interface for PSPP + Copyright (C) 2006 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + + +#ifndef SYNTAX_EDITOR_H +#define SYNTAX_EDITOR_H + +#include + + + +struct syntax_editor +{ + GtkWidget *window; /* The top level window of the editor */ + GtkTextBuffer *buffer; /* The buffer which contains the text */ + gchar *name; /* The name of this syntax buffer/editor */ +}; + + +#endif