1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <gtk/gtksignal.h>
20 #include <gtk/gtkbox.h>
21 #include <glade/glade.h>
24 #include "text-data-import-dialog.h"
27 #include <ui/syntax-gen.h>
28 #include <language/syntax-string-source.h>
29 #include <libpspp/message.h>
32 #include <data/procedure.h>
34 #include "psppire-data-window.h"
35 #include "psppire-syntax-window.h"
39 #include "goto-case-dialog.h"
40 #include "weight-cases-dialog.h"
41 #include "split-file-dialog.h"
42 #include "transpose-dialog.h"
43 #include "sort-cases-dialog.h"
44 #include "select-cases-dialog.h"
45 #include "compute-dialog.h"
46 #include "find-dialog.h"
47 #include "rank-dialog.h"
48 #include "recode-dialog.h"
49 #include "comments-dialog.h"
50 #include "variable-info-dialog.h"
51 #include "descriptives-dialog.h"
52 #include "crosstabs-dialog.h"
53 #include "frequencies-dialog.h"
54 #include "examine-dialog.h"
55 #include "dict-display.h"
56 #include "regression-dialog.h"
57 #include "oneway-anova-dialog.h"
58 #include "t-test-independent-samples-dialog.h"
59 #include "t-test-one-sample.h"
60 #include "t-test-paired-samples.h"
64 #define _(msgid) gettext (msgid)
65 #define N_(msgid) msgid
69 static void psppire_data_window_base_finalize (PsppireDataWindowClass *, gpointer);
70 static void psppire_data_window_base_init (PsppireDataWindowClass *class);
71 static void psppire_data_window_class_init (PsppireDataWindowClass *class);
72 static void psppire_data_window_init (PsppireDataWindow *data_editor);
76 psppire_data_window_get_type (void)
78 static GType psppire_data_window_type = 0;
80 if (!psppire_data_window_type)
82 static const GTypeInfo psppire_data_window_info =
84 sizeof (PsppireDataWindowClass),
85 (GBaseInitFunc) psppire_data_window_base_init,
86 (GBaseFinalizeFunc) psppire_data_window_base_finalize,
87 (GClassInitFunc)psppire_data_window_class_init,
88 (GClassFinalizeFunc) NULL,
90 sizeof (PsppireDataWindow),
92 (GInstanceInitFunc) psppire_data_window_init,
95 psppire_data_window_type =
96 g_type_register_static (PSPPIRE_WINDOW_TYPE, "PsppireDataWindow",
97 &psppire_data_window_info, 0);
100 return psppire_data_window_type;
105 psppire_data_window_finalize (GObject *object)
107 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (object);
109 GObjectClass *class = G_OBJECT_GET_CLASS (object);
111 GObjectClass *parent_class = g_type_class_peek_parent (class);
113 g_object_unref (de->xml);
116 if (G_OBJECT_CLASS (parent_class)->finalize)
117 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
122 psppire_data_window_class_init (PsppireDataWindowClass *class)
128 psppire_data_window_base_init (PsppireDataWindowClass *class)
130 GObjectClass *object_class = G_OBJECT_CLASS (class);
132 object_class->finalize = psppire_data_window_finalize;
138 psppire_data_window_base_finalize (PsppireDataWindowClass *class,
147 extern PsppireVarStore *the_var_store;
148 extern struct dataset *the_dataset;
149 extern PsppireDataStore *the_data_store ;
153 update_paste_menuitems (GtkWidget *w, gboolean x, gpointer data)
155 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
157 GtkWidget * edit_paste = get_widget_assert (de->xml, "edit_paste");
159 gtk_widget_set_sensitive (edit_paste, x);
163 update_cut_copy_menuitems (GtkWidget *w, gboolean x, gpointer data)
165 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
167 GtkWidget * edit_copy = get_widget_assert (de->xml, "edit_copy");
168 GtkWidget * edit_cut = get_widget_assert (de->xml, "edit_cut");
170 gtk_widget_set_sensitive (edit_copy, x);
171 gtk_widget_set_sensitive (edit_cut, x);
174 /* Run the EXECUTE command. */
176 execute (GtkMenuItem *mi, gpointer data)
178 struct getl_interface *sss = create_syntax_string_source ("EXECUTE.");
180 execute_syntax (sss);
184 transformation_change_callback (bool transformations_pending,
187 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
189 GtkWidget *menuitem =
190 get_widget_assert (de->xml, "transform_run-pending");
191 GtkWidget *status_label =
192 get_widget_assert (de->xml, "case-counter-area");
194 gtk_widget_set_sensitive (menuitem, transformations_pending);
197 if ( transformations_pending)
198 gtk_label_set_text (GTK_LABEL (status_label),
199 _("Transformations Pending"));
201 gtk_label_set_text (GTK_LABEL (status_label), "");
204 /* Callback for when the dictionary changes its filter variable */
206 on_filter_change (GObject *o, gint filter_index, gpointer data)
208 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
210 GtkWidget *filter_status_area =
211 get_widget_assert (de->xml, "filter-use-status-area");
213 if ( filter_index == -1 )
215 gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
219 PsppireVarStore *vs = NULL;
220 struct variable *var ;
223 g_object_get (de->data_editor, "var-store", &vs, NULL);
225 var = psppire_dict_get_variable (vs->dict, filter_index);
227 text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
229 gtk_label_set_text (GTK_LABEL (filter_status_area), text);
235 /* Callback for when the dictionary changes its split variables */
237 on_split_change (PsppireDict *dict, gpointer data)
239 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
241 size_t n_split_vars = dict_get_split_cnt (dict->dict);
243 GtkWidget *split_status_area =
244 get_widget_assert (de->xml, "split-file-status-area");
246 if ( n_split_vars == 0 )
248 gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
254 const struct variable *const * split_vars =
255 dict_get_split_vars (dict->dict);
257 text = g_string_new (_("Split by "));
259 for (i = 0 ; i < n_split_vars - 1; ++i )
261 g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
263 g_string_append (text, var_get_name (split_vars[i]));
265 gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
267 g_string_free (text, TRUE);
274 /* Callback for when the dictionary changes its weights */
276 on_weight_change (GObject *o, gint weight_index, gpointer data)
278 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
280 GtkWidget *weight_status_area =
281 get_widget_assert (de->xml, "weight-status-area");
283 if ( weight_index == -1 )
285 gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
289 struct variable *var ;
290 PsppireVarStore *vs = NULL;
293 g_object_get (de->data_editor, "var-store", &vs, NULL);
295 var = psppire_dict_get_variable (vs->dict, weight_index);
297 text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
299 gtk_label_set_text (GTK_LABEL (weight_status_area), text);
305 /* Puts FILE_NAME into the recent list.
306 If it's already in the list, it moves it to the top
309 add_most_recent (const char *file_name)
311 #if RECENT_LISTS_AVAILABLE
313 GtkRecentManager *manager = gtk_recent_manager_get_default();
314 gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
316 gtk_recent_manager_remove_item (manager, uri, NULL);
318 if ( ! gtk_recent_manager_add_item (manager, uri))
319 g_warning ("Could not add item %s to recent list\n",uri);
326 open_data_file (const gchar *file_name, PsppireDataWindow *de)
328 struct getl_interface *sss;
329 struct string filename;
331 ds_init_empty (&filename);
332 syntax_gen_string (&filename, ss_cstr (file_name));
334 sss = create_syntax_string_source ("GET FILE=%s.",
335 ds_cstr (&filename));
336 ds_destroy (&filename);
338 if (execute_syntax (sss) )
340 psppire_window_set_filename (PSPPIRE_WINDOW (de), file_name);
341 add_most_recent (file_name);
346 /* Callback for the data_open action.
347 Prompts for a filename and opens it */
349 open_data_dialog (GtkAction *action, PsppireDataWindow *de)
352 gtk_file_chooser_dialog_new (_("Open"),
354 GTK_FILE_CHOOSER_ACTION_OPEN,
355 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
356 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
359 GtkFileFilter *filter = gtk_file_filter_new ();
360 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
361 gtk_file_filter_add_pattern (filter, "*.sav");
362 gtk_file_filter_add_pattern (filter, "*.SAV");
363 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
365 filter = gtk_file_filter_new ();
366 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
367 gtk_file_filter_add_pattern (filter, "*.por");
368 gtk_file_filter_add_pattern (filter, "*.POR");
369 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
371 filter = gtk_file_filter_new ();
372 gtk_file_filter_set_name (filter, _("All Files"));
373 gtk_file_filter_add_pattern (filter, "*");
374 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
379 gchar *dir_name = g_path_get_dirname (de->file_name);
380 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
385 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
387 case GTK_RESPONSE_ACCEPT:
389 g_free (de->file_name);
391 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
393 open_data_file (de->file_name, de);
400 gtk_widget_destroy (dialog);
403 /* Returns true if NAME has a suffix which might denote a PSPP file */
405 name_has_suffix (const gchar *name)
407 if ( g_str_has_suffix (name, ".sav"))
409 if ( g_str_has_suffix (name, ".SAV"))
411 if ( g_str_has_suffix (name, ".por"))
413 if ( g_str_has_suffix (name, ".POR"))
420 /* Append SUFFIX to the filename of DE */
422 append_filename_suffix (PsppireDataWindow *de, const gchar *suffix)
424 if ( ! name_has_suffix (de->file_name))
426 gchar *s = de->file_name;
427 de->file_name = g_strconcat (de->file_name, suffix, NULL);
432 /* Save DE to file */
434 save_file (PsppireDataWindow *de)
436 struct getl_interface *sss;
437 struct string file_name ;
439 g_assert (de->file_name);
441 ds_init_empty (&file_name);
442 syntax_gen_string (&file_name, ss_cstr (de->file_name));
444 if ( de->save_as_portable )
446 append_filename_suffix (de, ".por");
447 sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
448 ds_cstr (&file_name));
452 append_filename_suffix (de, ".sav");
453 sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
454 ds_cstr (&file_name));
457 ds_destroy (&file_name);
459 execute_syntax (sss);
464 insert_case (GtkAction *action, gpointer data)
466 PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (data);
468 psppire_data_editor_insert_case (dw->data_editor);
472 on_insert_variable (GtkAction *action, gpointer data)
474 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
475 psppire_data_editor_insert_variable (de);
479 /* Callback for data_save_as action. Prompt for a filename and save */
481 data_save_as_dialog (GtkAction *action, PsppireDataWindow *de)
483 GtkWidget *button_sys;
485 gtk_file_chooser_dialog_new (_("Save"),
487 GTK_FILE_CHOOSER_ACTION_SAVE,
488 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
489 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
492 GtkFileFilter *filter = gtk_file_filter_new ();
493 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
494 gtk_file_filter_add_pattern (filter, "*.sav");
495 gtk_file_filter_add_pattern (filter, "*.SAV");
496 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
498 filter = gtk_file_filter_new ();
499 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
500 gtk_file_filter_add_pattern (filter, "*.por");
501 gtk_file_filter_add_pattern (filter, "*.POR");
502 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
504 filter = gtk_file_filter_new ();
505 gtk_file_filter_set_name (filter, _("All Files"));
506 gtk_file_filter_add_pattern (filter, "*");
507 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
510 GtkWidget *button_por;
511 GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
513 gtk_radio_button_new_with_label (NULL, _("System File"));
516 gtk_radio_button_new_with_label
517 (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
520 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
521 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_por);
523 gtk_widget_show_all (vbox);
525 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
528 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
530 case GTK_RESPONSE_ACCEPT:
532 g_free (de->file_name);
535 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
537 de->save_as_portable =
538 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
540 if ( de->save_as_portable)
541 append_filename_suffix (de, ".por");
543 append_filename_suffix (de, ".sav");
547 psppire_window_set_filename (PSPPIRE_WINDOW (de), de->file_name);
554 gtk_widget_destroy (dialog);
558 /* Callback for data_save action.
559 If there's an existing file name, then just save,
560 otherwise prompt for a file name, then save */
562 data_save (GtkAction *action, PsppireDataWindow *de)
567 data_save_as_dialog (action, de);
571 /* Callback for data_new action.
572 Performs the NEW FILE command */
574 new_file (GtkAction *action, PsppireDataWindow *de)
576 struct getl_interface *sss =
577 create_syntax_string_source ("NEW FILE.");
579 execute_syntax (sss);
581 g_free (de->file_name);
582 de->file_name = NULL;
584 // default_window_name (de);
589 /* Create the GtkActions and connect to their signals */
591 register_data_editor_actions (PsppireDataWindow *de)
593 de->action_data_open =
594 gtk_action_new ("data-open-dialog",
596 _("Open a data file"),
599 g_signal_connect (de->action_data_open, "activate",
600 G_CALLBACK (open_data_dialog), de);
603 de->action_data_save = gtk_action_new ("data-save",
605 _("Save data to file"),
608 g_signal_connect (de->action_data_save, "activate",
609 G_CALLBACK (data_save), de);
612 de->action_data_save_as = gtk_action_new ("data-save-as-dialog",
614 _("Save data to file"),
617 g_signal_connect (de->action_data_save_as, "activate",
618 G_CALLBACK (data_save_as_dialog), de);
620 de->action_data_new =
621 gtk_action_new ("data-new",
626 g_signal_connect (de->action_data_new, "activate",
627 G_CALLBACK (new_file), de);
629 de->invoke_text_import_assistant =
630 gtk_action_new ("file_import-text",
631 _("_Import Text Data"),
632 _("Import text data file"),
635 g_signal_connect (de->invoke_text_import_assistant, "activate",
636 G_CALLBACK (text_data_import_assistant), de);
640 on_edit_paste (GtkAction *a, gpointer data)
642 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
644 psppire_data_editor_clip_paste (de->data_editor);
648 on_edit_copy (GtkMenuItem *m, gpointer data)
650 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
652 psppire_data_editor_clip_copy (de->data_editor);
658 on_edit_cut (GtkMenuItem *m, gpointer data)
660 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
662 psppire_data_editor_clip_cut (de->data_editor);
667 status_bar_activate (GtkCheckMenuItem *menuitem, gpointer data)
669 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
670 GtkWidget *statusbar = get_widget_assert (de->xml, "status-bar");
672 if ( gtk_check_menu_item_get_active (menuitem) )
673 gtk_widget_show (statusbar);
675 gtk_widget_hide (statusbar);
680 grid_lines_activate (GtkCheckMenuItem *menuitem, gpointer data)
682 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
683 const gboolean grid_visible = gtk_check_menu_item_get_active (menuitem);
685 psppire_data_editor_show_grid (de->data_editor, grid_visible);
691 data_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
693 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
695 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
700 variable_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
702 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
704 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
709 fonts_activate (GtkMenuItem *menuitem, gpointer data)
711 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
712 PangoFontDescription *current_font;
715 gtk_font_selection_dialog_new (_("Font Selection"));
718 current_font = GTK_WIDGET(de->data_editor)->style->font_desc;
719 font_name = pango_font_description_to_string (current_font);
721 gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (dialog), font_name);
725 gtk_window_set_transient_for (GTK_WINDOW (dialog),
726 GTK_WINDOW (get_widget_assert (de->xml,
728 if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
730 const gchar *font = gtk_font_selection_dialog_get_font_name
731 (GTK_FONT_SELECTION_DIALOG (dialog));
733 PangoFontDescription* font_desc =
734 pango_font_description_from_string (font);
736 psppire_data_editor_set_font (de->data_editor, font_desc);
739 gtk_widget_hide (dialog);
744 /* Callback for the value labels action */
746 toggle_value_labels (GtkToggleAction *ta, gpointer data)
748 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
750 g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
754 toggle_split_window (GtkToggleAction *ta, gpointer data)
756 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
758 psppire_data_editor_split_window (de->data_editor,
759 gtk_toggle_action_get_active (ta));
764 file_quit (GtkCheckMenuItem *menuitem, gpointer data)
766 /* FIXME: Need to be more intelligent here.
767 Give the user the opportunity to save any unsaved data.
769 g_object_unref (the_data_store);
776 create_data_sheet_variable_popup_menu (PsppireDataWindow *de)
778 GtkWidget *menu = gtk_menu_new ();
780 GtkWidget *sort_ascending =
781 gtk_menu_item_new_with_label (_("Sort Ascending"));
783 GtkWidget *sort_descending =
784 gtk_menu_item_new_with_label (_("Sort Descending"));
786 GtkWidget *insert_variable =
787 gtk_menu_item_new_with_label (_("Insert Variable"));
789 GtkWidget *clear_variable =
790 gtk_menu_item_new_with_label (_("Clear"));
793 gtk_action_connect_proxy (de->delete_variables,
797 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
800 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
801 gtk_separator_menu_item_new ());
804 gtk_menu_shell_append (GTK_MENU_SHELL (menu), clear_variable);
807 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
808 gtk_separator_menu_item_new ());
811 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_ascending);
814 g_signal_connect_swapped (G_OBJECT (sort_ascending), "activate",
815 G_CALLBACK (psppire_data_editor_sort_ascending),
818 g_signal_connect_swapped (G_OBJECT (sort_descending), "activate",
819 G_CALLBACK (psppire_data_editor_sort_descending),
822 g_signal_connect_swapped (G_OBJECT (insert_variable), "activate",
823 G_CALLBACK (gtk_action_activate),
824 de->insert_variable);
827 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_descending);
829 gtk_widget_show_all (menu);
836 create_data_sheet_cases_popup_menu (PsppireDataWindow *de)
838 GtkWidget *menu = gtk_menu_new ();
840 GtkWidget *insert_case =
841 gtk_menu_item_new_with_label (_("Insert Case"));
843 GtkWidget *delete_case =
844 gtk_menu_item_new_with_label (_("Clear"));
847 gtk_action_connect_proxy (de->delete_cases,
851 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_case);
853 g_signal_connect_swapped (G_OBJECT (insert_case), "activate",
854 G_CALLBACK (gtk_action_activate),
858 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
859 gtk_separator_menu_item_new ());
862 gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_case);
865 gtk_widget_show_all (menu);
872 create_var_sheet_variable_popup_menu (PsppireDataWindow *de)
874 GtkWidget *menu = gtk_menu_new ();
876 GtkWidget *insert_variable =
877 gtk_menu_item_new_with_label (_("Insert Variable"));
879 GtkWidget *delete_variable =
880 gtk_menu_item_new_with_label (_("Clear"));
883 gtk_action_connect_proxy (de->delete_variables,
887 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
889 g_signal_connect_swapped (G_OBJECT (insert_variable), "activate",
890 G_CALLBACK (gtk_action_activate),
891 de->insert_variable);
894 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
895 gtk_separator_menu_item_new ());
898 gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_variable);
901 gtk_widget_show_all (menu);
907 #if RECENT_LISTS_AVAILABLE
910 on_recent_data_select (GtkMenuShell *menushell, gpointer user_data)
913 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
916 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
918 file = g_filename_from_uri (uri, NULL, NULL);
922 open_data_file (file, de);
928 on_recent_files_select (GtkMenuShell *menushell, gpointer user_data)
935 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
937 file = g_filename_from_uri (uri, NULL, NULL);
941 se = psppire_syntax_window_new ();
943 psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file, NULL);
944 gtk_widget_show (se);
952 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
954 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
956 gtk_action_set_visible (de->delete_cases, case_num != -1);
961 enable_delete_variables (GtkWidget *w, gint var, gpointer data)
963 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
965 gtk_action_set_visible (de->delete_variables, var != -1);
968 /* Callback for when the datasheet/varsheet is selected */
970 on_switch_sheet (GtkNotebook *notebook,
971 GtkNotebookPage *page,
975 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
977 GtkWidget *view_data = get_widget_assert (de->xml, "view_data");
978 GtkWidget *view_variables = get_widget_assert (de->xml, "view_variables");
982 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
983 gtk_widget_hide (view_variables);
984 gtk_widget_show (view_data);
985 gtk_action_set_sensitive (de->insert_variable, TRUE);
986 gtk_action_set_sensitive (de->insert_case, FALSE);
987 gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
989 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
990 gtk_widget_show (view_variables);
991 gtk_widget_hide (view_data);
992 gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
993 gtk_action_set_sensitive (de->insert_case, TRUE);
996 g_assert_not_reached ();
1001 update_paste_menuitem (de, page_num);
1009 psppire_data_window_init (PsppireDataWindow *de)
1011 PsppireVarStore *vs;
1017 GtkWidget *box = gtk_vbox_new (FALSE, 0);
1018 de->xml = XML_NEW ("data-editor.glade");
1020 menubar = get_widget_assert (de->xml, "menubar");
1021 hb = get_widget_assert (de->xml, "handlebox1");
1022 sb = get_widget_assert (de->xml, "status-bar");
1025 PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
1027 connect_help (de->xml);
1029 g_object_ref (menubar);
1030 gtk_widget_unparent (menubar);
1033 gtk_widget_unparent (hb);
1036 gtk_widget_unparent (sb);
1038 gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0);
1039 gtk_box_pack_start (GTK_BOX (box), hb, FALSE, TRUE, 0);
1040 gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (de->data_editor), TRUE, TRUE, 0);
1041 gtk_box_pack_start (GTK_BOX (box), sb, FALSE, TRUE, 0);
1043 gtk_container_add (GTK_CONTAINER (de), box);
1045 g_signal_connect (de->data_editor, "data-selection-changed",
1046 G_CALLBACK (update_cut_copy_menuitems), de);
1048 g_signal_connect (de->data_editor, "data-available-changed",
1049 G_CALLBACK (update_paste_menuitems), de);
1051 dataset_add_transform_change_callback (the_dataset,
1052 transformation_change_callback,
1058 g_assert(vs); /* Traps a possible bug in w32 build */
1060 g_signal_connect (vs->dict, "weight-changed",
1061 G_CALLBACK (on_weight_change),
1064 g_signal_connect (vs->dict, "filter-changed",
1065 G_CALLBACK (on_filter_change),
1068 g_signal_connect (vs->dict, "split-changed",
1069 G_CALLBACK (on_split_change),
1073 g_signal_connect (get_widget_assert (de->xml, "edit_copy"),
1075 G_CALLBACK (on_edit_copy), de);
1077 g_signal_connect (get_widget_assert (de->xml, "edit_cut"),
1079 G_CALLBACK (on_edit_cut), de);
1082 register_data_editor_actions (de);
1084 de->toggle_value_labels =
1085 gtk_toggle_action_new ("toggle-value-labels",
1087 _("Show/hide value labels"),
1088 "pspp-value-labels");
1090 g_signal_connect (de->toggle_value_labels, "toggled",
1091 G_CALLBACK (toggle_value_labels), de);
1094 gtk_action_connect_proxy (GTK_ACTION (de->toggle_value_labels),
1095 get_widget_assert (de->xml,
1096 "togglebutton-value-labels"));
1099 gtk_action_connect_proxy (GTK_ACTION (de->toggle_value_labels),
1100 get_widget_assert (de->xml,
1101 "view_value-labels"));
1106 gtk_action_new ("clear-cases",
1108 _("Delete the cases at the selected position(s)"),
1109 "pspp-clear-cases");
1111 g_signal_connect_swapped (de->delete_cases, "activate",
1112 G_CALLBACK (psppire_data_editor_delete_cases),
1115 gtk_action_connect_proxy (de->delete_cases,
1116 get_widget_assert (de->xml, "edit_clear-cases"));
1118 g_signal_connect (get_widget_assert (de->xml, "edit_paste"), "activate",
1119 G_CALLBACK (on_edit_paste),
1122 gtk_action_set_visible (de->delete_cases, FALSE);
1124 de->delete_variables =
1125 gtk_action_new ("clear-variables",
1127 _("Delete the variables at the selected position(s)"),
1128 "pspp-clear-variables");
1130 g_signal_connect_swapped (de->delete_variables, "activate",
1131 G_CALLBACK (psppire_data_editor_delete_variables),
1134 gtk_action_connect_proxy (de->delete_variables,
1135 get_widget_assert (de->xml, "edit_clear-variables")
1138 gtk_action_set_visible (de->delete_variables, FALSE);
1140 de->insert_variable =
1141 gtk_action_new ("insert-variable",
1142 _("Insert _Variable"),
1143 _("Create a new variable at the current position"),
1144 "pspp-insert-variable");
1146 g_signal_connect (de->insert_variable, "activate",
1147 G_CALLBACK (on_insert_variable), de->data_editor);
1150 gtk_action_connect_proxy (de->insert_variable,
1151 get_widget_assert (de->xml, "button-insert-variable")
1154 gtk_action_connect_proxy (de->insert_variable,
1155 get_widget_assert (de->xml, "edit_insert-variable")
1160 gtk_action_new ("insert-case",
1162 _("Create a new case at the current position"),
1163 "pspp-insert-case");
1165 g_signal_connect (de->insert_case, "activate",
1166 G_CALLBACK (insert_case), de);
1169 gtk_action_connect_proxy (de->insert_case,
1170 get_widget_assert (de->xml, "button-insert-case")
1174 gtk_action_connect_proxy (de->insert_case,
1175 get_widget_assert (de->xml, "edit_insert-case")
1179 de->invoke_goto_dialog =
1180 gtk_action_new ("goto-case-dialog",
1182 _("Jump to a Case in the Data Sheet"),
1186 gtk_action_connect_proxy (de->invoke_goto_dialog,
1187 get_widget_assert (de->xml, "button-goto-case")
1190 gtk_action_connect_proxy (de->invoke_goto_dialog,
1191 get_widget_assert (de->xml, "edit_goto-case")
1195 g_signal_connect (de->invoke_goto_dialog, "activate",
1196 G_CALLBACK (goto_case_dialog), de);
1198 de->invoke_weight_cases_dialog =
1199 gtk_action_new ("weight-cases-dialog",
1201 _("Weight cases by variable"),
1202 "pspp-weight-cases");
1204 g_signal_connect (de->invoke_weight_cases_dialog, "activate",
1205 G_CALLBACK (weight_cases_dialog), de);
1208 de->invoke_transpose_dialog =
1209 gtk_action_new ("transpose-dialog",
1211 _("Transpose the cases with the variables"),
1215 g_signal_connect (de->invoke_transpose_dialog, "activate",
1216 G_CALLBACK (transpose_dialog), de);
1220 de->invoke_split_file_dialog =
1221 gtk_action_new ("split-file-dialog",
1223 _("Split the active file"),
1226 g_signal_connect (de->invoke_split_file_dialog, "activate",
1227 G_CALLBACK (split_file_dialog), de);
1231 de->invoke_sort_cases_dialog =
1232 gtk_action_new ("sort-cases-dialog",
1234 _("Sort cases in the active file"),
1237 g_signal_connect (de->invoke_sort_cases_dialog, "activate",
1238 G_CALLBACK (sort_cases_dialog), de);
1240 de->invoke_select_cases_dialog =
1241 gtk_action_new ("select-cases-dialog",
1243 _("Select cases from the active file"),
1244 "pspp-select-cases");
1246 g_signal_connect (de->invoke_select_cases_dialog, "activate",
1247 G_CALLBACK (select_cases_dialog), de);
1250 de->invoke_compute_dialog =
1251 gtk_action_new ("compute-dialog",
1253 _("Compute new values for a variable"),
1256 g_signal_connect (de->invoke_compute_dialog, "activate",
1257 G_CALLBACK (compute_dialog), de);
1259 de->invoke_oneway_anova_dialog =
1260 gtk_action_new ("oneway-anova",
1262 _("Perform one way analysis of variance"),
1265 g_signal_connect (de->invoke_oneway_anova_dialog, "activate",
1266 G_CALLBACK (oneway_anova_dialog), de);
1268 de->invoke_t_test_independent_samples_dialog =
1269 gtk_action_new ("t-test-independent-samples",
1270 _("_Independent Samples T Test"),
1271 _("Calculate T Test for samples from independent groups"),
1274 g_signal_connect (de->invoke_t_test_independent_samples_dialog, "activate",
1275 G_CALLBACK (t_test_independent_samples_dialog), de);
1278 de->invoke_t_test_paired_samples_dialog =
1279 gtk_action_new ("t-test-paired-samples",
1280 _("_Paired Samples T Test"),
1281 _("Calculate T Test for paired samples"),
1284 g_signal_connect (de->invoke_t_test_paired_samples_dialog, "activate",
1285 G_CALLBACK (t_test_paired_samples_dialog), de);
1288 de->invoke_t_test_one_sample_dialog =
1289 gtk_action_new ("t-test-one-sample",
1290 _("One _Sample T Test"),
1291 _("Calculate T Test for sample from a single distribution"),
1294 g_signal_connect (de->invoke_t_test_one_sample_dialog, "activate",
1295 G_CALLBACK (t_test_one_sample_dialog), de);
1298 de->invoke_comments_dialog =
1299 gtk_action_new ("commments-dialog",
1300 _("Data File _Comments"),
1301 _("Commentary text for the data file"),
1304 g_signal_connect (de->invoke_comments_dialog, "activate",
1305 G_CALLBACK (comments_dialog), de);
1307 de->invoke_find_dialog =
1308 gtk_action_new ("find-dialog",
1313 g_signal_connect (de->invoke_find_dialog, "activate",
1314 G_CALLBACK (find_dialog), de);
1317 de->invoke_rank_dialog =
1318 gtk_action_new ("rank-dialog",
1323 g_signal_connect (de->invoke_rank_dialog, "activate",
1324 G_CALLBACK (rank_dialog), de);
1327 de->invoke_recode_same_dialog =
1328 gtk_action_new ("recode-same-dialog",
1329 _("Recode into _Same Variables"),
1330 _("Recode values into the same Variables"),
1331 "pspp-recode-same");
1333 g_signal_connect (de->invoke_recode_same_dialog, "activate",
1334 G_CALLBACK (recode_same_dialog), de);
1337 de->invoke_recode_different_dialog =
1338 gtk_action_new ("recode-different-dialog",
1339 _("Recode into _Different Variables"),
1340 _("Recode values into different Variables"),
1341 "pspp-recode-different");
1343 g_signal_connect (de->invoke_recode_different_dialog, "activate",
1344 G_CALLBACK (recode_different_dialog), de);
1347 de->invoke_variable_info_dialog =
1348 gtk_action_new ("variable-info-dialog",
1350 _("Jump to Variable"),
1351 "pspp-goto-variable");
1353 g_signal_connect (de->invoke_variable_info_dialog, "activate",
1354 G_CALLBACK (variable_info_dialog), de);
1356 de->invoke_descriptives_dialog =
1357 gtk_action_new ("descriptives-dialog",
1359 _("Calculate descriptive statistics (mean, variance, ...)"),
1360 "pspp-descriptives");
1362 g_signal_connect (de->invoke_descriptives_dialog, "activate",
1363 G_CALLBACK (descriptives_dialog), de);
1366 de->invoke_frequencies_dialog =
1367 gtk_action_new ("frequencies-dialog",
1369 _("Generate frequency statistics"),
1370 "pspp-frequencies");
1372 g_signal_connect (de->invoke_frequencies_dialog, "activate",
1373 G_CALLBACK (frequencies_dialog), de);
1375 de->invoke_crosstabs_dialog =
1376 gtk_action_new ("crosstabs-dialog",
1378 _("Generate crosstabulations"),
1381 g_signal_connect (de->invoke_crosstabs_dialog, "activate",
1382 G_CALLBACK (crosstabs_dialog), de);
1385 de->invoke_examine_dialog =
1386 gtk_action_new ("examine-dialog",
1388 _("Examine Data by Factors"),
1391 g_signal_connect (de->invoke_examine_dialog, "activate",
1392 G_CALLBACK (examine_dialog), de);
1395 de->invoke_regression_dialog =
1396 gtk_action_new ("regression-dialog",
1397 _("Linear _Regression"),
1398 _("Estimate parameters of the linear model"),
1401 g_signal_connect (de->invoke_regression_dialog, "activate",
1402 G_CALLBACK (regression_dialog), de);
1404 g_signal_connect_swapped (get_widget_assert (de->xml,"file_new_data"),
1406 G_CALLBACK (gtk_action_activate),
1407 de->action_data_new);
1409 g_signal_connect_swapped (get_widget_assert (de->xml,"file_open_data"),
1411 G_CALLBACK (gtk_action_activate),
1412 de->action_data_open);
1414 #if RECENT_LISTS_AVAILABLE
1416 GtkRecentManager *rm = gtk_recent_manager_get_default ();
1417 GtkWidget *recent_data = get_widget_assert (de->xml, "file_recent-data");
1418 GtkWidget *recent_files = get_widget_assert (de->xml, "file_recent-files");
1419 GtkWidget *recent_separator = get_widget_assert (de->xml, "file_separator1");
1421 GtkWidget *menu = gtk_recent_chooser_menu_new_for_manager (rm);
1423 GtkRecentFilter *filter = gtk_recent_filter_new ();
1425 gtk_widget_show (recent_data);
1426 gtk_widget_show (recent_files);
1427 gtk_widget_show (recent_separator);
1429 gtk_recent_filter_add_pattern (filter, "*.sav");
1430 gtk_recent_filter_add_pattern (filter, "*.SAV");
1432 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
1434 gtk_widget_set_sensitive (recent_data, TRUE);
1435 g_signal_connect (menu, "selection-done",
1436 G_CALLBACK (on_recent_data_select), de);
1438 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu);
1441 filter = gtk_recent_filter_new ();
1442 menu = gtk_recent_chooser_menu_new_for_manager (rm);
1444 gtk_recent_filter_add_pattern (filter, "*.sps");
1445 gtk_recent_filter_add_pattern (filter, "*.SPS");
1447 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
1449 gtk_widget_set_sensitive (recent_files, TRUE);
1450 g_signal_connect (menu, "selection-done",
1451 G_CALLBACK (on_recent_files_select), de);
1453 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu);
1457 g_signal_connect (get_widget_assert (de->xml,"file_new_syntax"),
1459 G_CALLBACK (create_syntax_window),
1462 g_signal_connect (get_widget_assert (de->xml,"file_open_syntax"),
1464 G_CALLBACK (open_syntax_window),
1467 g_signal_connect_swapped (get_widget_assert (de->xml,"file_import-text"),
1469 G_CALLBACK (gtk_action_activate),
1470 de->invoke_text_import_assistant);
1472 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save"),
1474 G_CALLBACK (gtk_action_activate),
1475 de->action_data_save);
1477 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save_as"),
1479 G_CALLBACK (gtk_action_activate),
1480 de->action_data_save_as);
1482 gtk_action_connect_proxy (de->invoke_find_dialog,
1483 get_widget_assert (de->xml, "edit_find")
1486 gtk_action_connect_proxy (de->invoke_find_dialog,
1487 get_widget_assert (de->xml, "button-find")
1490 gtk_action_connect_proxy (de->invoke_rank_dialog,
1491 get_widget_assert (de->xml, "transform_rank")
1494 gtk_action_connect_proxy (de->invoke_recode_same_dialog,
1495 get_widget_assert (de->xml,
1496 "transform_recode-same")
1499 gtk_action_connect_proxy (de->invoke_recode_different_dialog,
1500 get_widget_assert (de->xml,
1501 "transform_recode-different")
1504 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
1505 get_widget_assert (de->xml, "data_weight-cases")
1508 gtk_action_connect_proxy (de->invoke_transpose_dialog,
1509 get_widget_assert (de->xml, "data_transpose")
1512 gtk_action_connect_proxy (de->invoke_split_file_dialog,
1513 get_widget_assert (de->xml, "data_split-file")
1516 gtk_action_connect_proxy (de->invoke_sort_cases_dialog,
1517 get_widget_assert (de->xml, "data_sort-cases")
1520 gtk_action_connect_proxy (de->invoke_select_cases_dialog,
1521 get_widget_assert (de->xml, "data_select-cases")
1524 gtk_action_connect_proxy (de->invoke_compute_dialog,
1525 get_widget_assert (de->xml, "transform_compute")
1528 gtk_action_connect_proxy (de->invoke_t_test_independent_samples_dialog,
1529 get_widget_assert (de->xml,
1534 gtk_action_connect_proxy (de->invoke_t_test_paired_samples_dialog,
1535 get_widget_assert (de->xml,
1540 gtk_action_connect_proxy (de->invoke_t_test_one_sample_dialog,
1541 get_widget_assert (de->xml,
1542 "one-sample-t-test")
1546 gtk_action_connect_proxy (de->invoke_oneway_anova_dialog,
1547 get_widget_assert (de->xml,
1552 gtk_action_connect_proxy (de->invoke_comments_dialog,
1553 get_widget_assert (de->xml, "utilities_comments")
1556 gtk_action_connect_proxy (de->invoke_variable_info_dialog,
1557 get_widget_assert (de->xml, "utilities_variables")
1560 gtk_action_connect_proxy (de->invoke_descriptives_dialog,
1561 get_widget_assert (de->xml, "analyze_descriptives")
1564 gtk_action_connect_proxy (de->invoke_crosstabs_dialog,
1565 get_widget_assert (de->xml, "crosstabs")
1568 gtk_action_connect_proxy (de->invoke_frequencies_dialog,
1569 get_widget_assert (de->xml, "analyze_frequencies")
1573 gtk_action_connect_proxy (de->invoke_examine_dialog,
1574 get_widget_assert (de->xml, "analyze_explore")
1577 gtk_action_connect_proxy (de->invoke_regression_dialog,
1578 get_widget_assert (de->xml, "linear-regression")
1581 g_signal_connect (get_widget_assert (de->xml,"help_about"),
1583 G_CALLBACK (about_new),
1587 g_signal_connect (get_widget_assert (de->xml,"help_reference"),
1589 G_CALLBACK (reference_manual),
1593 g_signal_connect (de->data_editor,
1595 G_CALLBACK (enable_delete_cases),
1598 g_signal_connect (de->data_editor,
1599 "variables-selected",
1600 G_CALLBACK (enable_delete_variables),
1604 g_signal_connect (GTK_NOTEBOOK (de->data_editor),
1606 G_CALLBACK (on_switch_sheet), de);
1608 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1609 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1611 g_signal_connect (get_widget_assert (de->xml, "view_statusbar"),
1613 G_CALLBACK (status_bar_activate), de);
1616 g_signal_connect (get_widget_assert (de->xml, "view_gridlines"),
1618 G_CALLBACK (grid_lines_activate), de);
1622 g_signal_connect (get_widget_assert (de->xml, "view_data"),
1624 G_CALLBACK (data_view_activate), de);
1626 g_signal_connect (get_widget_assert (de->xml, "view_variables"),
1628 G_CALLBACK (variable_view_activate), de);
1632 g_signal_connect (get_widget_assert (de->xml, "view_fonts"),
1634 G_CALLBACK (fonts_activate), de);
1639 gtk_action_connect_proxy (de->action_data_open,
1640 get_widget_assert (de->xml, "button-open")
1643 gtk_action_connect_proxy (de->action_data_save,
1644 get_widget_assert (de->xml, "button-save")
1647 gtk_action_connect_proxy (de->invoke_variable_info_dialog,
1648 get_widget_assert (de->xml, "button-goto-variable")
1651 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
1652 get_widget_assert (de->xml, "button-weight-cases")
1655 gtk_action_connect_proxy (de->invoke_split_file_dialog,
1656 get_widget_assert (de->xml, "button-split-file")
1659 gtk_action_connect_proxy (de->invoke_select_cases_dialog,
1660 get_widget_assert (de->xml, "button-select-cases")
1664 g_signal_connect (get_widget_assert (de->xml, "file_quit"),
1666 G_CALLBACK (file_quit), de);
1668 g_signal_connect (get_widget_assert (de->xml, "transform_run-pending"),
1670 G_CALLBACK (execute), de);
1673 g_signal_connect (get_widget_assert (de->xml, "windows_minimise_all"),
1675 G_CALLBACK (psppire_window_minimise_all), NULL);
1677 de->toggle_split_window =
1678 gtk_toggle_action_new ("toggle-split-window",
1680 _("Split the window vertically and horizontally"),
1681 "pspp-split-window");
1683 g_signal_connect (de->toggle_split_window, "toggled",
1684 G_CALLBACK (toggle_split_window),
1687 gtk_action_connect_proxy (GTK_ACTION (de->toggle_split_window),
1688 get_widget_assert (de->xml,
1691 de->data_sheet_variable_popup_menu =
1692 GTK_MENU (create_data_sheet_variable_popup_menu (de));
1694 de->var_sheet_variable_popup_menu =
1695 GTK_MENU (create_var_sheet_variable_popup_menu (de));
1697 de->data_sheet_cases_popup_menu =
1698 GTK_MENU (create_data_sheet_cases_popup_menu (de));
1700 PSPPIRE_WINDOW (de)->menu = GTK_MENU_SHELL (get_widget_assert (de->xml,"Windows_menu"));
1702 g_object_set (de->data_editor,
1703 "datasheet-column-menu", de->data_sheet_variable_popup_menu,
1704 "datasheet-row-menu", de->data_sheet_cases_popup_menu,
1705 "varsheet-row-menu", de->var_sheet_variable_popup_menu,
1708 gtk_widget_show (GTK_WIDGET (de->data_editor));
1709 gtk_widget_show (box);
1714 psppire_data_window_new (void)
1716 return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
1717 "usage", PSPPIRE_WINDOW_USAGE_DATA,