From d43a876351d94acce0e8d565ad2cb4d690727fe9 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 30 Dec 2008 11:09:00 +0900 Subject: [PATCH] New objects psppire-window and psppire-syntax-window. Moved most of the functionality from syntax-editor into syntax-window, and window-manager into psppire-window. Eventually window-manager.c will be superseeded. --- src/ui/gui/automake.mk | 6 +- src/ui/gui/comments-dialog.c | 9 +- src/ui/gui/compute-dialog.c | 9 +- src/ui/gui/crosstabs-dialog.c | 9 +- src/ui/gui/data-editor.c | 14 +- src/ui/gui/descriptives-dialog.c | 9 +- src/ui/gui/examine-dialog.c | 9 +- src/ui/gui/frequencies-dialog.c | 9 +- src/ui/gui/oneway-anova-dialog.c | 9 +- ...yntax-editor.c => psppire-syntax-window.c} | 632 ++++++++++-------- src/ui/gui/psppire-syntax-window.h | 74 ++ src/ui/gui/psppire-window.c | 253 +++++++ src/ui/gui/psppire-window.h | 69 ++ src/ui/gui/rank-dialog.c | 9 +- src/ui/gui/recode-dialog.c | 9 +- src/ui/gui/regression-dialog.c | 9 +- src/ui/gui/select-cases-dialog.c | 9 +- src/ui/gui/sort-cases-dialog.c | 9 +- src/ui/gui/split-file-dialog.c | 9 +- src/ui/gui/syntax-editor-source.c | 16 +- src/ui/gui/syntax-editor-source.h | 2 +- src/ui/gui/syntax-editor.h | 44 -- .../gui/t-test-independent-samples-dialog.c | 9 +- src/ui/gui/t-test-one-sample.c | 9 +- src/ui/gui/t-test-paired-samples.c | 9 +- src/ui/gui/text-data-import-dialog.c | 12 +- src/ui/gui/transpose-dialog.c | 9 +- src/ui/gui/variable-info-dialog.c | 9 +- src/ui/gui/weight-cases-dialog.c | 9 +- src/ui/gui/window-manager.c | 4 +- 30 files changed, 876 insertions(+), 421 deletions(-) rename src/ui/gui/{syntax-editor.c => psppire-syntax-window.c} (66%) create mode 100644 src/ui/gui/psppire-syntax-window.h create mode 100644 src/ui/gui/psppire-window.c create mode 100644 src/ui/gui/psppire-window.h delete mode 100644 src/ui/gui/syntax-editor.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 57d9163c..a0798c57 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -171,8 +171,6 @@ src_ui_gui_psppire_SOURCES = \ 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 \ @@ -199,6 +197,10 @@ src_ui_gui_psppire_SOURCES = \ 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 diff --git a/src/ui/gui/comments-dialog.c b/src/ui/gui/comments-dialog.c index f1a4936e..6b2e8007 100644 --- a/src/ui/gui/comments-dialog.c +++ b/src/ui/gui/comments-dialog.c @@ -20,7 +20,7 @@ #include "helper.h" #include "data-editor.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include "psppire-var-store.h" #include @@ -177,10 +177,11 @@ comments_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/compute-dialog.c b/src/ui/gui/compute-dialog.c index 5d40d216..a887876f 100644 --- a/src/ui/gui/compute-dialog.c +++ b/src/ui/gui/compute-dialog.c @@ -27,7 +27,7 @@ #include #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" static void function_list_populate (GtkTreeView *tv); @@ -457,10 +457,11 @@ compute_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/crosstabs-dialog.c b/src/ui/gui/crosstabs-dialog.c index edaa3e42..3c3bd9f4 100644 --- a/src/ui/gui/crosstabs-dialog.c +++ b/src/ui/gui/crosstabs-dialog.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -495,10 +495,11 @@ crosstabs_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 13cc29a9..f540592d 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -59,7 +59,7 @@ #define N_(msgid) msgid #include "data-editor.h" -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include #include #include @@ -208,7 +208,7 @@ on_recent_files_select (GtkMenuShell *menushell, gpointer user_data) { gchar *file; - struct syntax_editor *se ; + GtkWidget *se ; gchar *uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell)); @@ -217,10 +217,10 @@ on_recent_files_select (GtkMenuShell *menushell, gpointer user_data) 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); } @@ -700,8 +700,8 @@ new_data_editor (void) 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", diff --git a/src/ui/gui/descriptives-dialog.c b/src/ui/gui/descriptives-dialog.c index 7b33eae2..93746221 100644 --- a/src/ui/gui/descriptives-dialog.c +++ b/src/ui/gui/descriptives-dialog.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -273,10 +273,11 @@ descriptives_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/examine-dialog.c b/src/ui/gui/examine-dialog.c index 6813b4b1..5f6a9bb8 100644 --- a/src/ui/gui/examine-dialog.c +++ b/src/ui/gui/examine-dialog.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -347,10 +347,11 @@ examine_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/frequencies-dialog.c b/src/ui/gui/frequencies-dialog.c index 802a4664..9d1215c4 100644 --- a/src/ui/gui/frequencies-dialog.c +++ b/src/ui/gui/frequencies-dialog.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -403,10 +403,11 @@ frequencies_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/oneway-anova-dialog.c b/src/ui/gui/oneway-anova-dialog.c index 13f36210..4db1e5ff 100644 --- a/src/ui/gui/oneway-anova-dialog.c +++ b/src/ui/gui/oneway-anova-dialog.c @@ -31,7 +31,7 @@ #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include "gettext.h" @@ -242,10 +242,11 @@ oneway_anova_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/syntax-editor.c b/src/ui/gui/psppire-syntax-window.c similarity index 66% rename from src/ui/gui/syntax-editor.c rename to src/ui/gui/psppire-syntax-window.c index 35749fcd..534e6cfc 100644 --- a/src/ui/gui/syntax-editor.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006 Free Software Foundation, Inc. + 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 @@ -15,34 +15,193 @@ along with this program. If not, see . */ #include -#include -#include -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid +#include +#include #include -#include -#include -#include #include "helper.h" + +#include +#include + + +#include "psppire-syntax-window.h" + #include "data-editor.h" #include "about.h" +#include "psppire-syntax-window.h" +#include "syntax-editor-source.h" +#include -#include "window-manager.h" +#include +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid -#include -#include -#include -#include -#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); +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. @@ -59,24 +218,72 @@ append_suffix (const gchar *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 (struct syntax_editor *se) +save_if_modified (PsppireSyntaxWindow *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), + 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?"), - e->name - ); + filename); gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_YES, @@ -97,7 +304,7 @@ save_if_modified (struct syntax_editor *se) { GError *err = NULL; - if ( ! save_editor_to_file (se, e->name, &err) ) + if ( ! save_editor_to_file (se, filename, &err) ) { msg (ME, err->message); g_error_free (err); @@ -108,7 +315,7 @@ save_if_modified (struct syntax_editor *se) return ; } - gtk_widget_destroy (GTK_WIDGET (e->window)); + gtk_widget_destroy (GTK_WIDGET (se)); } /* Callback for the File->SaveAs menuitem */ @@ -117,12 +324,12 @@ 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; + + PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data); GtkWidget *dialog = gtk_file_chooser_dialog_new (_("Save Syntax"), - GTK_WINDOW (e->window), + GTK_WINDOW (se), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, @@ -149,12 +356,7 @@ on_syntax_save_as (GtkMenuItem *menuitem, gpointer user_data) 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 + if ( ! save_editor_to_file (se, filename, &err) ) { msg ( ME, err->message ); g_error_free (err); @@ -163,22 +365,24 @@ on_syntax_save_as (GtkMenuItem *menuitem, gpointer user_data) free (filename); } - gtk_widget_destroy ( dialog ); + 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; + PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data); + const gchar *filename = psppire_window_get_filename (PSPPIRE_WINDOW (se)); + - if ( e->name == NULL ) - on_syntax_save_as (menuitem, user_data); + if ( filename == NULL ) + on_syntax_save_as (menuitem, se); else { GError *err = NULL; - save_editor_to_file (se, e->name, &err); + save_editor_to_file (se, filename, &err); if ( err ) { msg (ME, err->message); @@ -188,275 +392,208 @@ on_syntax_save (GtkMenuItem *menuitem, gpointer user_data) } -/* Callback for the "delete" action (clicking the x on the top right - hand corner of the window) */ +/* Callback for the File->Quit menuitem */ static gboolean -on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data) +on_quit (GtkMenuItem *menuitem, gpointer user_data) { - struct syntax_editor *se = user_data; + PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data); save_if_modified (se); - return TRUE; + return FALSE; } -/* Callback for the File->Quit menuitem */ +/* Callback for the "delete" action (clicking the x on the top right + hand corner of the window) */ static gboolean -on_quit (GtkMenuItem *menuitem, gpointer user_data) +on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data) { - struct syntax_editor *se = user_data; + PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data); + save_if_modified (se); - return FALSE; + return TRUE; } -static void -editor_execute_syntax (const struct syntax_editor *se, GtkTextIter start, - GtkTextIter stop) + +void +create_syntax_window (void) { - execute_syntax (create_syntax_editor_source (se, start, stop)); + GtkWidget *w = psppire_syntax_window_new (); + gtk_widget_show (w); } -/* Parse and execute all the text in the buffer */ -static void -on_run_all (GtkMenuItem *menuitem, gpointer user_data) +/* Callback for the File->Open->Syntax menuitem */ +void +open_syntax_window (GtkMenuItem *menuitem, gpointer parent) { - 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); + GtkFileFilter *filter; + gint response; - editor_execute_syntax (se, begin, end); -} + 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); -/* 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; + 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); - if ( gtk_text_buffer_get_selection_bounds (se->buffer, &begin, &end) ) - editor_execute_syntax (se, begin, end); -} + 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)); -/* Parse and execute the current line */ -static void -on_run_current_line (GtkMenuItem *menuitem, gpointer user_data) -{ - GtkTextIter begin, end; - GtkTextIter here; - gint line; + if (response == GTK_RESPONSE_ACCEPT) + { + const char *file_name = gtk_file_chooser_get_filename + (GTK_FILE_CHOOSER (dialog)); - struct syntax_editor *se = user_data; + GtkWidget *se = psppire_syntax_window_new (); - /* Get the current line */ - gtk_text_buffer_get_iter_at_mark (se->buffer, - &here, - gtk_text_buffer_get_insert (se->buffer) - ); + 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); - line = gtk_text_iter_get_line (&here) ; + 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); - /* 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); + g_free (uri); + } +#else + ; +#endif + gtk_widget_show (se); + } - editor_execute_syntax (se, begin, end); + gtk_widget_destroy (dialog); } +extern struct source_stream *the_source_stream ; -/* 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) +psppire_syntax_window_init (PsppireSyntaxWindow *window) { - 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); -} + 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); -/* - 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"); + g_object_ref (menubar); + gtk_widget_unparent (menubar); - GtkWidget *text_view; - struct syntax_editor *se ; - struct editor_window *e; + g_object_ref (sw); + gtk_widget_unparent (sw); - connect_help (xml); + g_object_ref (sb); + gtk_widget_unparent (sb); - se = g_malloc (sizeof (*se)); - e = (struct editor_window *)se; + 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); - 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); + gtk_widget_show_all (box); g_signal_connect (get_widget_assert (xml,"file_new_syntax"), "activate", - G_CALLBACK (new_syntax_window), - e->window); + G_CALLBACK (create_syntax_window), + NULL); g_signal_connect (get_widget_assert (xml,"file_open_syntax"), "activate", G_CALLBACK (open_syntax_window), - e->window); + window); + g_signal_connect (get_widget_assert (xml,"file_new_data"), "activate", G_CALLBACK (new_data_window), - e->window); + window); g_signal_connect (get_widget_assert (xml,"help_about"), "activate", G_CALLBACK (about_new), - e->window); + 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); + window); g_signal_connect (get_widget_assert (xml, "file_save_as"), "activate", G_CALLBACK (on_syntax_save_as), - se); - + window); g_signal_connect (get_widget_assert (xml,"file_quit"), "activate", G_CALLBACK (on_quit), - se); - + window); g_signal_connect (get_widget_assert (xml,"run_all"), "activate", G_CALLBACK (on_run_all), - se); + window); g_signal_connect (get_widget_assert (xml,"run_selection"), "activate", G_CALLBACK (on_run_selection), - se); + window); g_signal_connect (get_widget_assert (xml,"run_current_line"), "activate", G_CALLBACK (on_run_current_line), - se); - + window); g_signal_connect (get_widget_assert (xml,"run_to_end"), "activate", G_CALLBACK (on_run_to_end), - se); - + 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 (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); + g_signal_connect (window, "delete-event", + G_CALLBACK (on_delete), window); } -/* - 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) +GtkWidget* +psppire_syntax_window_new (void) { - 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; + return GTK_WIDGET (g_object_new (psppire_syntax_window_get_type (), NULL)); } @@ -464,11 +601,10 @@ save_editor_to_file (struct syntax_editor *se, Loads the buffer from the file called FILENAME */ gboolean -load_editor_from_file (struct syntax_editor *se, - const gchar *filename, - GError **err) +psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se, + const gchar *filename, + GError **err) { - GtkTextBuffer *buffer = se->buffer; gchar *text; GtkTextIter iter; @@ -485,72 +621,14 @@ load_editor_from_file (struct syntax_editor *se, } g_free (glibfilename); - gtk_text_buffer_get_iter_at_line (buffer, &iter, 0); + gtk_text_buffer_get_iter_at_line (se->buffer, &iter, 0); - gtk_text_buffer_insert (buffer, &iter, text, -1); + gtk_text_buffer_insert (se->buffer, &iter, text, -1); + psppire_window_set_filename (PSPPIRE_WINDOW (se), filename); - window_set_name_from_filename ((struct editor_window *)se, filename); - gtk_text_buffer_set_modified (buffer, FALSE); + gtk_text_buffer_set_modified (se->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); -} - diff --git a/src/ui/gui/psppire-syntax-window.h b/src/ui/gui/psppire-syntax-window.h new file mode 100644 index 00000000..18946413 --- /dev/null +++ b/src/ui/gui/psppire-syntax-window.h @@ -0,0 +1,74 @@ +/* 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 . */ + + +#ifndef __PSPPIRE_SYNTAX_WINDOW_H__ +#define __PSPPIRE_SYNTAX_WINDOW_H__ + + +#include +#include +#include +#include +#include "psppire-window.h" +#include + +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; + + /* */ + + 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__ */ diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c new file mode 100644 index 00000000..3848b897 --- /dev/null +++ b/src/ui/gui/psppire-window.c @@ -0,0 +1,253 @@ +/* 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 . */ + +#include + +#include +#include + +#include + +#include +#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); +} + diff --git a/src/ui/gui/psppire-window.h b/src/ui/gui/psppire-window.h new file mode 100644 index 00000000..d0eba024 --- /dev/null +++ b/src/ui/gui/psppire-window.h @@ -0,0 +1,69 @@ +/* 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 . */ + + +#ifndef __PSPPIRE_WINDOW_H__ +#define __PSPPIRE_WINDOW_H__ + + +#include +#include +#include +#include + +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; + + /* */ + 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__ */ diff --git a/src/ui/gui/rank-dialog.c b/src/ui/gui/rank-dialog.c index 174ac6d0..86fabd14 100644 --- a/src/ui/gui/rank-dialog.c +++ b/src/ui/gui/rank-dialog.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -359,10 +359,11 @@ rank_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/recode-dialog.c b/src/ui/gui/recode-dialog.c index 31436746..af6cbfa0 100644 --- a/src/ui/gui/recode-dialog.c +++ b/src/ui/gui/recode-dialog.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include "psppire-acr.h" @@ -1095,10 +1095,11 @@ recode_dialog (struct data_editor *de, gboolean diff) { 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); } diff --git a/src/ui/gui/regression-dialog.c b/src/ui/gui/regression-dialog.c index 4ee11fe9..a47d7345 100644 --- a/src/ui/gui/regression-dialog.c +++ b/src/ui/gui/regression-dialog.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -317,10 +317,11 @@ regression_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/select-cases-dialog.c b/src/ui/gui/select-cases-dialog.c index f241c79d..0056ca5e 100644 --- a/src/ui/gui/select-cases-dialog.c +++ b/src/ui/gui/select-cases-dialog.c @@ -26,7 +26,7 @@ #include "dict-display.h" #include "widget-io.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include @@ -364,10 +364,11 @@ select_cases_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/sort-cases-dialog.c b/src/ui/gui/sort-cases-dialog.c index 4c83676f..6c3f332d 100644 --- a/src/ui/gui/sort-cases-dialog.c +++ b/src/ui/gui/sort-cases-dialog.c @@ -25,7 +25,7 @@ #include "dict-display.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" static void refresh (PsppireDialog *dialog, GtkTreeView *dest) @@ -153,10 +153,11 @@ sort_cases_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/split-file-dialog.c b/src/ui/gui/split-file-dialog.c index 22cdb914..96ecf5a6 100644 --- a/src/ui/gui/split-file-dialog.c +++ b/src/ui/gui/split-file-dialog.c @@ -23,7 +23,7 @@ #include "data-editor.h" #include "dict-display.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include #include @@ -231,10 +231,11 @@ split_file_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/syntax-editor-source.c b/src/ui/gui/syntax-editor-source.c index f7617a89..9e1f2e87 100644 --- a/src/ui/gui/syntax-editor-source.c +++ b/src/ui/gui/syntax-editor-source.c @@ -26,14 +26,14 @@ #include #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; }; @@ -49,10 +49,10 @@ always_false (const struct getl_interface *i UNUSED) 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); } @@ -81,7 +81,7 @@ read_line_from_buffer (struct getl_interface *i, 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); @@ -103,14 +103,14 @@ do_close (struct getl_interface *i ) } 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; diff --git a/src/ui/gui/syntax-editor-source.h b/src/ui/gui/syntax-editor-source.h index ca198393..f66c46f9 100644 --- a/src/ui/gui/syntax-editor-source.h +++ b/src/ui/gui/syntax-editor-source.h @@ -23,7 +23,7 @@ struct getl_interface; 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 ); diff --git a/src/ui/gui/syntax-editor.h b/src/ui/gui/syntax-editor.h deleted file mode 100644 index b3943ec8..00000000 --- a/src/ui/gui/syntax-editor.h +++ /dev/null @@ -1,44 +0,0 @@ -/* 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 . */ - - -#ifndef SYNTAX_EDITOR_H -#define SYNTAX_EDITOR_H - -#include - -#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 diff --git a/src/ui/gui/t-test-independent-samples-dialog.c b/src/ui/gui/t-test-independent-samples-dialog.c index 9c3ea41d..03260012 100644 --- a/src/ui/gui/t-test-independent-samples-dialog.c +++ b/src/ui/gui/t-test-independent-samples-dialog.c @@ -32,7 +32,7 @@ #include #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include @@ -485,10 +485,11 @@ t_test_independent_samples_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/t-test-one-sample.c b/src/ui/gui/t-test-one-sample.c index ccecb075..db08576f 100644 --- a/src/ui/gui/t-test-one-sample.c +++ b/src/ui/gui/t-test-one-sample.c @@ -31,7 +31,7 @@ #include "t-test-options.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include #define _(msgid) gettext (msgid) @@ -191,10 +191,11 @@ t_test_one_sample_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/t-test-paired-samples.c b/src/ui/gui/t-test-paired-samples.c index e89e6d74..c0207949 100644 --- a/src/ui/gui/t-test-paired-samples.c +++ b/src/ui/gui/t-test-paired-samples.c @@ -31,7 +31,7 @@ #include "dialog-common.h" #include "psppire-dialog.h" -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include "helper.h" @@ -265,10 +265,11 @@ t_test_paired_samples_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index a82a81a1..1cab531b 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include "error.h" #include "xalloc.h" @@ -293,9 +293,13 @@ text_data_import_assistant (GObject *o, gpointer de_) 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; diff --git a/src/ui/gui/transpose-dialog.c b/src/ui/gui/transpose-dialog.c index 621e196c..9945c947 100644 --- a/src/ui/gui/transpose-dialog.c +++ b/src/ui/gui/transpose-dialog.c @@ -23,7 +23,7 @@ #include "data-editor.h" #include "dict-display.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include "dialog-common.h" @@ -139,10 +139,11 @@ transpose_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/variable-info-dialog.c b/src/ui/gui/variable-info-dialog.c index 533021e7..dcd1b911 100644 --- a/src/ui/gui/variable-info-dialog.c +++ b/src/ui/gui/variable-info-dialog.c @@ -29,7 +29,7 @@ #include "helper.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include @@ -215,10 +215,11 @@ variable_info_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/weight-cases-dialog.c b/src/ui/gui/weight-cases-dialog.c index 223568bf..3b1db1b9 100644 --- a/src/ui/gui/weight-cases-dialog.c +++ b/src/ui/gui/weight-cases-dialog.c @@ -23,7 +23,7 @@ #include "data-editor.h" #include "dict-display.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include #include @@ -173,10 +173,11 @@ weight_cases_dialog (GObject *o, gpointer data) { 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); } diff --git a/src/ui/gui/window-manager.c b/src/ui/gui/window-manager.c index 91f44a59..e4211664 100644 --- a/src/ui/gui/window-manager.c +++ b/src/ui/gui/window-manager.c @@ -20,7 +20,7 @@ #include "relocatable.h" #include -#include "syntax-editor.h" +#include "psppire-syntax-window.h" #include "data-editor.h" #include "output-viewer.h" @@ -84,7 +84,7 @@ window_create (enum window_type type, const gchar *name) 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 (); -- 2.30.2