1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2006, 2007, 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/>. */
21 #include <glade/glade.h>
24 #include "window-manager.h"
26 #include "psppire-data-editor.h"
30 #include <data/procedure.h>
31 #include "psppire-dialog.h"
32 #include "psppire-selector.h"
33 #include "weight-cases-dialog.h"
34 #include "split-file-dialog.h"
35 #include "transpose-dialog.h"
36 #include "sort-cases-dialog.h"
37 #include "select-cases-dialog.h"
38 #include "compute-dialog.h"
39 #include "goto-case-dialog.h"
40 #include "find-dialog.h"
41 #include "rank-dialog.h"
42 #include "recode-dialog.h"
43 #include "comments-dialog.h"
44 #include "variable-info-dialog.h"
45 #include "descriptives-dialog.h"
46 #include "crosstabs-dialog.h"
47 #include "frequencies-dialog.h"
48 #include "examine-dialog.h"
49 #include "dict-display.h"
50 #include "regression-dialog.h"
51 #include "text-data-import-dialog.h"
53 #include "oneway-anova-dialog.h"
54 #include "t-test-independent-samples-dialog.h"
55 #include "t-test-one-sample.h"
56 #include "t-test-paired-samples.h"
58 #define _(msgid) gettext (msgid)
59 #define N_(msgid) msgid
61 #include "data-editor.h"
62 #include "syntax-editor.h"
63 #include <language/syntax-string-source.h>
64 #include <language/command.h>
65 #include <ui/syntax-gen.h>
66 #include "window-manager.h"
68 #include "psppire-data-store.h"
69 #include "psppire-var-store.h"
71 static void on_edit_copy (GtkMenuItem *, gpointer);
72 static void on_edit_cut (GtkMenuItem *, gpointer);
73 static void on_edit_paste (GtkAction *a, gpointer data);
76 static GtkWidget * create_data_sheet_variable_popup_menu (struct data_editor *);
77 static GtkWidget * create_data_sheet_cases_popup_menu (struct data_editor *);
79 static void register_data_editor_actions (struct data_editor *de);
80 static void on_insert_variable (GtkAction *, gpointer data);
81 static void insert_case (GtkAction *a, gpointer data);
83 static void toggle_value_labels (GtkToggleAction *a, gpointer data);
85 /* Callback for when the dictionary changes properties*/
86 static void on_weight_change (GObject *, gint, gpointer);
87 static void on_filter_change (GObject *, gint, gpointer);
88 static void on_split_change (PsppireDict *, gpointer);
90 static void on_switch_sheet (GtkNotebook *notebook,
91 GtkNotebookPage *page,
95 static void status_bar_activate (GtkCheckMenuItem *, gpointer);
97 static void grid_lines_activate (GtkCheckMenuItem *, gpointer);
99 static void data_view_activate (GtkCheckMenuItem *, gpointer);
101 static void variable_view_activate (GtkCheckMenuItem *, gpointer );
103 static void fonts_activate (GtkMenuItem *, gpointer);
105 static void file_quit (GtkCheckMenuItem *, gpointer );
108 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
110 struct data_editor *de = data;
112 gtk_action_set_visible (de->delete_cases, case_num != -1);
117 enable_delete_variables (GtkWidget *w, gint var, gpointer data)
119 struct data_editor *de = data;
121 gtk_action_set_visible (de->delete_variables, var != -1);
126 /* Run the EXECUTE command. */
128 execute (GtkMenuItem *mi, gpointer data)
130 struct getl_interface *sss = create_syntax_string_source ("EXECUTE.");
132 execute_syntax (sss);
136 transformation_change_callback (bool transformations_pending,
139 struct data_editor *de = data;
140 GtkWidget *menuitem =
141 get_widget_assert (de->xml, "transform_run-pending");
142 GtkWidget *status_label =
143 get_widget_assert (de->xml, "case-counter-area");
145 gtk_widget_set_sensitive (menuitem, transformations_pending);
148 if ( transformations_pending)
149 gtk_label_set_text (GTK_LABEL (status_label),
150 _("Transformations Pending"));
152 gtk_label_set_text (GTK_LABEL (status_label), "");
156 static void open_data_file (const gchar *, struct data_editor *);
159 /* Puts FILE_NAME into the recent list.
160 If it's already in the list, it moves it to the top
163 add_most_recent (const char *file_name)
165 #if RECENT_LISTS_AVAILABLE
167 GtkRecentManager *manager = gtk_recent_manager_get_default();
168 gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
170 gtk_recent_manager_remove_item (manager, uri, NULL);
172 if ( ! gtk_recent_manager_add_item (manager, uri))
173 g_warning ("Could not add item %s to recent list\n",uri);
181 #if RECENT_LISTS_AVAILABLE
184 on_recent_data_select (GtkMenuShell *menushell, gpointer user_data)
187 struct data_editor *de = user_data;
190 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
192 file = g_filename_from_uri (uri, NULL, NULL);
196 open_data_file (file, de);
202 on_recent_files_select (GtkMenuShell *menushell, gpointer user_data)
206 struct syntax_editor *se ;
209 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
211 file = g_filename_from_uri (uri, NULL, NULL);
215 se = (struct syntax_editor *)
216 window_create (WINDOW_SYNTAX, file);
218 load_editor_from_file (se, file, NULL);
227 update_paste_menuitems (GtkWidget *w, gboolean x, gpointer data)
229 struct data_editor *de = data;
231 GtkWidget * edit_paste = get_widget_assert (de->xml, "edit_paste");
233 gtk_widget_set_sensitive (edit_paste, x);
237 update_cut_copy_menuitems (GtkWidget *w, gboolean x, gpointer data)
239 struct data_editor *de = data;
241 GtkWidget * edit_copy = get_widget_assert (de->xml, "edit_copy");
242 GtkWidget * edit_cut = get_widget_assert (de->xml, "edit_cut");
244 gtk_widget_set_sensitive (edit_copy, x);
245 gtk_widget_set_sensitive (edit_cut, x);
248 extern PsppireVarStore *the_var_store;
249 extern struct dataset *the_dataset;
250 extern PsppireDataStore *the_data_store ;
254 Create a new data editor.
257 new_data_editor (void)
259 struct data_editor *de ;
260 struct editor_window *e;
264 de = g_malloc0 (sizeof (*de));
266 e = (struct editor_window *) de;
268 de->xml = XML_NEW ("data-editor.glade");
271 vbox = get_widget_assert (de->xml, "vbox1");
273 de->data_editor = PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
275 g_signal_connect (de->data_editor, "data-selection-changed",
276 G_CALLBACK (update_cut_copy_menuitems), de);
278 g_signal_connect (de->data_editor, "data-available-changed",
279 G_CALLBACK (update_paste_menuitems), de);
282 gtk_widget_show (GTK_WIDGET (de->data_editor));
284 gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (de->data_editor));
285 gtk_box_reorder_child (GTK_BOX (vbox) , GTK_WIDGET (de->data_editor), 2);
286 dataset_add_transform_change_callback (the_dataset,
287 transformation_change_callback,
292 g_assert(vs); /* Traps a possible bug in w32 build */
294 g_signal_connect (vs->dict, "weight-changed",
295 G_CALLBACK (on_weight_change),
298 g_signal_connect (vs->dict, "filter-changed",
299 G_CALLBACK (on_filter_change),
302 g_signal_connect (vs->dict, "split-changed",
303 G_CALLBACK (on_split_change),
306 connect_help (de->xml);
310 g_signal_connect (get_widget_assert (de->xml, "edit_copy"),
312 G_CALLBACK (on_edit_copy), de);
314 g_signal_connect (get_widget_assert (de->xml, "edit_cut"),
316 G_CALLBACK (on_edit_cut), de);
319 register_data_editor_actions (de);
321 de->toggle_value_labels =
322 gtk_toggle_action_new ("toggle-value-labels",
324 _("Show/hide value labels"),
325 "pspp-value-labels");
327 g_signal_connect (de->toggle_value_labels, "toggled",
328 G_CALLBACK (toggle_value_labels), de);
331 gtk_action_connect_proxy (GTK_ACTION (de->toggle_value_labels),
332 get_widget_assert (de->xml,
333 "togglebutton-value-labels"));
336 gtk_action_connect_proxy (GTK_ACTION (de->toggle_value_labels),
337 get_widget_assert (de->xml,
338 "view_value-labels"));
341 gtk_action_new ("clear-cases",
343 _("Delete the cases at the selected position(s)"),
346 g_signal_connect_swapped (de->delete_cases, "activate",
347 G_CALLBACK (psppire_data_editor_delete_cases),
350 gtk_action_connect_proxy (de->delete_cases,
351 get_widget_assert (de->xml, "edit_clear-cases"));
353 g_signal_connect (get_widget_assert (de->xml, "edit_paste"), "activate",
354 G_CALLBACK (on_edit_paste),
357 gtk_action_set_visible (de->delete_cases, FALSE);
359 de->delete_variables =
360 gtk_action_new ("clear-variables",
362 _("Delete the variables at the selected position(s)"),
363 "pspp-clear-variables");
365 g_signal_connect_swapped (de->delete_variables, "activate",
366 G_CALLBACK (psppire_data_editor_delete_variables),
369 gtk_action_connect_proxy (de->delete_variables,
370 get_widget_assert (de->xml, "edit_clear-variables")
373 gtk_action_set_visible (de->delete_variables, FALSE);
375 de->insert_variable =
376 gtk_action_new ("insert-variable",
377 _("Insert _Variable"),
378 _("Create a new variable at the current position"),
379 "pspp-insert-variable");
381 g_signal_connect (de->insert_variable, "activate",
382 G_CALLBACK (on_insert_variable), de->data_editor);
385 gtk_action_connect_proxy (de->insert_variable,
386 get_widget_assert (de->xml, "button-insert-variable")
389 gtk_action_connect_proxy (de->insert_variable,
390 get_widget_assert (de->xml, "edit_insert-variable")
395 gtk_action_new ("insert-case",
397 _("Create a new case at the current position"),
400 g_signal_connect (de->insert_case, "activate",
401 G_CALLBACK (insert_case), de);
404 gtk_action_connect_proxy (de->insert_case,
405 get_widget_assert (de->xml, "button-insert-case")
409 gtk_action_connect_proxy (de->insert_case,
410 get_widget_assert (de->xml, "edit_insert-case")
415 de->invoke_goto_dialog =
416 gtk_action_new ("goto-case-dialog",
418 _("Jump to a Case in the Data Sheet"),
422 gtk_action_connect_proxy (de->invoke_goto_dialog,
423 get_widget_assert (de->xml, "button-goto-case")
426 gtk_action_connect_proxy (de->invoke_goto_dialog,
427 get_widget_assert (de->xml, "edit_goto-case")
431 g_signal_connect (de->invoke_goto_dialog, "activate",
432 G_CALLBACK (goto_case_dialog), de);
435 de->invoke_weight_cases_dialog =
436 gtk_action_new ("weight-cases-dialog",
438 _("Weight cases by variable"),
439 "pspp-weight-cases");
441 g_signal_connect (de->invoke_weight_cases_dialog, "activate",
442 G_CALLBACK (weight_cases_dialog), de);
445 de->invoke_transpose_dialog =
446 gtk_action_new ("transpose-dialog",
448 _("Transpose the cases with the variables"),
452 g_signal_connect (de->invoke_transpose_dialog, "activate",
453 G_CALLBACK (transpose_dialog), de);
457 de->invoke_split_file_dialog =
458 gtk_action_new ("split-file-dialog",
460 _("Split the active file"),
463 g_signal_connect (de->invoke_split_file_dialog, "activate",
464 G_CALLBACK (split_file_dialog), de);
468 de->invoke_sort_cases_dialog =
469 gtk_action_new ("sort-cases-dialog",
471 _("Sort cases in the active file"),
474 g_signal_connect (de->invoke_sort_cases_dialog, "activate",
475 G_CALLBACK (sort_cases_dialog), de);
477 de->invoke_select_cases_dialog =
478 gtk_action_new ("select-cases-dialog",
480 _("Select cases from the active file"),
481 "pspp-select-cases");
483 g_signal_connect (de->invoke_select_cases_dialog, "activate",
484 G_CALLBACK (select_cases_dialog), de);
487 de->invoke_compute_dialog =
488 gtk_action_new ("compute-dialog",
490 _("Compute new values for a variable"),
493 g_signal_connect (de->invoke_compute_dialog, "activate",
494 G_CALLBACK (compute_dialog), de);
496 de->invoke_oneway_anova_dialog =
497 gtk_action_new ("oneway-anova",
499 _("Perform one way analysis of variance"),
502 g_signal_connect (de->invoke_oneway_anova_dialog, "activate",
503 G_CALLBACK (oneway_anova_dialog), de);
505 de->invoke_t_test_independent_samples_dialog =
506 gtk_action_new ("t-test-independent-samples",
507 _("_Independent Samples T Test"),
508 _("Calculate T Test for samples from independent groups"),
511 g_signal_connect (de->invoke_t_test_independent_samples_dialog, "activate",
512 G_CALLBACK (t_test_independent_samples_dialog), de);
515 de->invoke_t_test_paired_samples_dialog =
516 gtk_action_new ("t-test-paired-samples",
517 _("_Paired Samples T Test"),
518 _("Calculate T Test for paired samples"),
521 g_signal_connect (de->invoke_t_test_paired_samples_dialog, "activate",
522 G_CALLBACK (t_test_paired_samples_dialog), de);
525 de->invoke_t_test_one_sample_dialog =
526 gtk_action_new ("t-test-one-sample",
527 _("One _Sample T Test"),
528 _("Calculate T Test for sample from a single distribution"),
531 g_signal_connect (de->invoke_t_test_one_sample_dialog, "activate",
532 G_CALLBACK (t_test_one_sample_dialog), de);
535 de->invoke_comments_dialog =
536 gtk_action_new ("commments-dialog",
537 _("Data File _Comments"),
538 _("Commentary text for the data file"),
541 g_signal_connect (de->invoke_comments_dialog, "activate",
542 G_CALLBACK (comments_dialog), de);
544 de->invoke_find_dialog =
545 gtk_action_new ("find-dialog",
550 g_signal_connect (de->invoke_find_dialog, "activate",
551 G_CALLBACK (find_dialog), de);
554 de->invoke_rank_dialog =
555 gtk_action_new ("rank-dialog",
560 g_signal_connect (de->invoke_rank_dialog, "activate",
561 G_CALLBACK (rank_dialog), de);
564 de->invoke_recode_same_dialog =
565 gtk_action_new ("recode-same-dialog",
566 _("Recode into _Same Variables"),
567 _("Recode values into the same Variables"),
570 g_signal_connect (de->invoke_recode_same_dialog, "activate",
571 G_CALLBACK (recode_same_dialog), de);
574 de->invoke_recode_different_dialog =
575 gtk_action_new ("recode-different-dialog",
576 _("Recode into _Different Variables"),
577 _("Recode values into different Variables"),
578 "pspp-recode-different");
580 g_signal_connect (de->invoke_recode_different_dialog, "activate",
581 G_CALLBACK (recode_different_dialog), de);
584 de->invoke_variable_info_dialog =
585 gtk_action_new ("variable-info-dialog",
587 _("Jump to Variable"),
588 "pspp-goto-variable");
590 g_signal_connect (de->invoke_variable_info_dialog, "activate",
591 G_CALLBACK (variable_info_dialog), de);
593 de->invoke_descriptives_dialog =
594 gtk_action_new ("descriptives-dialog",
596 _("Calculate descriptive statistics (mean, variance, ...)"),
597 "pspp-descriptives");
599 g_signal_connect (de->invoke_descriptives_dialog, "activate",
600 G_CALLBACK (descriptives_dialog), de);
603 de->invoke_frequencies_dialog =
604 gtk_action_new ("frequencies-dialog",
606 _("Generate frequency statistics"),
609 g_signal_connect (de->invoke_frequencies_dialog, "activate",
610 G_CALLBACK (frequencies_dialog), de);
612 de->invoke_crosstabs_dialog =
613 gtk_action_new ("crosstabs-dialog",
615 _("Generate crosstabulations"),
618 g_signal_connect (de->invoke_crosstabs_dialog, "activate",
619 G_CALLBACK (crosstabs_dialog), de);
622 de->invoke_examine_dialog =
623 gtk_action_new ("examine-dialog",
625 _("Examine Data by Factors"),
628 g_signal_connect (de->invoke_examine_dialog, "activate",
629 G_CALLBACK (examine_dialog), de);
632 de->invoke_regression_dialog =
633 gtk_action_new ("regression-dialog",
634 _("Linear _Regression"),
635 _("Estimate parameters of the linear model"),
638 g_signal_connect (de->invoke_regression_dialog, "activate",
639 G_CALLBACK (regression_dialog), de);
641 e->window = GTK_WINDOW (get_widget_assert (de->xml, "data_editor"));
643 g_signal_connect_swapped (get_widget_assert (de->xml,"file_new_data"),
645 G_CALLBACK (gtk_action_activate),
646 de->action_data_new);
648 g_signal_connect_swapped (get_widget_assert (de->xml,"file_open_data"),
650 G_CALLBACK (gtk_action_activate),
651 de->action_data_open);
653 #if RECENT_LISTS_AVAILABLE
655 GtkRecentManager *rm = gtk_recent_manager_get_default ();
656 GtkWidget *recent_data = get_widget_assert (de->xml, "file_recent-data");
657 GtkWidget *recent_files = get_widget_assert (de->xml, "file_recent-files");
658 GtkWidget *recent_separator = get_widget_assert (de->xml, "file_separator1");
660 GtkWidget *menu = gtk_recent_chooser_menu_new_for_manager (rm);
662 GtkRecentFilter *filter = gtk_recent_filter_new ();
664 gtk_widget_show (recent_data);
665 gtk_widget_show (recent_files);
666 gtk_widget_show (recent_separator);
668 gtk_recent_filter_add_pattern (filter, "*.sav");
669 gtk_recent_filter_add_pattern (filter, "*.SAV");
671 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
673 gtk_widget_set_sensitive (recent_data, TRUE);
674 g_signal_connect (menu, "selection-done",
675 G_CALLBACK (on_recent_data_select), de);
677 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu);
680 filter = gtk_recent_filter_new ();
681 menu = gtk_recent_chooser_menu_new_for_manager (rm);
683 gtk_recent_filter_add_pattern (filter, "*.sps");
684 gtk_recent_filter_add_pattern (filter, "*.SPS");
686 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
688 gtk_widget_set_sensitive (recent_files, TRUE);
689 g_signal_connect (menu, "selection-done",
690 G_CALLBACK (on_recent_files_select), de);
692 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu);
696 g_signal_connect (get_widget_assert (de->xml,"file_new_syntax"),
698 G_CALLBACK (new_syntax_window),
701 g_signal_connect (get_widget_assert (de->xml,"file_open_syntax"),
703 G_CALLBACK (open_syntax_window),
706 g_signal_connect_swapped (get_widget_assert (de->xml,"file_import-text"),
708 G_CALLBACK (gtk_action_activate),
709 de->invoke_text_import_assistant);
711 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save"),
713 G_CALLBACK (gtk_action_activate),
714 de->action_data_save);
716 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save_as"),
718 G_CALLBACK (gtk_action_activate),
719 de->action_data_save_as);
721 gtk_action_connect_proxy (de->invoke_find_dialog,
722 get_widget_assert (de->xml, "edit_find")
725 gtk_action_connect_proxy (de->invoke_find_dialog,
726 get_widget_assert (de->xml, "button-find")
729 gtk_action_connect_proxy (de->invoke_rank_dialog,
730 get_widget_assert (de->xml, "transform_rank")
733 gtk_action_connect_proxy (de->invoke_recode_same_dialog,
734 get_widget_assert (de->xml,
735 "transform_recode-same")
738 gtk_action_connect_proxy (de->invoke_recode_different_dialog,
739 get_widget_assert (de->xml,
740 "transform_recode-different")
743 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
744 get_widget_assert (de->xml, "data_weight-cases")
747 gtk_action_connect_proxy (de->invoke_transpose_dialog,
748 get_widget_assert (de->xml, "data_transpose")
751 gtk_action_connect_proxy (de->invoke_split_file_dialog,
752 get_widget_assert (de->xml, "data_split-file")
755 gtk_action_connect_proxy (de->invoke_sort_cases_dialog,
756 get_widget_assert (de->xml, "data_sort-cases")
759 gtk_action_connect_proxy (de->invoke_select_cases_dialog,
760 get_widget_assert (de->xml, "data_select-cases")
763 gtk_action_connect_proxy (de->invoke_compute_dialog,
764 get_widget_assert (de->xml, "transform_compute")
767 gtk_action_connect_proxy (de->invoke_t_test_independent_samples_dialog,
768 get_widget_assert (de->xml,
773 gtk_action_connect_proxy (de->invoke_t_test_paired_samples_dialog,
774 get_widget_assert (de->xml,
779 gtk_action_connect_proxy (de->invoke_t_test_one_sample_dialog,
780 get_widget_assert (de->xml,
785 gtk_action_connect_proxy (de->invoke_oneway_anova_dialog,
786 get_widget_assert (de->xml,
791 gtk_action_connect_proxy (de->invoke_comments_dialog,
792 get_widget_assert (de->xml, "utilities_comments")
795 gtk_action_connect_proxy (de->invoke_variable_info_dialog,
796 get_widget_assert (de->xml, "utilities_variables")
799 gtk_action_connect_proxy (de->invoke_descriptives_dialog,
800 get_widget_assert (de->xml, "analyze_descriptives")
803 gtk_action_connect_proxy (de->invoke_crosstabs_dialog,
804 get_widget_assert (de->xml, "crosstabs")
807 gtk_action_connect_proxy (de->invoke_frequencies_dialog,
808 get_widget_assert (de->xml, "analyze_frequencies")
812 gtk_action_connect_proxy (de->invoke_examine_dialog,
813 get_widget_assert (de->xml, "analyze_explore")
816 gtk_action_connect_proxy (de->invoke_regression_dialog,
817 get_widget_assert (de->xml, "linear-regression")
820 g_signal_connect (get_widget_assert (de->xml,"help_about"),
822 G_CALLBACK (about_new),
826 g_signal_connect (get_widget_assert (de->xml,"help_reference"),
828 G_CALLBACK (reference_manual),
832 g_signal_connect (de->data_editor,
834 G_CALLBACK (enable_delete_cases),
838 g_signal_connect (de->data_editor,
839 "variables-selected",
840 G_CALLBACK (enable_delete_variables),
844 g_signal_connect (GTK_NOTEBOOK (de->data_editor),
846 G_CALLBACK (on_switch_sheet), de);
848 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
849 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
851 g_signal_connect (get_widget_assert (de->xml, "view_statusbar"),
853 G_CALLBACK (status_bar_activate), de);
856 g_signal_connect (get_widget_assert (de->xml, "view_gridlines"),
858 G_CALLBACK (grid_lines_activate), de);
862 g_signal_connect (get_widget_assert (de->xml, "view_data"),
864 G_CALLBACK (data_view_activate), de);
866 g_signal_connect (get_widget_assert (de->xml, "view_variables"),
868 G_CALLBACK (variable_view_activate), de);
872 g_signal_connect (get_widget_assert (de->xml, "view_fonts"),
874 G_CALLBACK (fonts_activate), de);
879 gtk_action_connect_proxy (de->action_data_open,
880 get_widget_assert (de->xml, "button-open")
883 gtk_action_connect_proxy (de->action_data_save,
884 get_widget_assert (de->xml, "button-save")
887 gtk_action_connect_proxy (de->invoke_variable_info_dialog,
888 get_widget_assert (de->xml, "button-goto-variable")
891 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
892 get_widget_assert (de->xml, "button-weight-cases")
895 gtk_action_connect_proxy (de->invoke_split_file_dialog,
896 get_widget_assert (de->xml, "button-split-file")
899 gtk_action_connect_proxy (de->invoke_select_cases_dialog,
900 get_widget_assert (de->xml, "button-select-cases")
904 g_signal_connect (get_widget_assert (de->xml, "file_quit"),
906 G_CALLBACK (file_quit), de);
908 g_signal_connect (get_widget_assert (de->xml, "transform_run-pending"),
910 G_CALLBACK (execute), de);
913 g_signal_connect (get_widget_assert (de->xml, "windows_minimise_all"),
915 G_CALLBACK (minimise_all_windows), NULL);
918 de->data_sheet_variable_popup_menu =
919 GTK_MENU (create_data_sheet_variable_popup_menu (de));
921 de->data_sheet_cases_popup_menu =
922 GTK_MENU (create_data_sheet_cases_popup_menu (de));
925 g_object_set (de->data_editor,
926 "column-menu", de->data_sheet_variable_popup_menu, NULL);
929 g_object_set (de->data_editor,
930 "row-menu", de->data_sheet_cases_popup_menu, NULL);
937 new_data_window (GtkMenuItem *menuitem, gpointer parent)
939 window_create (WINDOW_DATA, NULL);
942 /* Callback for when the datasheet/varsheet is selected */
944 on_switch_sheet (GtkNotebook *notebook,
945 GtkNotebookPage *page,
949 struct data_editor *de = user_data;
951 GtkWidget *view_data = get_widget_assert (de->xml, "view_data");
952 GtkWidget *view_variables = get_widget_assert (de->xml, "view_variables");
956 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
957 gtk_widget_hide (view_variables);
958 gtk_widget_show (view_data);
959 gtk_action_set_sensitive (de->insert_variable, TRUE);
960 gtk_action_set_sensitive (de->insert_case, FALSE);
961 gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
963 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
964 gtk_widget_show (view_variables);
965 gtk_widget_hide (view_data);
966 gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
967 gtk_action_set_sensitive (de->insert_case, TRUE);
970 g_assert_not_reached ();
975 update_paste_menuitem (de, page_num);
981 status_bar_activate (GtkCheckMenuItem *menuitem, gpointer data)
983 struct data_editor *de = data;
984 GtkWidget *statusbar = get_widget_assert (de->xml, "status-bar");
986 if ( gtk_check_menu_item_get_active (menuitem) )
987 gtk_widget_show (statusbar);
989 gtk_widget_hide (statusbar);
994 grid_lines_activate (GtkCheckMenuItem *menuitem, gpointer data)
996 struct data_editor *de = data;
997 const gboolean grid_visible = gtk_check_menu_item_get_active (menuitem);
999 psppire_data_editor_show_grid (de->data_editor, grid_visible);
1005 data_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
1007 struct data_editor *de = data;
1009 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1014 variable_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
1016 struct data_editor *de = data;
1018 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1023 fonts_activate (GtkMenuItem *menuitem, gpointer data)
1025 struct data_editor *de = data;
1027 gtk_font_selection_dialog_new (_("Font Selection"));
1029 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1030 GTK_WINDOW (get_widget_assert (de->xml,
1032 if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
1034 const gchar *font = gtk_font_selection_dialog_get_font_name
1035 (GTK_FONT_SELECTION_DIALOG (dialog));
1037 PangoFontDescription* font_desc =
1038 pango_font_description_from_string (font);
1040 psppire_data_editor_set_font (de->data_editor, font_desc);
1043 gtk_widget_hide (dialog);
1048 /* Callback for the value labels action */
1050 toggle_value_labels (GtkToggleAction *ta, gpointer data)
1052 struct data_editor *de = data;
1054 g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
1060 file_quit (GtkCheckMenuItem *menuitem, gpointer data)
1062 /* FIXME: Need to be more intelligent here.
1063 Give the user the opportunity to save any unsaved data.
1065 g_object_unref (the_data_store);
1071 insert_case (GtkAction *action, gpointer data)
1073 struct data_editor *de = data;
1075 psppire_data_editor_insert_case (de->data_editor);
1079 on_insert_variable (GtkAction *action, gpointer data)
1081 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
1082 psppire_data_editor_insert_variable (de);
1086 /* Callback for when the dictionary changes its split variables */
1088 on_split_change (PsppireDict *dict, gpointer data)
1090 struct data_editor *de = data;
1092 size_t n_split_vars = dict_get_split_cnt (dict->dict);
1094 GtkWidget *split_status_area =
1095 get_widget_assert (de->xml, "split-file-status-area");
1097 if ( n_split_vars == 0 )
1099 gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
1105 const struct variable *const * split_vars =
1106 dict_get_split_vars (dict->dict);
1108 text = g_string_new (_("Split by "));
1110 for (i = 0 ; i < n_split_vars - 1; ++i )
1112 g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
1114 g_string_append (text, var_get_name (split_vars[i]));
1116 gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
1118 g_string_free (text, TRUE);
1123 /* Callback for when the dictionary changes its filter variable */
1125 on_filter_change (GObject *o, gint filter_index, gpointer data)
1127 struct data_editor *de = data;
1128 GtkWidget *filter_status_area =
1129 get_widget_assert (de->xml, "filter-use-status-area");
1131 if ( filter_index == -1 )
1133 gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
1137 PsppireVarStore *vs = NULL;
1138 struct variable *var ;
1141 g_object_get (de->data_editor, "var-store", &vs, NULL);
1143 var = psppire_dict_get_variable (vs->dict, filter_index);
1145 text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
1147 gtk_label_set_text (GTK_LABEL (filter_status_area), text);
1153 /* Callback for when the dictionary changes its weights */
1155 on_weight_change (GObject *o, gint weight_index, gpointer data)
1157 struct data_editor *de = data;
1158 GtkWidget *weight_status_area =
1159 get_widget_assert (de->xml, "weight-status-area");
1161 if ( weight_index == -1 )
1163 gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
1167 struct variable *var ;
1168 PsppireVarStore *vs = NULL;
1171 g_object_get (de->data_editor, "var-store", &vs, NULL);
1173 var = psppire_dict_get_variable (vs->dict, weight_index);
1175 text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
1177 gtk_label_set_text (GTK_LABEL (weight_status_area), text);
1186 static void data_save_as_dialog (GtkAction *, struct data_editor *de);
1187 static void new_file (GtkAction *, struct editor_window *de);
1188 static void open_data_dialog (GtkAction *, struct data_editor *de);
1189 static void data_save (GtkAction *action, struct data_editor *e);
1192 /* Create the GtkActions and connect to their signals */
1194 register_data_editor_actions (struct data_editor *de)
1196 de->action_data_open =
1197 gtk_action_new ("data-open-dialog",
1199 _("Open a data file"),
1202 g_signal_connect (de->action_data_open, "activate",
1203 G_CALLBACK (open_data_dialog), de);
1206 de->action_data_save = gtk_action_new ("data-save",
1208 _("Save data to file"),
1211 g_signal_connect (de->action_data_save, "activate",
1212 G_CALLBACK (data_save), de);
1216 de->action_data_save_as = gtk_action_new ("data-save-as-dialog",
1218 _("Save data to file"),
1221 g_signal_connect (de->action_data_save_as, "activate",
1222 G_CALLBACK (data_save_as_dialog), de);
1224 de->action_data_new =
1225 gtk_action_new ("data-new",
1230 g_signal_connect (de->action_data_new, "activate",
1231 G_CALLBACK (new_file), de);
1233 de->invoke_text_import_assistant =
1234 gtk_action_new ("file_import-text",
1235 _("_Import Text Data"),
1236 _("Import text data file"),
1239 g_signal_connect (de->invoke_text_import_assistant, "activate",
1240 G_CALLBACK (text_data_import_assistant), de);
1243 /* Returns true if NAME has a suffix which might denote a PSPP file */
1245 name_has_suffix (const gchar *name)
1247 if ( g_str_has_suffix (name, ".sav"))
1249 if ( g_str_has_suffix (name, ".SAV"))
1251 if ( g_str_has_suffix (name, ".por"))
1253 if ( g_str_has_suffix (name, ".POR"))
1259 /* Append SUFFIX to the filename of DE */
1261 append_filename_suffix (struct data_editor *de, const gchar *suffix)
1263 if ( ! name_has_suffix (de->file_name))
1265 gchar *s = de->file_name;
1266 de->file_name = g_strconcat (de->file_name, suffix, NULL);
1271 /* Save DE to file */
1273 save_file (struct data_editor *de)
1275 struct getl_interface *sss;
1276 struct string file_name ;
1278 g_assert (de->file_name);
1280 ds_init_empty (&file_name);
1281 syntax_gen_string (&file_name, ss_cstr (de->file_name));
1283 if ( de->save_as_portable )
1285 append_filename_suffix (de, ".por");
1286 sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
1287 ds_cstr (&file_name));
1291 append_filename_suffix (de, ".sav");
1292 sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
1293 ds_cstr (&file_name));
1296 ds_destroy (&file_name);
1298 execute_syntax (sss);
1302 /* Callback for data_save action.
1303 If there's an existing file name, then just save,
1304 otherwise prompt for a file name, then save */
1306 data_save (GtkAction *action, struct data_editor *de)
1311 data_save_as_dialog (action, de);
1315 /* Callback for data_save_as action. Prompt for a filename and save */
1317 data_save_as_dialog (GtkAction *action, struct data_editor *de)
1319 struct editor_window *e = (struct editor_window *) de;
1321 GtkWidget *button_sys;
1323 gtk_file_chooser_dialog_new (_("Save"),
1324 GTK_WINDOW (e->window),
1325 GTK_FILE_CHOOSER_ACTION_SAVE,
1326 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1327 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1330 GtkFileFilter *filter = gtk_file_filter_new ();
1331 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
1332 gtk_file_filter_add_pattern (filter, "*.sav");
1333 gtk_file_filter_add_pattern (filter, "*.SAV");
1334 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1336 filter = gtk_file_filter_new ();
1337 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
1338 gtk_file_filter_add_pattern (filter, "*.por");
1339 gtk_file_filter_add_pattern (filter, "*.POR");
1340 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1342 filter = gtk_file_filter_new ();
1343 gtk_file_filter_set_name (filter, _("All Files"));
1344 gtk_file_filter_add_pattern (filter, "*");
1345 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1348 GtkWidget *button_por;
1349 GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
1351 gtk_radio_button_new_with_label (NULL, _("System File"));
1354 gtk_radio_button_new_with_label
1355 (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
1356 _("Portable File"));
1358 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
1359 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_por);
1361 gtk_widget_show_all (vbox);
1363 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
1366 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
1368 case GTK_RESPONSE_ACCEPT:
1370 g_free (de->file_name);
1373 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1375 de->save_as_portable =
1376 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
1380 window_set_name_from_filename (e, de->file_name);
1387 gtk_widget_destroy (dialog);
1391 /* Callback for data_new action.
1392 Performs the NEW FILE command */
1394 new_file (GtkAction *action, struct editor_window *e)
1396 struct data_editor *de = (struct data_editor *) e;
1398 struct getl_interface *sss =
1399 create_syntax_string_source ("NEW FILE.");
1401 execute_syntax (sss);
1403 g_free (de->file_name);
1404 de->file_name = NULL;
1406 default_window_name (e);
1411 open_data_file (const gchar *file_name, struct data_editor *de)
1413 struct getl_interface *sss;
1414 struct string filename;
1416 ds_init_empty (&filename);
1417 syntax_gen_string (&filename, ss_cstr (file_name));
1419 sss = create_syntax_string_source ("GET FILE=%s.",
1420 ds_cstr (&filename));
1421 ds_destroy (&filename);
1423 if (execute_syntax (sss) )
1425 window_set_name_from_filename ((struct editor_window *) de, file_name);
1426 add_most_recent (file_name);
1432 /* Callback for the data_open action.
1433 Prompts for a filename and opens it */
1435 open_data_dialog (GtkAction *action, struct data_editor *de)
1437 struct editor_window *e = (struct editor_window *) de;
1440 gtk_file_chooser_dialog_new (_("Open"),
1441 GTK_WINDOW (e->window),
1442 GTK_FILE_CHOOSER_ACTION_OPEN,
1443 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1444 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1447 GtkFileFilter *filter = gtk_file_filter_new ();
1448 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
1449 gtk_file_filter_add_pattern (filter, "*.sav");
1450 gtk_file_filter_add_pattern (filter, "*.SAV");
1451 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1453 filter = gtk_file_filter_new ();
1454 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
1455 gtk_file_filter_add_pattern (filter, "*.por");
1456 gtk_file_filter_add_pattern (filter, "*.POR");
1457 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1459 filter = gtk_file_filter_new ();
1460 gtk_file_filter_set_name (filter, _("All Files"));
1461 gtk_file_filter_add_pattern (filter, "*");
1462 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1467 gchar *dir_name = g_path_get_dirname (de->file_name);
1468 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
1473 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
1475 case GTK_RESPONSE_ACCEPT:
1477 g_free (de->file_name);
1479 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1481 open_data_file (de->file_name, de);
1488 gtk_widget_destroy (dialog);
1493 create_data_sheet_variable_popup_menu (struct data_editor *de)
1495 GtkWidget *menu = gtk_menu_new ();
1497 GtkWidget *sort_ascending =
1498 gtk_menu_item_new_with_label (_("Sort Ascending"));
1500 GtkWidget *sort_descending =
1501 gtk_menu_item_new_with_label (_("Sort Descending"));
1503 GtkWidget *insert_variable =
1504 gtk_menu_item_new_with_label (_("Insert Variable"));
1506 GtkWidget *clear_variable =
1507 gtk_menu_item_new_with_label (_("Clear"));
1509 gtk_action_connect_proxy (de->insert_variable,
1513 gtk_action_connect_proxy (de->delete_variables,
1517 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
1520 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
1521 gtk_separator_menu_item_new ());
1524 gtk_menu_shell_append (GTK_MENU_SHELL (menu), clear_variable);
1527 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
1528 gtk_separator_menu_item_new ());
1531 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_ascending);
1534 g_signal_connect_swapped (G_OBJECT (sort_ascending), "activate",
1535 G_CALLBACK (psppire_data_editor_sort_ascending),
1538 g_signal_connect_swapped (G_OBJECT (sort_descending), "activate",
1539 G_CALLBACK (psppire_data_editor_sort_descending),
1542 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_descending);
1544 gtk_widget_show_all (menu);
1551 create_data_sheet_cases_popup_menu (struct data_editor *de)
1553 GtkWidget *menu = gtk_menu_new ();
1555 GtkWidget *insert_case =
1556 gtk_menu_item_new_with_label (_("Insert Case"));
1558 GtkWidget *delete_case =
1559 gtk_menu_item_new_with_label (_("Clear"));
1562 gtk_action_connect_proxy (de->insert_case,
1566 gtk_action_connect_proxy (de->delete_cases,
1570 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_case);
1573 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
1574 gtk_separator_menu_item_new ());
1577 gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_case);
1580 gtk_widget_show_all (menu);
1589 on_edit_paste (GtkAction *a, gpointer data)
1591 struct data_editor *de = data;
1593 psppire_data_editor_clip_paste (de->data_editor);
1597 on_edit_copy (GtkMenuItem *m, gpointer data)
1599 struct data_editor *de = data;
1601 psppire_data_editor_clip_copy (de->data_editor);
1607 on_edit_cut (GtkMenuItem *m, gpointer data)
1609 struct data_editor *de = data;
1611 psppire_data_editor_clip_cut (de->data_editor);