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"
25 #include <gtksheet/gtksheet.h>
27 #include "psppire-data-editor.h"
31 #include <data/procedure.h>
32 #include "psppire-dialog.h"
33 #include "psppire-selector.h"
34 #include "weight-cases-dialog.h"
35 #include "split-file-dialog.h"
36 #include "transpose-dialog.h"
37 #include "sort-cases-dialog.h"
38 #include "select-cases-dialog.h"
39 #include "compute-dialog.h"
40 #include "goto-case-dialog.h"
41 #include "find-dialog.h"
42 #include "rank-dialog.h"
43 #include "recode-dialog.h"
44 #include "comments-dialog.h"
45 #include "variable-info-dialog.h"
46 #include "descriptives-dialog.h"
47 #include "crosstabs-dialog.h"
48 #include "frequencies-dialog.h"
49 #include "examine-dialog.h"
50 #include "dict-display.h"
51 #include "regression-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 <libpspp/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_save"),
708 G_CALLBACK (gtk_action_activate),
709 de->action_data_save);
711 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save_as"),
713 G_CALLBACK (gtk_action_activate),
714 de->action_data_save_as);
716 gtk_action_connect_proxy (de->invoke_find_dialog,
717 get_widget_assert (de->xml, "edit_find")
720 gtk_action_connect_proxy (de->invoke_find_dialog,
721 get_widget_assert (de->xml, "button-find")
724 gtk_action_connect_proxy (de->invoke_rank_dialog,
725 get_widget_assert (de->xml, "transform_rank")
728 gtk_action_connect_proxy (de->invoke_recode_same_dialog,
729 get_widget_assert (de->xml,
730 "transform_recode-same")
733 gtk_action_connect_proxy (de->invoke_recode_different_dialog,
734 get_widget_assert (de->xml,
735 "transform_recode-different")
738 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
739 get_widget_assert (de->xml, "data_weight-cases")
742 gtk_action_connect_proxy (de->invoke_transpose_dialog,
743 get_widget_assert (de->xml, "data_transpose")
746 gtk_action_connect_proxy (de->invoke_split_file_dialog,
747 get_widget_assert (de->xml, "data_split-file")
750 gtk_action_connect_proxy (de->invoke_sort_cases_dialog,
751 get_widget_assert (de->xml, "data_sort-cases")
754 gtk_action_connect_proxy (de->invoke_select_cases_dialog,
755 get_widget_assert (de->xml, "data_select-cases")
758 gtk_action_connect_proxy (de->invoke_compute_dialog,
759 get_widget_assert (de->xml, "transform_compute")
762 gtk_action_connect_proxy (de->invoke_t_test_independent_samples_dialog,
763 get_widget_assert (de->xml,
768 gtk_action_connect_proxy (de->invoke_t_test_paired_samples_dialog,
769 get_widget_assert (de->xml,
774 gtk_action_connect_proxy (de->invoke_t_test_one_sample_dialog,
775 get_widget_assert (de->xml,
780 gtk_action_connect_proxy (de->invoke_oneway_anova_dialog,
781 get_widget_assert (de->xml,
786 gtk_action_connect_proxy (de->invoke_comments_dialog,
787 get_widget_assert (de->xml, "utilities_comments")
790 gtk_action_connect_proxy (de->invoke_variable_info_dialog,
791 get_widget_assert (de->xml, "utilities_variables")
794 gtk_action_connect_proxy (de->invoke_descriptives_dialog,
795 get_widget_assert (de->xml, "analyze_descriptives")
798 gtk_action_connect_proxy (de->invoke_crosstabs_dialog,
799 get_widget_assert (de->xml, "crosstabs")
802 gtk_action_connect_proxy (de->invoke_frequencies_dialog,
803 get_widget_assert (de->xml, "analyze_frequencies")
807 gtk_action_connect_proxy (de->invoke_examine_dialog,
808 get_widget_assert (de->xml, "analyze_explore")
811 gtk_action_connect_proxy (de->invoke_regression_dialog,
812 get_widget_assert (de->xml, "linear-regression")
815 g_signal_connect (get_widget_assert (de->xml,"help_about"),
817 G_CALLBACK (about_new),
821 g_signal_connect (get_widget_assert (de->xml,"help_reference"),
823 G_CALLBACK (reference_manual),
827 g_signal_connect (de->data_editor,
829 G_CALLBACK (enable_delete_cases),
833 g_signal_connect (de->data_editor,
834 "variables-selected",
835 G_CALLBACK (enable_delete_variables),
839 g_signal_connect (GTK_NOTEBOOK (de->data_editor),
841 G_CALLBACK (on_switch_sheet), de);
843 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
844 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
846 g_signal_connect (get_widget_assert (de->xml, "view_statusbar"),
848 G_CALLBACK (status_bar_activate), de);
851 g_signal_connect (get_widget_assert (de->xml, "view_gridlines"),
853 G_CALLBACK (grid_lines_activate), de);
857 g_signal_connect (get_widget_assert (de->xml, "view_data"),
859 G_CALLBACK (data_view_activate), de);
861 g_signal_connect (get_widget_assert (de->xml, "view_variables"),
863 G_CALLBACK (variable_view_activate), de);
867 g_signal_connect (get_widget_assert (de->xml, "view_fonts"),
869 G_CALLBACK (fonts_activate), de);
874 gtk_action_connect_proxy (de->action_data_open,
875 get_widget_assert (de->xml, "button-open")
878 gtk_action_connect_proxy (de->action_data_save,
879 get_widget_assert (de->xml, "button-save")
882 gtk_action_connect_proxy (de->invoke_variable_info_dialog,
883 get_widget_assert (de->xml, "button-goto-variable")
886 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
887 get_widget_assert (de->xml, "button-weight-cases")
890 gtk_action_connect_proxy (de->invoke_split_file_dialog,
891 get_widget_assert (de->xml, "button-split-file")
894 gtk_action_connect_proxy (de->invoke_select_cases_dialog,
895 get_widget_assert (de->xml, "button-select-cases")
899 g_signal_connect (get_widget_assert (de->xml, "file_quit"),
901 G_CALLBACK (file_quit), de);
903 g_signal_connect (get_widget_assert (de->xml, "transform_run-pending"),
905 G_CALLBACK (execute), de);
908 g_signal_connect (get_widget_assert (de->xml, "windows_minimise_all"),
910 G_CALLBACK (minimise_all_windows), NULL);
913 de->data_sheet_variable_popup_menu =
914 GTK_MENU (create_data_sheet_variable_popup_menu (de));
916 de->data_sheet_cases_popup_menu =
917 GTK_MENU (create_data_sheet_cases_popup_menu (de));
920 g_object_set (de->data_editor,
921 "column-menu", de->data_sheet_variable_popup_menu, NULL);
924 g_object_set (de->data_editor,
925 "row-menu", de->data_sheet_cases_popup_menu, NULL);
932 new_data_window (GtkMenuItem *menuitem, gpointer parent)
934 window_create (WINDOW_DATA, NULL);
937 /* Callback for when the datasheet/varsheet is selected */
939 on_switch_sheet (GtkNotebook *notebook,
940 GtkNotebookPage *page,
944 struct data_editor *de = user_data;
946 GtkWidget *view_data = get_widget_assert (de->xml, "view_data");
947 GtkWidget *view_variables = get_widget_assert (de->xml, "view_variables");
951 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
952 gtk_widget_hide (view_variables);
953 gtk_widget_show (view_data);
954 gtk_action_set_sensitive (de->insert_variable, TRUE);
955 gtk_action_set_sensitive (de->insert_case, FALSE);
956 gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
958 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
959 gtk_widget_show (view_variables);
960 gtk_widget_hide (view_data);
961 gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
962 gtk_action_set_sensitive (de->insert_case, TRUE);
965 g_assert_not_reached ();
970 update_paste_menuitem (de, page_num);
976 status_bar_activate (GtkCheckMenuItem *menuitem, gpointer data)
978 struct data_editor *de = data;
979 GtkWidget *statusbar = get_widget_assert (de->xml, "status-bar");
981 if ( gtk_check_menu_item_get_active (menuitem) )
982 gtk_widget_show (statusbar);
984 gtk_widget_hide (statusbar);
989 grid_lines_activate (GtkCheckMenuItem *menuitem, gpointer data)
991 struct data_editor *de = data;
992 const gboolean grid_visible = gtk_check_menu_item_get_active (menuitem);
994 psppire_data_editor_show_grid (de->data_editor, grid_visible);
1000 data_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
1002 struct data_editor *de = data;
1004 gtk_notebook_set_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1009 variable_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
1011 struct data_editor *de = data;
1013 gtk_notebook_set_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1018 fonts_activate (GtkMenuItem *menuitem, gpointer data)
1020 struct data_editor *de = data;
1022 gtk_font_selection_dialog_new (_("Font Selection"));
1024 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1025 GTK_WINDOW (get_widget_assert (de->xml,
1027 if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
1029 const gchar *font = gtk_font_selection_dialog_get_font_name
1030 (GTK_FONT_SELECTION_DIALOG (dialog));
1032 PangoFontDescription* font_desc =
1033 pango_font_description_from_string (font);
1035 psppire_data_editor_set_font (de->data_editor, font_desc);
1038 gtk_widget_hide (dialog);
1043 /* Callback for the value labels action */
1045 toggle_value_labels (GtkToggleAction *ta, gpointer data)
1047 struct data_editor *de = data;
1049 g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
1055 file_quit (GtkCheckMenuItem *menuitem, gpointer data)
1057 /* FIXME: Need to be more intelligent here.
1058 Give the user the opportunity to save any unsaved data.
1060 g_object_unref (the_data_store);
1066 insert_case (GtkAction *action, gpointer data)
1068 struct data_editor *de = data;
1070 psppire_data_editor_insert_case (de->data_editor);
1074 on_insert_variable (GtkAction *action, gpointer data)
1076 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
1077 psppire_data_editor_insert_variable (de);
1081 /* Callback for when the dictionary changes its split variables */
1083 on_split_change (PsppireDict *dict, gpointer data)
1085 struct data_editor *de = data;
1087 size_t n_split_vars = dict_get_split_cnt (dict->dict);
1089 GtkWidget *split_status_area =
1090 get_widget_assert (de->xml, "split-file-status-area");
1092 if ( n_split_vars == 0 )
1094 gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
1100 const struct variable *const * split_vars =
1101 dict_get_split_vars (dict->dict);
1103 text = g_string_new (_("Split by "));
1105 for (i = 0 ; i < n_split_vars - 1; ++i )
1107 g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
1109 g_string_append (text, var_get_name (split_vars[i]));
1111 gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
1113 g_string_free (text, TRUE);
1118 /* Callback for when the dictionary changes its filter variable */
1120 on_filter_change (GObject *o, gint filter_index, gpointer data)
1122 struct data_editor *de = data;
1123 GtkWidget *filter_status_area =
1124 get_widget_assert (de->xml, "filter-use-status-area");
1126 if ( filter_index == -1 )
1128 gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
1132 PsppireVarStore *vs = NULL;
1133 struct variable *var ;
1136 g_object_get (de->data_editor, "var-store", &vs, NULL);
1138 var = psppire_dict_get_variable (vs->dict, filter_index);
1140 text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
1142 gtk_label_set_text (GTK_LABEL (filter_status_area), text);
1148 /* Callback for when the dictionary changes its weights */
1150 on_weight_change (GObject *o, gint weight_index, gpointer data)
1152 struct data_editor *de = data;
1153 GtkWidget *weight_status_area =
1154 get_widget_assert (de->xml, "weight-status-area");
1156 if ( weight_index == -1 )
1158 gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
1162 struct variable *var ;
1163 PsppireVarStore *vs = NULL;
1166 g_object_get (de->data_editor, "var-store", &vs, NULL);
1168 var = psppire_dict_get_variable (vs->dict, weight_index);
1170 text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
1172 gtk_label_set_text (GTK_LABEL (weight_status_area), text);
1181 static void data_save_as_dialog (GtkAction *, struct data_editor *de);
1182 static void new_file (GtkAction *, struct editor_window *de);
1183 static void open_data_dialog (GtkAction *, struct data_editor *de);
1184 static void data_save (GtkAction *action, struct data_editor *e);
1187 /* Create the GtkActions and connect to their signals */
1189 register_data_editor_actions (struct data_editor *de)
1191 de->action_data_open =
1192 gtk_action_new ("data-open-dialog",
1194 _("Open a data file"),
1197 g_signal_connect (de->action_data_open, "activate",
1198 G_CALLBACK (open_data_dialog), de);
1201 de->action_data_save = gtk_action_new ("data-save",
1203 _("Save data to file"),
1206 g_signal_connect (de->action_data_save, "activate",
1207 G_CALLBACK (data_save), de);
1211 de->action_data_save_as = gtk_action_new ("data-save-as-dialog",
1213 _("Save data to file"),
1216 g_signal_connect (de->action_data_save_as, "activate",
1217 G_CALLBACK (data_save_as_dialog), de);
1219 de->action_data_new =
1220 gtk_action_new ("data-new",
1225 g_signal_connect (de->action_data_new, "activate",
1226 G_CALLBACK (new_file), de);
1229 /* Returns true if NAME has a suffix which might denote a PSPP file */
1231 name_has_suffix (const gchar *name)
1233 if ( g_str_has_suffix (name, ".sav"))
1235 if ( g_str_has_suffix (name, ".SAV"))
1237 if ( g_str_has_suffix (name, ".por"))
1239 if ( g_str_has_suffix (name, ".POR"))
1245 /* Append SUFFIX to the filename of DE */
1247 append_filename_suffix (struct data_editor *de, const gchar *suffix)
1249 if ( ! name_has_suffix (de->file_name))
1251 gchar *s = de->file_name;
1252 de->file_name = g_strconcat (de->file_name, suffix, NULL);
1257 /* Save DE to file */
1259 save_file (struct data_editor *de)
1261 struct getl_interface *sss;
1262 struct string file_name ;
1264 g_assert (de->file_name);
1266 ds_init_cstr (&file_name, de->file_name);
1267 gen_quoted_string (&file_name);
1269 if ( de->save_as_portable )
1271 append_filename_suffix (de, ".por");
1272 sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
1273 ds_cstr (&file_name));
1277 append_filename_suffix (de, ".sav");
1278 sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
1279 ds_cstr (&file_name));
1282 ds_destroy (&file_name);
1284 execute_syntax (sss);
1288 /* Callback for data_save action.
1289 If there's an existing file name, then just save,
1290 otherwise prompt for a file name, then save */
1292 data_save (GtkAction *action, struct data_editor *de)
1297 data_save_as_dialog (action, de);
1301 /* Callback for data_save_as action. Prompt for a filename and save */
1303 data_save_as_dialog (GtkAction *action, struct data_editor *de)
1305 struct editor_window *e = (struct editor_window *) de;
1307 GtkWidget *button_sys;
1309 gtk_file_chooser_dialog_new (_("Save"),
1310 GTK_WINDOW (e->window),
1311 GTK_FILE_CHOOSER_ACTION_SAVE,
1312 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1313 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1316 GtkFileFilter *filter = gtk_file_filter_new ();
1317 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
1318 gtk_file_filter_add_pattern (filter, "*.sav");
1319 gtk_file_filter_add_pattern (filter, "*.SAV");
1320 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1322 filter = gtk_file_filter_new ();
1323 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
1324 gtk_file_filter_add_pattern (filter, "*.por");
1325 gtk_file_filter_add_pattern (filter, "*.POR");
1326 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1328 filter = gtk_file_filter_new ();
1329 gtk_file_filter_set_name (filter, _("All Files"));
1330 gtk_file_filter_add_pattern (filter, "*");
1331 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1334 GtkWidget *button_por;
1335 GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
1337 gtk_radio_button_new_with_label (NULL, _("System File"));
1340 gtk_radio_button_new_with_label
1341 (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
1342 _("Portable File"));
1344 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
1345 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_por);
1347 gtk_widget_show_all (vbox);
1349 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
1352 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
1354 case GTK_RESPONSE_ACCEPT:
1356 g_free (de->file_name);
1359 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1361 de->save_as_portable =
1362 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
1366 window_set_name_from_filename (e, de->file_name);
1373 gtk_widget_destroy (dialog);
1377 /* Callback for data_new action.
1378 Performs the NEW FILE command */
1380 new_file (GtkAction *action, struct editor_window *e)
1382 struct data_editor *de = (struct data_editor *) e;
1384 struct getl_interface *sss =
1385 create_syntax_string_source ("NEW FILE.");
1387 execute_syntax (sss);
1389 g_free (de->file_name);
1390 de->file_name = NULL;
1392 default_window_name (e);
1397 open_data_file (const gchar *file_name, struct data_editor *de)
1399 struct getl_interface *sss;
1400 struct string filename;
1402 ds_init_cstr (&filename, file_name);
1404 gen_quoted_string (&filename);
1406 sss = create_syntax_string_source ("GET FILE=%s.",
1407 ds_cstr (&filename));
1408 ds_destroy (&filename);
1410 if (execute_syntax (sss) )
1412 window_set_name_from_filename ((struct editor_window *) de, file_name);
1413 add_most_recent (file_name);
1419 /* Callback for the data_open action.
1420 Prompts for a filename and opens it */
1422 open_data_dialog (GtkAction *action, struct data_editor *de)
1424 struct editor_window *e = (struct editor_window *) de;
1427 gtk_file_chooser_dialog_new (_("Open"),
1428 GTK_WINDOW (e->window),
1429 GTK_FILE_CHOOSER_ACTION_OPEN,
1430 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1431 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1434 GtkFileFilter *filter = gtk_file_filter_new ();
1435 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
1436 gtk_file_filter_add_pattern (filter, "*.sav");
1437 gtk_file_filter_add_pattern (filter, "*.SAV");
1438 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1440 filter = gtk_file_filter_new ();
1441 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
1442 gtk_file_filter_add_pattern (filter, "*.por");
1443 gtk_file_filter_add_pattern (filter, "*.POR");
1444 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1446 filter = gtk_file_filter_new ();
1447 gtk_file_filter_set_name (filter, _("All Files"));
1448 gtk_file_filter_add_pattern (filter, "*");
1449 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1454 gchar *dir_name = g_path_get_dirname (de->file_name);
1455 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
1460 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
1462 case GTK_RESPONSE_ACCEPT:
1464 g_free (de->file_name);
1466 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1468 open_data_file (de->file_name, de);
1475 gtk_widget_destroy (dialog);
1480 create_data_sheet_variable_popup_menu (struct data_editor *de)
1482 GtkWidget *menu = gtk_menu_new ();
1484 GtkWidget *sort_ascending =
1485 gtk_menu_item_new_with_label (_("Sort Ascending"));
1487 GtkWidget *sort_descending =
1488 gtk_menu_item_new_with_label (_("Sort Descending"));
1490 GtkWidget *insert_variable =
1491 gtk_menu_item_new_with_label (_("Insert Variable"));
1493 GtkWidget *clear_variable =
1494 gtk_menu_item_new_with_label (_("Clear"));
1496 gtk_action_connect_proxy (de->insert_variable,
1500 gtk_action_connect_proxy (de->delete_variables,
1504 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
1507 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
1508 gtk_separator_menu_item_new ());
1511 gtk_menu_shell_append (GTK_MENU_SHELL (menu), clear_variable);
1514 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
1515 gtk_separator_menu_item_new ());
1518 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_ascending);
1521 g_signal_connect_swapped (G_OBJECT (sort_ascending), "activate",
1522 G_CALLBACK (psppire_data_editor_sort_ascending),
1525 g_signal_connect_swapped (G_OBJECT (sort_descending), "activate",
1526 G_CALLBACK (psppire_data_editor_sort_descending),
1529 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_descending);
1531 gtk_widget_show_all (menu);
1538 create_data_sheet_cases_popup_menu (struct data_editor *de)
1540 GtkWidget *menu = gtk_menu_new ();
1542 GtkWidget *insert_case =
1543 gtk_menu_item_new_with_label (_("Insert Case"));
1545 GtkWidget *delete_case =
1546 gtk_menu_item_new_with_label (_("Clear"));
1549 gtk_action_connect_proxy (de->insert_case,
1553 gtk_action_connect_proxy (de->delete_cases,
1557 gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_case);
1560 gtk_menu_shell_append (GTK_MENU_SHELL (menu),
1561 gtk_separator_menu_item_new ());
1564 gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_case);
1567 gtk_widget_show_all (menu);
1576 on_edit_paste (GtkAction *a, gpointer data)
1578 struct data_editor *de = data;
1580 psppire_data_editor_clip_paste (de->data_editor);
1584 on_edit_copy (GtkMenuItem *m, gpointer data)
1586 struct data_editor *de = data;
1588 psppire_data_editor_clip_copy (de->data_editor);
1594 on_edit_cut (GtkMenuItem *m, gpointer data)
1596 struct data_editor *de = data;
1598 psppire_data_editor_clip_cut (de->data_editor);