src/ui/gui/sort-cases-dialog.h \
src/ui/gui/split-file-dialog.c \
src/ui/gui/split-file-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/text-data-import-dialog.c \
src/ui/gui/weight-cases-dialog.h \
src/ui/gui/widget-io.c \
src/ui/gui/widget-io.h \
+ src/ui/gui/psppire-window.c \
+ src/ui/gui/psppire-window.h \
+ src/ui/gui/psppire-syntax-window.c \
+ src/ui/gui/psppire-syntax-window.h \
src/ui/gui/window-manager.c \
src/ui/gui/window-manager.h
#include "helper.h"
#include "data-editor.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include "psppire-var-store.h"
#include <ui/syntax-gen.h>
{
gchar *syntax = generate_syntax (&cd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <language/expressions/public.h>
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
static void function_list_populate (GtkTreeView *tv);
{
gchar *syntax = generate_syntax (&scd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&cd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#define N_(msgid) msgid
#include "data-editor.h"
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <language/syntax-string-source.h>
#include <language/command.h>
#include <ui/syntax-gen.h>
{
gchar *file;
- struct syntax_editor *se ;
+ GtkWidget *se ;
gchar *uri =
gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
g_free (uri);
- se = (struct syntax_editor *)
- window_create (WINDOW_SYNTAX, file);
+ se = psppire_syntax_window_new ();
- load_editor_from_file (se, file, NULL);
+ psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file, NULL);
+ gtk_widget_show (se);
g_free (file);
}
g_signal_connect (get_widget_assert (de->xml,"file_new_syntax"),
"activate",
- G_CALLBACK (new_syntax_window),
- e->window);
+ G_CALLBACK (create_syntax_window),
+ NULL);
g_signal_connect (get_widget_assert (de->xml,"file_open_syntax"),
"activate",
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&scd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&ex_d);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&fd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include "gettext.h"
{
gchar *syntax = generate_syntax (&ow);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <gtk/gtksignal.h>
+#include <gtk/gtkbox.h>
+#include <glade/glade.h>
+#include "helper.h"
+
+#include <libpspp/message.h>
+#include <stdlib.h>
+
+
+#include "psppire-syntax-window.h"
+
+#include "data-editor.h"
+#include "about.h"
+#include "psppire-syntax-window.h"
+#include "syntax-editor-source.h"
+#include <language/lexer/lexer.h>
+
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+
+
+static void psppire_syntax_window_base_finalize (PsppireSyntaxWindowClass *, gpointer);
+static void psppire_syntax_window_base_init (PsppireSyntaxWindowClass *class);
+static void psppire_syntax_window_class_init (PsppireSyntaxWindowClass *class);
+static void psppire_syntax_window_init (PsppireSyntaxWindow *syntax_editor);
+
+
+GType
+psppire_syntax_window_get_type (void)
+{
+ static GType psppire_syntax_window_type = 0;
+
+ if (!psppire_syntax_window_type)
+ {
+ static const GTypeInfo psppire_syntax_window_info =
+ {
+ sizeof (PsppireSyntaxWindowClass),
+ (GBaseInitFunc) psppire_syntax_window_base_init,
+ (GBaseFinalizeFunc) psppire_syntax_window_base_finalize,
+ (GClassInitFunc)psppire_syntax_window_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (PsppireSyntaxWindow),
+ 0,
+ (GInstanceInitFunc) psppire_syntax_window_init,
+ };
+
+ psppire_syntax_window_type =
+ g_type_register_static (PSPPIRE_WINDOW_TYPE, "PsppireSyntaxWindow",
+ &psppire_syntax_window_info, 0);
+ }
+
+ return psppire_syntax_window_type;
+}
+
+
+static void
+psppire_syntax_window_finalize (GObject *object)
+{
+ g_debug ("%s %p", __FUNCTION__, object);
+
+ GObjectClass *class = G_OBJECT_GET_CLASS (object);
+
+ GObjectClass *parent_class = g_type_class_peek_parent (class);
+
+
+ if (G_OBJECT_CLASS (parent_class)->finalize)
+ (*G_OBJECT_CLASS (parent_class)->finalize) (object);
+
+}
+
+
+static void
+psppire_syntax_window_class_init (PsppireSyntaxWindowClass *class)
+{
+}
+
+
+static void
+psppire_syntax_window_base_init (PsppireSyntaxWindowClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = psppire_syntax_window_finalize;
+}
+
+
+
+static void
+psppire_syntax_window_base_finalize (PsppireSyntaxWindowClass *class,
+ gpointer class_data)
+{
+}
+
+
+static void
+editor_execute_syntax (const PsppireSyntaxWindow *se, GtkTextIter start,
+ GtkTextIter stop)
+{
+ execute_syntax (create_syntax_editor_source (se->buffer, start, stop));
+}
+
+
+/* Parse and execute all the text in the buffer */
+static void
+on_run_all (GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkTextIter begin, end;
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+
+ gtk_text_buffer_get_iter_at_offset (se->buffer, &begin, 0);
+ gtk_text_buffer_get_iter_at_offset (se->buffer, &end, -1);
+
+ editor_execute_syntax (se, begin, end);
+}
+
+/* Parse and execute the currently selected text */
+static void
+on_run_selection (GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkTextIter begin, end;
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+
+ if ( gtk_text_buffer_get_selection_bounds (se->buffer, &begin, &end) )
+ editor_execute_syntax (se, begin, end);
+}
+
+
+/* Parse and execute the from the current line, to the end of the
+ buffer */
+static void
+on_run_to_end (GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkTextIter begin, end;
+ GtkTextIter here;
+ gint line;
+
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+
+ /* Get the current line */
+ gtk_text_buffer_get_iter_at_mark (se->buffer,
+ &here,
+ gtk_text_buffer_get_insert (se->buffer)
+ );
+
+ line = gtk_text_iter_get_line (&here) ;
+
+ /* Now set begin and end to the start of this line, and end of buffer
+ respectively */
+ gtk_text_buffer_get_iter_at_line (se->buffer, &begin, line);
+ gtk_text_buffer_get_iter_at_line (se->buffer, &end, -1);
+
+ editor_execute_syntax (se, begin, end);
+}
+
+
+
+/* Parse and execute the current line */
+static void
+on_run_current_line (GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkTextIter begin, end;
+ GtkTextIter here;
+ gint line;
+
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+
+ /* Get the current line */
+ gtk_text_buffer_get_iter_at_mark (se->buffer,
+ &here,
+ gtk_text_buffer_get_insert (se->buffer)
+ );
+
+ line = gtk_text_iter_get_line (&here) ;
+
+ /* Now set begin and end to the start of this line, and start of
+ following line respectively */
+ gtk_text_buffer_get_iter_at_line (se->buffer, &begin, line);
+ gtk_text_buffer_get_iter_at_line (se->buffer, &end, line + 1);
+
+ editor_execute_syntax (se, begin, end);
+}
+
+
+
+/* Append ".sps" to FILENAME if necessary.
+ The returned result must be freed when no longer required.
+ */
+static gchar *
+append_suffix (const gchar *filename)
+{
+ if ( ! g_str_has_suffix (filename, ".sps" ) &&
+ ! g_str_has_suffix (filename, ".SPS" ) )
+ {
+ return g_strdup_printf ("%s.sps", filename);
+ }
+
+ return strdup (filename);
+}
+
+/*
+ Save BUFFER to the file called FILENAME.
+ If successful, clears the buffer's modified flag
+*/
+static gboolean
+save_editor_to_file (PsppireSyntaxWindow *se,
+ const gchar *filename,
+ GError **err)
+{
+ GtkTextBuffer *buffer = se->buffer;
+ gboolean result ;
+ GtkTextIter start, stop;
+ gchar *text;
+
+ gchar *suffixedname;
+ gchar *glibfilename;
+ g_assert (filename);
+
+ suffixedname = append_suffix (filename);
+
+ glibfilename = g_filename_from_utf8 (suffixedname, -1, 0, 0, err);
+
+ g_free ( suffixedname);
+
+ if ( ! glibfilename )
+ return FALSE;
+
+ gtk_text_buffer_get_iter_at_line (buffer, &start, 0);
+ gtk_text_buffer_get_iter_at_offset (buffer, &stop, -1);
+
+ text = gtk_text_buffer_get_text (buffer, &start, &stop, FALSE);
+
+ result = g_file_set_contents (glibfilename, text, -1, err);
+
+ if ( result )
+ {
+ psppire_window_set_filename (PSPPIRE_WINDOW (se), filename);
+ gtk_text_buffer_set_modified (buffer, FALSE);
+ }
+
+ return result;
+}
+
+/* If the buffer's modified flag is set, then save it, and close the window.
+ Otherwise just close the window.
+*/
+static void
+save_if_modified (PsppireSyntaxWindow *se)
+{
+
+ if ( TRUE == gtk_text_buffer_get_modified (se->buffer))
+ {
+ gint response;
+ GtkWidget *dialog;
+
+ const gchar *filename = psppire_window_get_filename (PSPPIRE_WINDOW (se));
+
+ g_return_if_fail (filename != NULL);
+
+ dialog =
+ gtk_message_dialog_new (GTK_WINDOW (se),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _("Save contents of syntax editor to %s?"),
+ filename);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_YES,
+ GTK_RESPONSE_ACCEPT);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_NO,
+ GTK_RESPONSE_REJECT);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
+
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ if ( response == GTK_RESPONSE_ACCEPT )
+ {
+ GError *err = NULL;
+
+ if ( ! save_editor_to_file (se, filename, &err) )
+ {
+ msg (ME, err->message);
+ g_error_free (err);
+ }
+ }
+
+ if ( response == GTK_RESPONSE_CANCEL )
+ return ;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (se));
+}
+
+/* Callback for the File->SaveAs menuitem */
+static void
+on_syntax_save_as (GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkFileFilter *filter;
+ gint response;
+
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+
+ GtkWidget *dialog =
+ gtk_file_chooser_dialog_new (_("Save Syntax"),
+ GTK_WINDOW (se),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
+ gtk_file_filter_add_pattern (filter, "*.sps");
+ gtk_file_filter_add_pattern (filter, "*.SPS");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All Files"));
+ gtk_file_filter_add_pattern (filter, "*");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
+ TRUE);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if ( response == GTK_RESPONSE_ACCEPT )
+ {
+ GError *err = NULL;
+ char *filename =
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog) );
+
+ if ( ! save_editor_to_file (se, filename, &err) )
+ {
+ msg ( ME, err->message );
+ g_error_free (err);
+ }
+
+ free (filename);
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
+
+/* Callback for the File->Save menuitem */
+static void
+on_syntax_save (GtkMenuItem *menuitem, gpointer user_data)
+{
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+ const gchar *filename = psppire_window_get_filename (PSPPIRE_WINDOW (se));
+
+
+ if ( filename == NULL )
+ on_syntax_save_as (menuitem, se);
+ else
+ {
+ GError *err = NULL;
+ save_editor_to_file (se, filename, &err);
+ if ( err )
+ {
+ msg (ME, err->message);
+ g_error_free (err);
+ }
+ }
+}
+
+
+/* Callback for the File->Quit menuitem */
+static gboolean
+on_quit (GtkMenuItem *menuitem, gpointer user_data)
+{
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+ save_if_modified (se);
+ return FALSE;
+}
+
+
+/* Callback for the "delete" action (clicking the x on the top right
+ hand corner of the window) */
+static gboolean
+on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
+{
+ PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+
+ save_if_modified (se);
+ return TRUE;
+}
+
+
+void
+create_syntax_window (void)
+{
+ GtkWidget *w = psppire_syntax_window_new ();
+ gtk_widget_show (w);
+}
+
+/* Callback for the File->Open->Syntax menuitem */
+void
+open_syntax_window (GtkMenuItem *menuitem, gpointer parent)
+{
+ GtkFileFilter *filter;
+ gint response;
+
+ GtkWidget *dialog =
+ gtk_file_chooser_dialog_new (_("Open Syntax"),
+ GTK_WINDOW (parent),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
+ gtk_file_filter_add_pattern (filter, "*.sps");
+ gtk_file_filter_add_pattern (filter, "*.SPS");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All Files"));
+ gtk_file_filter_add_pattern (filter, "*");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ const char *file_name = gtk_file_chooser_get_filename
+ (GTK_FILE_CHOOSER (dialog));
+
+ GtkWidget *se = psppire_syntax_window_new ();
+
+ if ( psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file_name, NULL) )
+#if RECENT_LISTS_AVAILABLE
+ {
+ GtkRecentManager *manager = gtk_recent_manager_get_default();
+ gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
+
+ gtk_recent_manager_remove_item (manager, uri, NULL);
+ if ( ! gtk_recent_manager_add_item (manager, uri))
+ g_warning ("Could not add item %s to recent list\n",uri);
+
+ g_free (uri);
+ }
+#else
+ ;
+#endif
+ gtk_widget_show (se);
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
+
+extern struct source_stream *the_source_stream ;
+
+static void
+psppire_syntax_window_init (PsppireSyntaxWindow *window)
+{
+ GladeXML *xml = XML_NEW ("syntax-editor.glade");
+ GtkWidget *box = gtk_vbox_new (FALSE, 0);
+
+ GtkWidget *menubar = get_widget_assert (xml, "menubar2");
+ GtkWidget *sw = get_widget_assert (xml, "scrolledwindow8");
+ GtkWidget *sb = get_widget_assert (xml, "statusbar2");
+
+ GtkWidget *text_view = get_widget_assert (xml, "syntax_text_view");
+ window->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
+ window->lexer = lex_create (the_source_stream);
+
+ connect_help (xml);
+
+ gtk_container_add (GTK_CONTAINER (window), box);
+
+ g_object_ref (menubar);
+ gtk_widget_unparent (menubar);
+
+ g_object_ref (sw);
+ gtk_widget_unparent (sw);
+
+ g_object_ref (sb);
+ gtk_widget_unparent (sb);
+
+
+ gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), sw, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), sb, FALSE, TRUE, 0);
+
+ gtk_widget_show_all (box);
+
+ g_signal_connect (get_widget_assert (xml,"file_new_syntax"),
+ "activate",
+ G_CALLBACK (create_syntax_window),
+ NULL);
+
+ g_signal_connect (get_widget_assert (xml,"file_open_syntax"),
+ "activate",
+ G_CALLBACK (open_syntax_window),
+ window);
+
+
+ g_signal_connect (get_widget_assert (xml,"file_new_data"),
+ "activate",
+ G_CALLBACK (new_data_window),
+ window);
+
+ g_signal_connect (get_widget_assert (xml,"help_about"),
+ "activate",
+ G_CALLBACK (about_new),
+ window);
+
+ g_signal_connect (get_widget_assert (xml,"help_reference"),
+ "activate",
+ G_CALLBACK (reference_manual),
+ NULL);
+
+ g_signal_connect (get_widget_assert (xml, "file_save"),
+ "activate",
+ G_CALLBACK (on_syntax_save),
+ window);
+
+ g_signal_connect (get_widget_assert (xml, "file_save_as"),
+ "activate",
+ G_CALLBACK (on_syntax_save_as),
+ window);
+
+ g_signal_connect (get_widget_assert (xml,"file_quit"),
+ "activate",
+ G_CALLBACK (on_quit),
+ window);
+
+ g_signal_connect (get_widget_assert (xml,"run_all"),
+ "activate",
+ G_CALLBACK (on_run_all),
+ window);
+
+
+ g_signal_connect (get_widget_assert (xml,"run_selection"),
+ "activate",
+ G_CALLBACK (on_run_selection),
+ window);
+
+ g_signal_connect (get_widget_assert (xml,"run_current_line"),
+ "activate",
+ G_CALLBACK (on_run_current_line),
+ window);
+
+ g_signal_connect (get_widget_assert (xml,"run_to_end"),
+ "activate",
+ G_CALLBACK (on_run_to_end),
+ window);
+
+#if 0
+ g_signal_connect (get_widget_assert (xml,"windows_minimise_all"),
+ "activate",
+ G_CALLBACK (minimise_all_windows),
+ NULL);
+#endif
+
+ g_object_unref (xml);
+
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (on_delete), window);
+}
+
+
+GtkWidget*
+psppire_syntax_window_new (void)
+{
+ return GTK_WIDGET (g_object_new (psppire_syntax_window_get_type (), NULL));
+}
+
+
+/*
+ Loads the buffer from the file called FILENAME
+*/
+gboolean
+psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se,
+ const gchar *filename,
+ GError **err)
+{
+ gchar *text;
+ GtkTextIter iter;
+
+ gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err);
+
+ if ( ! glibfilename )
+ return FALSE;
+
+ /* FIXME: What if it's a very big file ? */
+ if ( ! g_file_get_contents (glibfilename, &text, NULL, err) )
+ {
+ g_free (glibfilename);
+ return FALSE;
+ }
+ g_free (glibfilename);
+
+ gtk_text_buffer_get_iter_at_line (se->buffer, &iter, 0);
+
+ gtk_text_buffer_insert (se->buffer, &iter, text, -1);
+
+ psppire_window_set_filename (PSPPIRE_WINDOW (se), filename);
+
+ gtk_text_buffer_set_modified (se->buffer, FALSE);
+
+ return TRUE;
+}
+
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef __PSPPIRE_SYNTAX_WINDOW_H__
+#define __PSPPIRE_SYNTAX_WINDOW_H__
+
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtkaction.h>
+#include <gtk/gtktextbuffer.h>
+#include "psppire-window.h"
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PSPPIRE_SYNTAX_WINDOW_TYPE (psppire_syntax_window_get_type ())
+#define PSPPIRE_SYNTAX_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPPIRE_SYNTAX_WINDOW_TYPE, PsppireSyntaxWindow))
+#define PSPPIRE_SYNTAX_WINDOW_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
+ PSPPIRE_SYNTAX_WINDOW_TYPE, PsppireSyntax_WindowClass))
+#define PSPPIRE_IS_SYNTAX_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PSPPIRE_SYNTAX_WINDOW_TYPE))
+#define PSPPIRE_IS_SYNTAX_WINDOW_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
+ PSPPIRE_SYNTAX_WINDOW_TYPE))
+
+
+typedef struct _PsppireSyntaxWindow PsppireSyntaxWindow;
+typedef struct _PsppireSyntaxWindowClass PsppireSyntaxWindowClass;
+
+
+struct _PsppireSyntaxWindow
+{
+ PsppireWindow parent;
+
+ /* <private> */
+
+ GtkTextBuffer *buffer; /* The buffer which contains the text */
+ struct lexer *lexer; /* Lexer to parse syntax */
+};
+
+struct _PsppireSyntaxWindowClass
+{
+ PsppireWindowClass parent_class;
+
+};
+
+GType psppire_syntax_window_get_type (void);
+GtkWidget* psppire_syntax_window_new (void);
+
+gboolean psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se,
+ const gchar *filename,
+ GError **err);
+
+void open_syntax_window (GtkMenuItem *menuitem, gpointer parent);
+void create_syntax_window (void);
+
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_SYNTAX_WINDOW_H__ */
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <gtk/gtksignal.h>
+#include <gtk/gtkwindow.h>
+
+#include <stdlib.h>
+
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+#include "psppire-window.h"
+
+
+static void psppire_window_base_finalize (PsppireWindowClass *, gpointer);
+static void psppire_window_base_init (PsppireWindowClass *class);
+static void psppire_window_class_init (PsppireWindowClass *class);
+static void psppire_window_init (PsppireWindow *window);
+
+
+
+GType
+psppire_window_get_type (void)
+{
+ static GType psppire_window_type = 0;
+
+ if (!psppire_window_type)
+ {
+ static const GTypeInfo psppire_window_info =
+ {
+ sizeof (PsppireWindowClass),
+ (GBaseInitFunc) psppire_window_base_init,
+ (GBaseFinalizeFunc) psppire_window_base_finalize,
+ (GClassInitFunc)psppire_window_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (PsppireWindow),
+ 0,
+ (GInstanceInitFunc) psppire_window_init,
+ };
+
+ psppire_window_type =
+ g_type_register_static (GTK_TYPE_WINDOW, "PsppireWindow",
+ &psppire_window_info, 0);
+ }
+
+ return psppire_window_type;
+}
+
+
+/* Properties */
+enum
+{
+ PROP_0,
+ PROP_FILENAME
+};
+
+
+gchar *
+uniquify (const gchar *str, int *x)
+{
+ return g_strdup_printf ("%s%d", str, (*x)++);
+}
+
+static void
+psppire_window_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireWindow *window = PSPPIRE_WINDOW (object);
+
+ PsppireWindowClass *class = PSPPIRE_WINDOW_CLASS (G_OBJECT_GET_CLASS (object));
+
+ switch (prop_id)
+ {
+ case PROP_FILENAME:
+ {
+ gchar mdash[6] = {0,0,0,0,0,0};
+ gchar *basename, *title;
+ const gchar *name = g_value_get_string (value);
+ gchar *candidate_name = strdup (name);
+ int x = 0;
+
+ while ( g_hash_table_lookup (class->name_table, candidate_name))
+ {
+ free (candidate_name);
+ candidate_name = uniquify (name, &x);
+ }
+
+ basename = g_path_get_basename (candidate_name);
+ g_unichar_to_utf8 (0x2014, mdash);
+
+ title = g_strdup_printf ( _("%s %s PSPPIRE Syntax Editor"), basename, mdash);
+
+ gtk_window_set_title (GTK_WINDOW (window), title);
+
+ free (window->name);
+ window->name = candidate_name;
+
+
+ g_hash_table_insert (class->name_table, window->name, window);
+
+ free (basename);
+ free (title);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+
+static void
+psppire_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireWindow *window = PSPPIRE_WINDOW (object);
+
+ switch (prop_id)
+ {
+ case PROP_FILENAME:
+ g_value_set_string (value, window->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+
+
+static void
+psppire_window_finalize (GObject *object)
+{
+ PsppireWindow *window = PSPPIRE_WINDOW (object);
+ PsppireWindowClass *class = PSPPIRE_WINDOW_CLASS (G_OBJECT_GET_CLASS (object));
+
+ GtkWindowClass *parent_class = g_type_class_peek_parent (class);
+
+ if ( window->finalized )
+ return;
+
+ window->finalized = TRUE;
+
+ g_debug ("%s %p", __FUNCTION__, object);
+
+ g_hash_table_remove (class->name_table, window->name);
+ free (window->name);
+
+ if (G_OBJECT_CLASS (parent_class)->finalize)
+ (*G_OBJECT_CLASS (parent_class)->finalize) (object);
+}
+
+
+static void
+psppire_window_class_init (PsppireWindowClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ GParamSpec *filename_spec =
+ g_param_spec_string ("filename",
+ "File name",
+ "The name of the file associated with this window, if any",
+ "Untitled",
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT
+ );
+
+
+ object_class->set_property = psppire_window_set_property;
+ object_class->get_property = psppire_window_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_FILENAME,
+ filename_spec);
+
+
+
+ class->name_table = g_hash_table_new (g_str_hash, g_str_equal);
+
+ g_hash_table_insert (class->name_table, "Untitled", NULL);
+}
+
+
+static void
+psppire_window_base_init (PsppireWindowClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = psppire_window_finalize;
+
+}
+
+
+
+static void
+psppire_window_base_finalize (PsppireWindowClass *class,
+ gpointer class_data)
+{
+ g_hash_table_destroy (class->name_table);
+}
+
+
+
+static void
+psppire_window_init (PsppireWindow *window)
+{
+ window->name = NULL;
+ window->finalized = FALSE;
+}
+
+
+GtkWidget*
+psppire_window_new (void)
+{
+ return GTK_WIDGET (g_object_new (psppire_window_get_type (), "type", GTK_WINDOW_TOPLEVEL, NULL));
+}
+
+
+const gchar *
+psppire_window_get_filename (PsppireWindow *w)
+{
+ const gchar *name = NULL;
+ g_object_get (w, "filename", name, NULL);
+ return name;
+}
+
+
+void
+psppire_window_set_filename (PsppireWindow *w, const gchar *filename)
+{
+ g_object_set (w, "filename", filename, NULL);
+}
+
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef __PSPPIRE_WINDOW_H__
+#define __PSPPIRE_WINDOW_H__
+
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtkwindow.h>
+#include <gtk/gtkaction.h>
+
+G_BEGIN_DECLS
+
+#define PSPPIRE_WINDOW_TYPE (psppire_window_get_type ())
+#define PSPPIRE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPPIRE_WINDOW_TYPE, PsppireWindow))
+#define PSPPIRE_WINDOW_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
+ PSPPIRE_WINDOW_TYPE, PsppireWindowClass))
+#define PSPPIRE_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PSPPIRE_WINDOW_TYPE))
+#define PSPPIRE_IS_WINDOW_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
+ PSPPIRE_WINDOW_TYPE))
+
+
+typedef struct _PsppireWindow PsppireWindow;
+typedef struct _PsppireWindowClass PsppireWindowClass;
+
+
+struct _PsppireWindow
+{
+ GtkWindow parent;
+
+ /* <private> */
+ gchar *name;
+ gboolean finalized;
+};
+
+struct _PsppireWindowClass
+{
+ GtkWindowClass parent_class;
+
+ GHashTable *name_table;
+};
+
+GType psppire_window_get_type (void);
+GtkWidget* psppire_window_new (void);
+
+const gchar * psppire_window_get_filename (PsppireWindow *);
+
+void psppire_window_set_filename (PsppireWindow *w, const gchar *filename);
+
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_WINDOW_H__ */
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&rd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include <ui/syntax-gen.h>
#include "psppire-acr.h"
{
gchar *syntax = generate_syntax (&rd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <ui/gui/helper.h>
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&rd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "dict-display.h"
#include "widget-io.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <gettext.h>
{
gchar *syntax = generate_syntax (&scd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "dict-display.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
static void
refresh (PsppireDialog *dialog, GtkTreeView *dest)
{
gchar *syntax = generate_syntax (&scd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "data-editor.h"
#include "dict-display.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <data/dictionary.h>
#include <gtk/gtk.h>
{
gchar *syntax = generate_syntax (&sfd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <gtk/gtk.h>
#include "syntax-editor-source.h"
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include "xalloc.h"
struct syntax_editor_source
{
struct getl_interface parent;
- const struct syntax_editor *se;
+ GtkTextBuffer *buffer;
GtkTextIter i;
GtkTextIter end;
};
static const char *
name (const struct getl_interface *i)
{
- const struct syntax_editor_source *ses =
- (const struct syntax_editor_source *) i;
+ // const struct syntax_editor_source *ses =
+ // (const struct syntax_editor_source *) i;
- return window_name ((const struct editor_window *) ses->se);
+ return "I have no idea"; // window_name ((const struct editor_window *) ses->se);
}
next_line = ses->i;
gtk_text_iter_forward_line (&next_line);
- text = gtk_text_buffer_get_text (ses->se->buffer,
+ text = gtk_text_buffer_get_text (ses->buffer,
&ses->i, &next_line,
FALSE);
g_strchomp (text);
}
struct getl_interface *
-create_syntax_editor_source (const struct syntax_editor *se,
+create_syntax_editor_source (GtkTextBuffer *buffer,
GtkTextIter start,
GtkTextIter stop
)
{
struct syntax_editor_source *ses = xzalloc (sizeof *ses);
- ses->se = se;
+ ses->buffer = buffer;
ses->i = start;
ses->end = stop;
struct syntax_editor;
struct getl_interface *
-create_syntax_editor_source (const struct syntax_editor *se,
+create_syntax_editor_source (GtkTextBuffer *buffer,
GtkTextIter start,
GtkTextIter stop
);
+++ /dev/null
-/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2006 Free Software Foundation, Inc.
-
- 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 3 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, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include <stdlib.h>
-#include <gettext.h>
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-#include <glade/glade.h>
-#include <gtk/gtk.h>
-#include <libpspp/message.h>
-#include <libpspp/getl.h>
-#include "helper.h"
-#include "data-editor.h"
-#include "about.h"
-
-#include "window-manager.h"
-
-#include <data/dictionary.h>
-#include <language/lexer/lexer.h>
-#include <language/command.h>
-#include <data/procedure.h>
-#include "syntax-editor.h"
-#include "syntax-editor-source.h"
-
-extern struct source_stream *the_source_stream ;
-extern struct dataset *the_dataset;
-
-static gboolean save_editor_to_file (struct syntax_editor *se,
- const gchar *filename,
- GError **err);
-
-/* Append ".sps" to FILENAME if necessary.
- The returned result must be freed when no longer required.
- */
-static gchar *
-append_suffix (const gchar *filename)
-{
- if ( ! g_str_has_suffix (filename, ".sps" ) &&
- ! g_str_has_suffix (filename, ".SPS" ) )
- {
- return g_strdup_printf ("%s.sps", filename);
- }
-
- return strdup (filename);
-}
-
-/* If the buffer's modified flag is set, then save it, and close the window.
- Otherwise just close the window.
-*/
-static void
-save_if_modified (struct syntax_editor *se)
-{
- struct editor_window *e = (struct editor_window *) se;
- if ( TRUE == gtk_text_buffer_get_modified (se->buffer))
- {
- gint response;
- GtkWidget *dialog =
- gtk_message_dialog_new (GTK_WINDOW (e->window),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- _("Save contents of syntax editor to %s?"),
- e->name
- );
-
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_YES,
- GTK_RESPONSE_ACCEPT);
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_NO,
- GTK_RESPONSE_REJECT);
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL);
-
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- gtk_widget_destroy (dialog);
-
- if ( response == GTK_RESPONSE_ACCEPT )
- {
- GError *err = NULL;
-
- if ( ! save_editor_to_file (se, e->name, &err) )
- {
- msg (ME, err->message);
- g_error_free (err);
- }
- }
-
- if ( response == GTK_RESPONSE_CANCEL )
- return ;
- }
-
- gtk_widget_destroy (GTK_WIDGET (e->window));
-}
-
-/* Callback for the File->SaveAs menuitem */
-static void
-on_syntax_save_as (GtkMenuItem *menuitem, gpointer user_data)
-{
- GtkFileFilter *filter;
- gint response;
- struct syntax_editor *se = user_data;
- struct editor_window *e = user_data;
-
- GtkWidget *dialog =
- gtk_file_chooser_dialog_new (_("Save Syntax"),
- GTK_WINDOW (e->window),
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
- NULL);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
- gtk_file_filter_add_pattern (filter, "*.sps");
- gtk_file_filter_add_pattern (filter, "*.SPS");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("All Files"));
- gtk_file_filter_add_pattern (filter, "*");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
- TRUE);
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- if ( response == GTK_RESPONSE_ACCEPT )
- {
- GError *err = NULL;
- char *filename =
- gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog) );
-
- if ( save_editor_to_file (se, filename, &err) )
- {
- g_free (e->name);
- e->name = g_strdup (filename);
- }
- else
- {
- msg ( ME, err->message );
- g_error_free (err);
- }
-
- free (filename);
- }
-
- gtk_widget_destroy ( dialog );
-}
-
-/* Callback for the File->Save menuitem */
-static void
-on_syntax_save (GtkMenuItem *menuitem, gpointer user_data)
-{
- struct syntax_editor *se = user_data;
- struct editor_window *e = user_data;
-
- if ( e->name == NULL )
- on_syntax_save_as (menuitem, user_data);
- else
- {
- GError *err = NULL;
- save_editor_to_file (se, e->name, &err);
- if ( err )
- {
- msg (ME, err->message);
- g_error_free (err);
- }
- }
-}
-
-
-/* Callback for the "delete" action (clicking the x on the top right
- hand corner of the window) */
-static gboolean
-on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
-{
- struct syntax_editor *se = user_data;
- save_if_modified (se);
- return TRUE;
-}
-
-
-/* Callback for the File->Quit menuitem */
-static gboolean
-on_quit (GtkMenuItem *menuitem, gpointer user_data)
-{
- struct syntax_editor *se = user_data;
- save_if_modified (se);
- return FALSE;
-}
-
-static void
-editor_execute_syntax (const struct syntax_editor *se, GtkTextIter start,
- GtkTextIter stop)
-{
- execute_syntax (create_syntax_editor_source (se, start, stop));
-}
-
-/* Parse and execute all the text in the buffer */
-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_offset (se->buffer, &begin, 0);
- gtk_text_buffer_get_iter_at_offset (se->buffer, &end, -1);
-
- editor_execute_syntax (se, begin, end);
-}
-
-/* Parse and execute the currently selected text */
-static void
-on_run_selection (GtkMenuItem *menuitem, gpointer user_data)
-{
- GtkTextIter begin, end;
- struct syntax_editor *se = user_data;
-
- if ( gtk_text_buffer_get_selection_bounds (se->buffer, &begin, &end) )
- editor_execute_syntax (se, begin, end);
-}
-
-
-/* Parse and execute the current line */
-static void
-on_run_current_line (GtkMenuItem *menuitem, gpointer user_data)
-{
- GtkTextIter begin, end;
- GtkTextIter here;
- gint line;
-
- struct syntax_editor *se = user_data;
-
- /* Get the current line */
- gtk_text_buffer_get_iter_at_mark (se->buffer,
- &here,
- gtk_text_buffer_get_insert (se->buffer)
- );
-
- line = gtk_text_iter_get_line (&here) ;
-
- /* Now set begin and end to the start of this line, and start of
- following line respectively */
- gtk_text_buffer_get_iter_at_line (se->buffer, &begin, line);
- gtk_text_buffer_get_iter_at_line (se->buffer, &end, line + 1);
-
- editor_execute_syntax (se, begin, end);
-}
-
-
-
-/* Parse and execute the from the current line, to the end of the
- buffer */
-static void
-on_run_to_end (GtkMenuItem *menuitem, gpointer user_data)
-{
- GtkTextIter begin, end;
- GtkTextIter here;
- gint line;
-
- struct syntax_editor *se = user_data;
-
- /* Get the current line */
- gtk_text_buffer_get_iter_at_mark (se->buffer,
- &here,
- gtk_text_buffer_get_insert (se->buffer)
- );
-
- line = gtk_text_iter_get_line (&here) ;
-
- /* Now set begin and end to the start of this line, and end of buffer
- respectively */
- gtk_text_buffer_get_iter_at_line (se->buffer, &begin, line);
- gtk_text_buffer_get_iter_at_line (se->buffer, &end, -1);
-
- editor_execute_syntax (se, begin, end);
-}
-
-
-
-
-/*
- Create a new syntax editor with NAME.
- If NAME is NULL, a name will be automatically assigned
-*/
-struct syntax_editor *
-new_syntax_editor (void)
-{
- GladeXML *xml = XML_NEW ("syntax-editor.glade");
-
- GtkWidget *text_view;
- struct syntax_editor *se ;
- struct editor_window *e;
-
- connect_help (xml);
-
- se = g_malloc (sizeof (*se));
-
- e = (struct editor_window *)se;
-
- e->window = GTK_WINDOW (get_widget_assert (xml, "syntax_editor"));
- text_view = get_widget_assert (xml, "syntax_text_view");
- se->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
- se->lexer = lex_create (the_source_stream);
-
- g_signal_connect (get_widget_assert (xml,"file_new_syntax"),
- "activate",
- G_CALLBACK (new_syntax_window),
- e->window);
-
- g_signal_connect (get_widget_assert (xml,"file_open_syntax"),
- "activate",
- G_CALLBACK (open_syntax_window),
- e->window);
-
- g_signal_connect (get_widget_assert (xml,"file_new_data"),
- "activate",
- G_CALLBACK (new_data_window),
- e->window);
-
- g_signal_connect (get_widget_assert (xml,"help_about"),
- "activate",
- G_CALLBACK (about_new),
- e->window);
-
- g_signal_connect (get_widget_assert (xml,"help_reference"),
- "activate",
- G_CALLBACK (reference_manual),
- NULL);
-
-
- g_signal_connect (get_widget_assert (xml, "file_save"),
- "activate",
- G_CALLBACK (on_syntax_save),
- se);
-
- g_signal_connect (get_widget_assert (xml, "file_save_as"),
- "activate",
- G_CALLBACK (on_syntax_save_as),
- se);
-
-
- g_signal_connect (get_widget_assert (xml,"file_quit"),
- "activate",
- G_CALLBACK (on_quit),
- se);
-
-
- g_signal_connect (get_widget_assert (xml,"run_all"),
- "activate",
- G_CALLBACK (on_run_all),
- se);
-
-
- g_signal_connect (get_widget_assert (xml,"run_selection"),
- "activate",
- G_CALLBACK (on_run_selection),
- se);
-
- g_signal_connect (get_widget_assert (xml,"run_current_line"),
- "activate",
- G_CALLBACK (on_run_current_line),
- se);
-
-
- g_signal_connect (get_widget_assert (xml,"run_to_end"),
- "activate",
- G_CALLBACK (on_run_to_end),
- se);
-
-
- g_signal_connect (get_widget_assert (xml,"windows_minimise_all"),
- "activate",
- G_CALLBACK (minimise_all_windows),
- NULL);
-
-
-
- g_object_unref (xml);
-
- g_signal_connect (e->window, "delete-event",
- G_CALLBACK (on_delete), se);
-
-
-
- return se;
-}
-
-/*
- Callback for the File->New->Syntax menuitem
-*/
-void
-new_syntax_window (GtkMenuItem *menuitem,
- gpointer user_data)
-{
- window_create (WINDOW_SYNTAX, NULL);
-}
-
-
-/*
- 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,
- GError **err)
-{
- GtkTextBuffer *buffer = se->buffer;
- gboolean result ;
- GtkTextIter start, stop;
- gchar *text;
-
- gchar *suffixedname;
- gchar *glibfilename;
- g_assert (filename);
-
- suffixedname = append_suffix (filename);
-
- glibfilename = g_filename_from_utf8 (suffixedname, -1, 0, 0, err);
-
- g_free ( suffixedname);
-
- if ( ! glibfilename )
- return FALSE;
-
- gtk_text_buffer_get_iter_at_line (buffer, &start, 0);
- gtk_text_buffer_get_iter_at_offset (buffer, &stop, -1);
-
- text = gtk_text_buffer_get_text (buffer, &start, &stop, FALSE);
-
- result = g_file_set_contents (glibfilename, text, -1, err);
-
- if ( result )
- {
- window_set_name_from_filename ((struct editor_window *) se, filename);
- gtk_text_buffer_set_modified (buffer, FALSE);
- }
-
- return result;
-}
-
-
-/*
- Loads the buffer from the file called FILENAME
-*/
-gboolean
-load_editor_from_file (struct syntax_editor *se,
- const gchar *filename,
- GError **err)
-{
- GtkTextBuffer *buffer = se->buffer;
- gchar *text;
- GtkTextIter iter;
-
- gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err);
-
- if ( ! glibfilename )
- return FALSE;
-
- /* FIXME: What if it's a very big file ? */
- if ( ! g_file_get_contents (glibfilename, &text, NULL, err) )
- {
- g_free (glibfilename);
- return FALSE;
- }
- g_free (glibfilename);
-
- gtk_text_buffer_get_iter_at_line (buffer, &iter, 0);
-
- gtk_text_buffer_insert (buffer, &iter, text, -1);
-
-
- window_set_name_from_filename ((struct editor_window *)se, filename);
- gtk_text_buffer_set_modified (buffer, FALSE);
-
- return TRUE;
-}
-
-
-/* Callback for the File->Open->Syntax menuitem */
-void
-open_syntax_window (GtkMenuItem *menuitem, gpointer parent)
-{
- GtkFileFilter *filter;
- gint response;
-
- GtkWidget *dialog =
- gtk_file_chooser_dialog_new (_("Open Syntax"),
- GTK_WINDOW (parent),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
- gtk_file_filter_add_pattern (filter, "*.sps");
- gtk_file_filter_add_pattern (filter, "*.SPS");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("All Files"));
- gtk_file_filter_add_pattern (filter, "*");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- if (response == GTK_RESPONSE_ACCEPT)
- {
- const char *file_name = gtk_file_chooser_get_filename
- (GTK_FILE_CHOOSER (dialog));
-
- struct syntax_editor *se = (struct syntax_editor *)
- window_create (WINDOW_SYNTAX, file_name);
-
- if ( load_editor_from_file (se, file_name, NULL) )
-#if RECENT_LISTS_AVAILABLE
- {
- GtkRecentManager *manager = gtk_recent_manager_get_default();
- gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
-
- gtk_recent_manager_remove_item (manager, uri, NULL);
- if ( ! gtk_recent_manager_add_item (manager, uri))
- g_warning ("Could not add item %s to recent list\n",uri);
-
- g_free (uri);
- }
-#else
- ;
-#endif
-
- }
-
- gtk_widget_destroy (dialog);
-}
-
+++ /dev/null
-/* 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 3 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, see <http://www.gnu.org/licenses/>. */
-
-
-#ifndef SYNTAX_EDITOR_H
-#define SYNTAX_EDITOR_H
-
-#include <gtk/gtk.h>
-
-#include "window-manager.h"
-
-struct lexer;
-
-struct syntax_editor
-{
- struct editor_window parent;
- GtkTextBuffer *buffer; /* The buffer which contains the text */
- struct lexer *lexer; /* Lexer to parse syntax */
-};
-
-
-struct syntax_editor * new_syntax_editor (void);
-
-void new_syntax_window (GtkMenuItem *, gpointer);
-
-void open_syntax_window (GtkMenuItem *, gpointer);
-
-gboolean load_editor_from_file (struct syntax_editor *se,
- const gchar *filename,
- GError **err);
-#endif
#include <ui/syntax-gen.h>
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <gl/xalloc.h>
{
gchar *syntax = generate_syntax (&tt_d);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "t-test-options.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <gettext.h>
#define _(msgid) gettext (msgid)
{
gchar *syntax = generate_syntax (&tt_d);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "dialog-common.h"
#include "psppire-dialog.h"
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include "helper.h"
{
gchar *syntax = generate_syntax (&tt_d);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include <ui/gui/psppire-dialog.h>
#include <ui/gui/psppire-var-sheet.h>
#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
+#include <ui/gui/psppire-syntax-window.h>
#include "error.h"
#include "xalloc.h"
case PSPPIRE_RESPONSE_PASTE:
{
char *syntax = generate_syntax (ia);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+
+ GtkWidget *se = psppire_syntax_window_new ();
+
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
+
free (syntax);
}
break;
#include "data-editor.h"
#include "dict-display.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include "dialog-common.h"
{
gchar *syntax = generate_syntax (vs->dict, xml);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "helper.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <gettext.h>
{
gchar *syntax = generate_syntax (GTK_TREE_VIEW (treeview));
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "data-editor.h"
#include "dict-display.h"
#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include <gtk/gtk.h>
#include <glade/glade.h>
{
gchar *syntax = generate_syntax (&wcd);
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+ GtkWidget *se = psppire_syntax_window_new ();
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+ gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
+
+ gtk_widget_show (se);
g_free (syntax);
}
#include "relocatable.h"
#include <glib.h>
-#include "syntax-editor.h"
+#include "psppire-syntax-window.h"
#include "data-editor.h"
#include "output-viewer.h"
switch (type)
{
case WINDOW_SYNTAX:
- e = (struct editor_window *) new_syntax_editor ();
+ //e = (struct editor_window *) new_syntax_editor ();
break;
case WINDOW_DATA:
e = (struct editor_window *) new_data_editor ();