1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2009, 2010 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>
23 #include "data/any-reader.h"
24 #include "data/procedure.h"
25 #include "language/syntax-string-source.h"
26 #include "libpspp/message.h"
27 #include "ui/gui/about.h"
28 #include "ui/gui/comments-dialog.h"
29 #include "ui/gui/compute-dialog.h"
30 #include "ui/gui/correlation-dialog.h"
31 #include "ui/gui/crosstabs-dialog.h"
32 #include "ui/gui/descriptives-dialog.h"
33 #include "ui/gui/examine-dialog.h"
34 #include "ui/gui/executor.h"
35 #include "ui/gui/factor-dialog.h"
36 #include "ui/gui/find-dialog.h"
37 #include "ui/gui/frequencies-dialog.h"
38 #include "ui/gui/goto-case-dialog.h"
39 #include "ui/gui/helper.h"
40 #include "ui/gui/oneway-anova-dialog.h"
41 #include "ui/gui/psppire-data-window.h"
42 #include "ui/gui/psppire-syntax-window.h"
43 #include "ui/gui/psppire-window.h"
44 #include "ui/gui/psppire.h"
45 #include "ui/gui/rank-dialog.h"
46 #include "ui/gui/recode-dialog.h"
47 #include "ui/gui/regression-dialog.h"
48 #include "ui/gui/reliability-dialog.h"
49 #include "ui/gui/roc-dialog.h"
50 #include "ui/gui/select-cases-dialog.h"
51 #include "ui/gui/sort-cases-dialog.h"
52 #include "ui/gui/split-file-dialog.h"
53 #include "ui/gui/t-test-independent-samples-dialog.h"
54 #include "ui/gui/t-test-one-sample.h"
55 #include "ui/gui/t-test-paired-samples.h"
56 #include "ui/gui/text-data-import-dialog.h"
57 #include "ui/gui/transpose-dialog.h"
58 #include "ui/gui/variable-info-dialog.h"
59 #include "ui/gui/weight-cases-dialog.h"
60 #include "ui/syntax-gen.h"
63 #define _(msgid) gettext (msgid)
64 #define N_(msgid) msgid
68 static void psppire_data_window_base_finalize (PsppireDataWindowClass *, gpointer);
69 static void psppire_data_window_base_init (PsppireDataWindowClass *class);
70 static void psppire_data_window_class_init (PsppireDataWindowClass *class);
71 static void psppire_data_window_init (PsppireDataWindow *data_editor);
74 static void psppire_data_window_iface_init (PsppireWindowIface *iface);
78 psppire_data_window_get_type (void)
80 static GType psppire_data_window_type = 0;
82 if (!psppire_data_window_type)
84 static const GTypeInfo psppire_data_window_info =
86 sizeof (PsppireDataWindowClass),
87 (GBaseInitFunc) psppire_data_window_base_init,
88 (GBaseFinalizeFunc) psppire_data_window_base_finalize,
89 (GClassInitFunc)psppire_data_window_class_init,
90 (GClassFinalizeFunc) NULL,
92 sizeof (PsppireDataWindow),
94 (GInstanceInitFunc) psppire_data_window_init,
97 static const GInterfaceInfo window_interface_info =
99 (GInterfaceInitFunc) psppire_data_window_iface_init,
104 psppire_data_window_type =
105 g_type_register_static (PSPPIRE_TYPE_WINDOW, "PsppireDataWindow",
106 &psppire_data_window_info, 0);
109 g_type_add_interface_static (psppire_data_window_type,
110 PSPPIRE_TYPE_WINDOW_MODEL,
111 &window_interface_info);
114 return psppire_data_window_type;
117 static GObjectClass *parent_class ;
120 psppire_data_window_finalize (GObject *object)
122 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (object);
124 g_object_unref (de->builder);
126 if (G_OBJECT_CLASS (parent_class)->finalize)
127 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
132 psppire_data_window_class_init (PsppireDataWindowClass *class)
134 parent_class = g_type_class_peek_parent (class);
139 psppire_data_window_base_init (PsppireDataWindowClass *class)
141 GObjectClass *object_class = G_OBJECT_CLASS (class);
143 object_class->finalize = psppire_data_window_finalize;
149 psppire_data_window_base_finalize (PsppireDataWindowClass *class,
158 extern PsppireVarStore *the_var_store;
159 extern struct dataset *the_dataset;
160 extern PsppireDataStore *the_data_store ;
162 extern GtkRecentManager *the_recent_mgr;
165 set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
167 GtkAction *edit_paste = get_action_assert (de->builder, "edit_paste");
169 gtk_action_set_sensitive (edit_paste, x);
173 set_cut_copy_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
175 GtkAction *edit_copy = get_action_assert (de->builder, "edit_copy");
176 GtkAction *edit_cut = get_action_assert (de->builder, "edit_cut");
178 gtk_action_set_sensitive (edit_copy, x);
179 gtk_action_set_sensitive (edit_cut, x);
182 /* Run the EXECUTE command. */
184 execute (GtkMenuItem *mi, gpointer data)
186 struct getl_interface *sss = create_syntax_string_source ("EXECUTE.");
188 execute_syntax (sss);
192 transformation_change_callback (bool transformations_pending,
195 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
197 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
199 GtkWidget *menuitem =
200 gtk_ui_manager_get_widget (uim,"/ui/menubar/transform/transform_run-pending");
202 GtkWidget *status_label =
203 get_widget_assert (de->builder, "case-counter-area");
205 gtk_widget_set_sensitive (menuitem, transformations_pending);
208 if ( transformations_pending)
209 gtk_label_set_text (GTK_LABEL (status_label),
210 _("Transformations Pending"));
212 gtk_label_set_text (GTK_LABEL (status_label), "");
215 /* Callback for when the dictionary changes its filter variable */
217 on_filter_change (GObject *o, gint filter_index, gpointer data)
219 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
221 GtkWidget *filter_status_area =
222 get_widget_assert (de->builder, "filter-use-status-area");
224 if ( filter_index == -1 )
226 gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
230 PsppireVarStore *vs = NULL;
231 PsppireDict *dict = NULL;
232 struct variable *var ;
235 g_object_get (de->data_editor, "var-store", &vs, NULL);
236 g_object_get (vs, "dictionary", &dict, NULL);
238 var = psppire_dict_get_variable (dict, filter_index);
240 text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
242 gtk_label_set_text (GTK_LABEL (filter_status_area), text);
248 /* Callback for when the dictionary changes its split variables */
250 on_split_change (PsppireDict *dict, gpointer data)
252 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
254 size_t n_split_vars = dict_get_split_cnt (dict->dict);
256 GtkWidget *split_status_area =
257 get_widget_assert (de->builder, "split-file-status-area");
259 if ( n_split_vars == 0 )
261 gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
267 const struct variable *const * split_vars =
268 dict_get_split_vars (dict->dict);
270 text = g_string_new (_("Split by "));
272 for (i = 0 ; i < n_split_vars - 1; ++i )
274 g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
276 g_string_append (text, var_get_name (split_vars[i]));
278 gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
280 g_string_free (text, TRUE);
287 /* Callback for when the dictionary changes its weights */
289 on_weight_change (GObject *o, gint weight_index, gpointer data)
291 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
293 GtkWidget *weight_status_area =
294 get_widget_assert (de->builder, "weight-status-area");
296 if ( weight_index == -1 )
298 gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
302 struct variable *var ;
303 PsppireVarStore *vs = NULL;
304 PsppireDict *dict = NULL;
307 g_object_get (de->data_editor, "var-store", &vs, NULL);
308 g_object_get (vs, "dictionary", &dict, NULL);
310 var = psppire_dict_get_variable (dict, weight_index);
312 text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
314 gtk_label_set_text (GTK_LABEL (weight_status_area), text);
322 dump_rm (GtkRecentManager *rm)
324 GList *items = gtk_recent_manager_get_items (rm);
328 g_print ("Recent Items:\n");
329 for (i = items; i; i = i->next)
331 GtkRecentInfo *ri = i->data;
333 g_print ("Item: %s (Mime: %s) (Desc: %s) (URI: %s)\n",
334 gtk_recent_info_get_short_name (ri),
335 gtk_recent_info_get_mime_type (ri),
336 gtk_recent_info_get_description (ri),
337 gtk_recent_info_get_uri (ri)
341 gtk_recent_info_unref (ri);
350 load_file (PsppireWindow *de, const gchar *file_name)
352 gchar *native_file_name;
353 struct getl_interface *sss;
354 struct string filename;
356 ds_init_empty (&filename);
359 convert_glib_filename_to_system_filename (file_name, NULL);
361 syntax_gen_string (&filename, ss_cstr (native_file_name));
363 g_free (native_file_name);
365 sss = create_syntax_string_source ("GET FILE=%s.",
366 ds_cstr (&filename));
368 ds_destroy (&filename);
370 if (execute_syntax (sss) )
377 sysfile_chooser_dialog (PsppireWindow *toplevel)
380 gtk_file_chooser_dialog_new (_("Open"),
381 GTK_WINDOW (toplevel),
382 GTK_FILE_CHOOSER_ACTION_OPEN,
383 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
384 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
387 GtkFileFilter *filter;
389 filter = gtk_file_filter_new ();
390 gtk_file_filter_set_name (filter, _("Data and Syntax Files"));
391 gtk_file_filter_add_pattern (filter, "*.sav");
392 gtk_file_filter_add_pattern (filter, "*.SAV");
393 gtk_file_filter_add_pattern (filter, "*.por");
394 gtk_file_filter_add_pattern (filter, "*.POR");
395 gtk_file_filter_add_pattern (filter, "*.sps");
396 gtk_file_filter_add_pattern (filter, "*.SPS");
397 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
399 filter = gtk_file_filter_new ();
400 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
401 gtk_file_filter_add_pattern (filter, "*.sav");
402 gtk_file_filter_add_pattern (filter, "*.SAV");
403 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
405 filter = gtk_file_filter_new ();
406 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
407 gtk_file_filter_add_pattern (filter, "*.por");
408 gtk_file_filter_add_pattern (filter, "*.POR");
409 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
411 filter = gtk_file_filter_new ();
412 gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
413 gtk_file_filter_add_pattern (filter, "*.sps");
414 gtk_file_filter_add_pattern (filter, "*.SPS");
415 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
417 filter = gtk_file_filter_new ();
418 gtk_file_filter_set_name (filter, _("All Files"));
419 gtk_file_filter_add_pattern (filter, "*");
420 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
424 gchar *filename = NULL;
425 g_object_get (toplevel, "filename", &filename, NULL);
427 if ( ! g_path_is_absolute (filename))
430 g_build_filename (g_get_current_dir (), filename, NULL);
431 dir_name = g_path_get_dirname (path);
436 dir_name = g_path_get_dirname (filename);
438 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
446 /* Callback for the data_open action.
447 Prompts for a filename and opens it */
449 open_window (GtkAction *action, PsppireWindow *de)
451 GtkWidget *dialog = sysfile_chooser_dialog (de);
453 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
455 case GTK_RESPONSE_ACCEPT:
458 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
460 if (any_reader_may_open (name))
461 psppire_window_load (de, name);
463 open_syntax_window (name);
472 gtk_widget_destroy (dialog);
475 /* Returns true if NAME has a suffix which might denote a PSPP file */
477 name_has_suffix (const gchar *name)
479 if ( g_str_has_suffix (name, ".sav"))
481 if ( g_str_has_suffix (name, ".SAV"))
483 if ( g_str_has_suffix (name, ".por"))
485 if ( g_str_has_suffix (name, ".POR"))
492 /* Save DE to file */
494 save_file (PsppireWindow *w)
496 gchar *native_file_name = NULL;
497 gchar *file_name = NULL;
499 struct getl_interface *sss;
500 struct string filename ;
501 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (w);
503 g_object_get (w, "filename", &file_name, NULL);
505 fnx = g_string_new (file_name);
507 if ( ! name_has_suffix (fnx->str))
509 if ( de->save_as_portable)
510 g_string_append (fnx, ".por");
512 g_string_append (fnx, ".sav");
515 ds_init_empty (&filename);
518 convert_glib_filename_to_system_filename (fnx->str, NULL);
520 g_string_free (fnx, TRUE);
522 syntax_gen_string (&filename, ss_cstr (native_file_name));
523 g_free (native_file_name);
525 if ( de->save_as_portable )
527 sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
528 ds_cstr (&filename));
532 sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
533 ds_cstr (&filename));
536 ds_destroy (&filename);
538 execute_syntax (sss);
543 insert_case (GtkAction *action, gpointer data)
545 PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (data);
546 psppire_data_editor_insert_case (dw->data_editor);
550 on_insert_variable (GtkAction *action, gpointer data)
552 PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (data);
553 psppire_data_editor_insert_variable (dw->data_editor);
558 display_dict (PsppireDataWindow *de)
561 struct getl_interface *sss =
562 create_syntax_string_source ("DISPLAY DICTIONARY.");
564 execute_syntax (sss);
568 sysfile_info (PsppireDataWindow *de)
570 GtkWidget *dialog = sysfile_chooser_dialog (PSPPIRE_WINDOW (de));
572 if ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (dialog)))
574 struct string filename;
575 struct getl_interface *sss;
577 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
579 gchar *native_file_name =
580 convert_glib_filename_to_system_filename (file_name, NULL);
582 ds_init_empty (&filename);
584 syntax_gen_string (&filename, ss_cstr (native_file_name));
586 g_free (native_file_name);
588 sss = create_syntax_string_source ("SYSFILE INFO %s.",
589 ds_cstr (&filename));
590 execute_syntax (sss);
593 gtk_widget_destroy (dialog);
597 /* Callback for data_save_as action. Prompt for a filename and save */
599 data_save_as_dialog (PsppireDataWindow *de)
601 GtkWidget *button_sys;
603 gtk_file_chooser_dialog_new (_("Save"),
605 GTK_FILE_CHOOSER_ACTION_SAVE,
606 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
607 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
610 GtkFileFilter *filter = gtk_file_filter_new ();
611 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
612 gtk_file_filter_add_pattern (filter, "*.sav");
613 gtk_file_filter_add_pattern (filter, "*.SAV");
614 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
616 filter = gtk_file_filter_new ();
617 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
618 gtk_file_filter_add_pattern (filter, "*.por");
619 gtk_file_filter_add_pattern (filter, "*.POR");
620 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
622 filter = gtk_file_filter_new ();
623 gtk_file_filter_set_name (filter, _("All Files"));
624 gtk_file_filter_add_pattern (filter, "*");
625 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
628 GtkWidget *button_por;
629 GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
631 gtk_radio_button_new_with_label (NULL, _("System File"));
634 gtk_radio_button_new_with_label
635 (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
638 psppire_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
639 psppire_box_pack_start_defaults (GTK_BOX (vbox), button_por);
641 gtk_widget_show_all (vbox);
643 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
646 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
648 case GTK_RESPONSE_ACCEPT:
653 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog))
656 de->save_as_portable =
657 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
659 if ( ! name_has_suffix (filename->str))
661 if ( de->save_as_portable)
662 g_string_append (filename, ".por");
664 g_string_append (filename, ".sav");
667 psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str);
669 save_file (PSPPIRE_WINDOW (de));
671 g_string_free (filename, TRUE);
678 gtk_widget_destroy (dialog);
682 /* Callback for data_save action.
685 data_save (PsppireWindow *de)
687 const gchar *fn = psppire_window_get_filename (de);
690 psppire_window_save (de);
692 data_save_as_dialog (PSPPIRE_DATA_WINDOW (de));
696 /* Callback for data_new action.
697 Performs the NEW FILE command */
699 new_file (GtkAction *action, PsppireDataWindow *de)
701 struct getl_interface *sss =
702 create_syntax_string_source ("NEW FILE.");
704 execute_syntax (sss);
706 psppire_window_set_filename (PSPPIRE_WINDOW (de), NULL);
712 on_edit_paste (GtkAction *a, gpointer data)
714 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
716 psppire_data_editor_clip_paste (de->data_editor);
720 on_edit_copy (GtkMenuItem *m, gpointer data)
722 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
724 psppire_data_editor_clip_copy (de->data_editor);
730 on_edit_cut (GtkMenuItem *m, gpointer data)
732 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
734 psppire_data_editor_clip_cut (de->data_editor);
739 status_bar_activate (GtkToggleAction *action, gpointer data)
741 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
742 GtkWidget *statusbar = get_widget_assert (de->builder, "status-bar");
744 if ( gtk_toggle_action_get_active (action) )
745 gtk_widget_show (statusbar);
747 gtk_widget_hide (statusbar);
752 grid_lines_activate (GtkToggleAction *action, gpointer data)
754 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
755 const gboolean grid_visible = gtk_toggle_action_get_active (action);
757 psppire_data_editor_show_grid (de->data_editor, grid_visible);
761 data_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
763 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
765 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
770 variable_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
772 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
774 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
779 fonts_activate (GtkMenuItem *menuitem, gpointer data)
781 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
782 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (de));
783 PangoFontDescription *current_font;
786 gtk_font_selection_dialog_new (_("Font Selection"));
789 current_font = GTK_WIDGET(de->data_editor)->style->font_desc;
790 font_name = pango_font_description_to_string (current_font);
792 gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (dialog), font_name);
796 gtk_window_set_transient_for (GTK_WINDOW (dialog),
797 GTK_WINDOW (toplevel));
799 if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
801 const gchar *font = gtk_font_selection_dialog_get_font_name
802 (GTK_FONT_SELECTION_DIALOG (dialog));
804 PangoFontDescription* font_desc =
805 pango_font_description_from_string (font);
807 psppire_data_editor_set_font (de->data_editor, font_desc);
810 gtk_widget_hide (dialog);
815 /* Callback for the value labels action */
817 toggle_value_labels (GtkToggleAction *ta, gpointer data)
819 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
821 g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
825 toggle_split_window (GtkToggleAction *ta, gpointer data)
827 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
829 psppire_data_editor_split_window (de->data_editor,
830 gtk_toggle_action_get_active (ta));
835 file_quit (GtkCheckMenuItem *menuitem, gpointer data)
837 /* FIXME: Need to be more intelligent here.
838 Give the user the opportunity to save any unsaved data.
840 g_object_unref (the_data_store);
847 on_recent_data_select (GtkMenuShell *menushell,
848 PsppireWindow *window)
853 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
855 file = g_filename_from_uri (uri, NULL, NULL);
859 psppire_window_load (window, file);
865 on_recent_files_select (GtkMenuShell *menushell, gpointer user_data)
872 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
874 file = g_filename_from_uri (uri, NULL, NULL);
878 se = psppire_syntax_window_new ();
880 if ( psppire_window_load (PSPPIRE_WINDOW (se), file) )
881 gtk_widget_show (se);
883 gtk_widget_destroy (se);
890 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
892 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
894 gtk_action_set_visible (de->delete_cases, case_num != -1);
899 enable_delete_variables (GtkWidget *w, gint var, gpointer data)
901 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
903 gtk_action_set_visible (de->delete_variables, var != -1);
906 /* Callback for when the datasheet/varsheet is selected */
908 on_switch_sheet (GtkNotebook *notebook,
909 GtkNotebookPage *page,
913 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
915 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
917 GtkWidget *view_data =
918 gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_data");
920 GtkWidget *view_variables =
921 gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_variables");
925 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
926 gtk_widget_hide (view_variables);
927 gtk_widget_show (view_data);
928 gtk_action_set_sensitive (de->insert_variable, TRUE);
929 gtk_action_set_sensitive (de->insert_case, FALSE);
930 gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
932 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
933 gtk_widget_show (view_variables);
934 gtk_widget_hide (view_data);
935 gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
936 gtk_action_set_sensitive (de->insert_case, TRUE);
939 g_assert_not_reached ();
944 update_paste_menuitem (de, page_num);
951 set_unsaved (gpointer w)
953 psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
957 psppire_data_window_init (PsppireDataWindow *de)
960 PsppireDict *dict = NULL;
966 GtkWidget *box = gtk_vbox_new (FALSE, 0);
967 de->builder = builder_new ("data-editor.ui");
969 menubar = get_widget_assert (de->builder, "menubar");
970 hb = get_widget_assert (de->builder, "handlebox1");
971 sb = get_widget_assert (de->builder, "status-bar");
974 PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
976 g_signal_connect_swapped (the_data_store, "case-changed",
977 G_CALLBACK (set_unsaved), de);
979 g_signal_connect_swapped (the_data_store, "case-inserted",
980 G_CALLBACK (set_unsaved), de);
982 g_signal_connect_swapped (the_data_store, "cases-deleted",
983 G_CALLBACK (set_unsaved), de);
985 dataset_set_callback (the_dataset, set_unsaved, de);
987 connect_help (de->builder);
989 gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0);
990 gtk_box_pack_start (GTK_BOX (box), hb, FALSE, TRUE, 0);
991 gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (de->data_editor), TRUE, TRUE, 0);
992 gtk_box_pack_start (GTK_BOX (box), sb, FALSE, TRUE, 0);
994 gtk_container_add (GTK_CONTAINER (de), box);
996 set_cut_copy_menuitem_sensitivity (de, FALSE);
998 g_signal_connect_swapped (de->data_editor, "data-selection-changed",
999 G_CALLBACK (set_cut_copy_menuitem_sensitivity), de);
1002 set_paste_menuitem_sensitivity (de, FALSE);
1004 g_signal_connect_swapped (de->data_editor, "data-available-changed",
1005 G_CALLBACK (set_paste_menuitem_sensitivity), de);
1007 dataset_add_transform_change_callback (the_dataset,
1008 transformation_change_callback,
1014 g_assert(vs); /* Traps a possible bug in w32 build */
1016 g_object_get (vs, "dictionary", &dict, NULL);
1018 g_signal_connect (dict, "weight-changed",
1019 G_CALLBACK (on_weight_change),
1022 g_signal_connect (dict, "filter-changed",
1023 G_CALLBACK (on_filter_change),
1026 g_signal_connect (dict, "split-changed",
1027 G_CALLBACK (on_split_change),
1031 g_signal_connect (get_action_assert (de->builder, "edit_copy"),
1033 G_CALLBACK (on_edit_copy), de);
1035 g_signal_connect (get_action_assert (de->builder, "edit_cut"),
1037 G_CALLBACK (on_edit_cut), de);
1044 GtkAction *action_data_new =
1045 get_action_assert (de->builder, "file_new_data");
1047 g_signal_connect (action_data_new, "activate",
1048 G_CALLBACK (new_file), de);
1054 GtkAction *invoke_text_import_assistant =
1055 get_action_assert (de->builder, "file_import-text");
1057 g_signal_connect (invoke_text_import_assistant, "activate",
1058 G_CALLBACK (text_data_import_assistant), de);
1064 GtkAction *action_data_save = get_action_assert (de->builder, "file_save");
1066 g_signal_connect_swapped (action_data_save, "activate",
1067 G_CALLBACK (data_save), de);
1072 GtkAction *action_data_open = get_action_assert (de->builder, "file_open");
1074 g_signal_connect (action_data_open, "activate",
1075 G_CALLBACK (open_window), de);
1079 GtkAction *action_data_save_as =
1080 get_action_assert (de->builder, "file_save_as");
1082 g_signal_connect_swapped (action_data_save_as, "activate",
1083 G_CALLBACK (data_save_as_dialog), de);
1088 GtkAction *action_info_working_file =
1089 get_action_assert (de->builder, "file_information_working-file");
1092 g_signal_connect_swapped (action_info_working_file, "activate",
1093 G_CALLBACK (display_dict), de);
1098 GtkAction *action_info_external_file =
1099 get_action_assert (de->builder, "file_information_external-file");
1102 g_signal_connect_swapped (action_info_external_file, "activate",
1103 G_CALLBACK (sysfile_info), de);
1109 g_signal_connect (get_action_assert (de->builder, "edit_paste"), "activate",
1110 G_CALLBACK (on_edit_paste),
1114 de->insert_case = get_action_assert (de->builder, "edit_insert-case");
1115 g_signal_connect (de->insert_case, "activate",
1116 G_CALLBACK (insert_case),
1122 de->insert_variable = get_action_assert (de->builder, "action_insert-variable");
1124 g_signal_connect (de->insert_variable, "activate",
1125 G_CALLBACK (on_insert_variable),
1131 de->invoke_goto_dialog = get_action_assert (de->builder, "edit_goto-case");
1132 g_signal_connect (de->invoke_goto_dialog, "activate", G_CALLBACK (goto_case_dialog), de);
1136 GtkAction *value_labels_action = get_action_assert (de->builder, "view_value-labels");
1137 g_signal_connect (value_labels_action, "toggled",
1138 G_CALLBACK (toggle_value_labels), de);
1143 get_action_assert (de->builder, "edit_clear-cases");
1146 g_signal_connect_swapped (de->delete_cases, "activate",
1147 G_CALLBACK (psppire_data_editor_delete_cases),
1150 gtk_action_set_visible (de->delete_cases, FALSE);
1155 de->delete_variables =
1156 get_action_assert (de->builder, "edit_clear-variables");
1158 g_signal_connect_swapped (de->delete_variables, "activate",
1159 G_CALLBACK (psppire_data_editor_delete_variables),
1162 gtk_action_set_visible (de->delete_variables, FALSE);
1168 GtkAction *invoke_transpose_dialog =
1169 get_action_assert (de->builder, "data_transpose");
1172 g_signal_connect (invoke_transpose_dialog, "activate",
1173 G_CALLBACK (transpose_dialog), de);
1178 GtkAction *invoke_sort_cases_dialog =
1179 get_action_assert (de->builder, "data_sort-cases");
1182 g_signal_connect (invoke_sort_cases_dialog, "activate",
1183 G_CALLBACK (sort_cases_dialog), de);
1189 GtkAction *invoke_compute_dialog =
1190 get_action_assert (de->builder, "transform_compute");
1192 g_signal_connect (invoke_compute_dialog, "activate",
1193 G_CALLBACK (compute_dialog), de);
1197 GtkAction *invoke_find_dialog = get_action_assert (de->builder, "edit_find");
1199 g_signal_connect (invoke_find_dialog, "activate",
1200 G_CALLBACK (find_dialog), de);
1205 GtkAction *invoke_split_file_dialog = get_action_assert (de->builder, "data_split-file");
1207 g_signal_connect (invoke_split_file_dialog, "activate",
1208 G_CALLBACK (split_file_dialog), de);
1213 GtkAction *invoke_weight_cases_dialog = get_action_assert (de->builder, "data_weight-cases");
1215 g_signal_connect (invoke_weight_cases_dialog, "activate",
1216 G_CALLBACK (weight_cases_dialog), de);
1222 GtkAction *invoke_variable_info_dialog = get_action_assert (de->builder, "utilities_variables");
1224 g_signal_connect (invoke_variable_info_dialog, "activate",
1225 G_CALLBACK (variable_info_dialog), de);
1231 GtkAction *invoke_oneway_anova_dialog =
1232 get_action_assert (de->builder, "oneway-anova");
1234 g_signal_connect (invoke_oneway_anova_dialog, "activate",
1235 G_CALLBACK (oneway_anova_dialog), de);
1240 GtkAction *invoke_t_test_independent_samples_dialog =
1241 get_action_assert (de->builder, "indep-t-test");
1244 g_signal_connect (invoke_t_test_independent_samples_dialog, "activate",
1245 G_CALLBACK (t_test_independent_samples_dialog), de);
1250 GtkAction *invoke_t_test_paired_samples_dialog =
1251 get_action_assert (de->builder, "paired-t-test");
1253 g_signal_connect (invoke_t_test_paired_samples_dialog, "activate",
1254 G_CALLBACK (t_test_paired_samples_dialog), de);
1259 GtkAction *invoke_t_test_one_sample_dialog =
1260 get_action_assert (de->builder, "one-sample-t-test");
1262 g_signal_connect (invoke_t_test_one_sample_dialog, "activate",
1263 G_CALLBACK (t_test_one_sample_dialog), de);
1268 GtkAction *invoke_comments_dialog =
1269 get_action_assert (de->builder, "utilities_comments");
1272 g_signal_connect (invoke_comments_dialog, "activate",
1273 G_CALLBACK (comments_dialog), de);
1279 GtkAction *invoke_rank_dialog =
1280 get_action_assert (de->builder, "transform_rank");
1282 g_signal_connect (invoke_rank_dialog, "activate",
1283 G_CALLBACK (rank_dialog), de);
1288 GtkAction *invoke_recode_same_dialog =
1289 get_action_assert (de->builder, "transform_recode-same");
1291 g_signal_connect (invoke_recode_same_dialog, "activate",
1292 G_CALLBACK (recode_same_dialog), de);
1297 GtkAction *invoke_recode_different_dialog =
1298 get_action_assert (de->builder, "transform_recode-different");
1301 g_signal_connect (invoke_recode_different_dialog, "activate",
1302 G_CALLBACK (recode_different_dialog), de);
1307 GtkAction *invoke_descriptives_dialog =
1308 get_action_assert (de->builder, "analyze_descriptives");
1310 g_signal_connect (invoke_descriptives_dialog, "activate",
1311 G_CALLBACK (descriptives_dialog), de);
1316 GtkAction *invoke_frequencies_dialog =
1317 get_action_assert (de->builder, "analyze_frequencies");
1320 g_signal_connect (invoke_frequencies_dialog, "activate",
1321 G_CALLBACK (frequencies_dialog), de);
1326 GtkAction *invoke_crosstabs_dialog =
1327 get_action_assert (de->builder, "crosstabs");
1330 g_signal_connect (invoke_crosstabs_dialog, "activate",
1331 G_CALLBACK (crosstabs_dialog), de);
1337 GtkAction *invoke_examine_dialog =
1338 get_action_assert (de->builder, "analyze_explore");
1341 g_signal_connect (invoke_examine_dialog, "activate",
1342 G_CALLBACK (examine_dialog), de);
1347 GtkAction *invoke_regression_dialog =
1348 get_action_assert (de->builder, "linear-regression");
1351 g_signal_connect (invoke_regression_dialog, "activate",
1352 G_CALLBACK (regression_dialog), de);
1356 GtkAction *invoke_reliability_dialog =
1357 get_action_assert (de->builder, "reliability");
1360 g_signal_connect (invoke_reliability_dialog, "activate",
1361 G_CALLBACK (reliability_dialog), de);
1365 GtkAction *invoke_roc_dialog =
1366 get_action_assert (de->builder, "roc-curve");
1369 g_signal_connect (invoke_roc_dialog, "activate",
1370 G_CALLBACK (roc_dialog), de);
1374 GtkAction *invoke_correlation_dialog =
1375 get_action_assert (de->builder, "correlation");
1378 g_signal_connect (invoke_correlation_dialog, "activate",
1379 G_CALLBACK (correlation_dialog), de);
1383 GtkAction *invoke_factor_dialog =
1384 get_action_assert (de->builder, "factor-analysis");
1386 g_signal_connect (invoke_factor_dialog, "activate",
1387 G_CALLBACK (factor_dialog), de);
1392 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1394 GtkWidget *recent_data =
1395 gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-data");
1397 GtkWidget *recent_files =
1398 gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
1401 GtkWidget *menu_data =
1402 gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1404 GtkWidget *menu_files =
1405 gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1408 GtkRecentFilter *filter = gtk_recent_filter_new ();
1410 gtk_recent_filter_add_pattern (filter, "*.sav");
1411 gtk_recent_filter_add_pattern (filter, "*.SAV");
1412 gtk_recent_filter_add_pattern (filter, "*.por");
1413 gtk_recent_filter_add_pattern (filter, "*.POR");
1415 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);
1417 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_data), filter);
1420 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu_data);
1423 g_signal_connect (menu_data, "selection-done",
1424 G_CALLBACK (on_recent_data_select),
1428 GtkRecentFilter *filter = gtk_recent_filter_new ();
1430 gtk_recent_filter_add_pattern (filter, "*.sps");
1431 gtk_recent_filter_add_pattern (filter, "*.SPS");
1433 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_files), GTK_RECENT_SORT_MRU);
1435 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_files), filter);
1438 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu_files);
1440 g_signal_connect (menu_files, "selection-done",
1441 G_CALLBACK (on_recent_files_select),
1446 g_signal_connect (get_action_assert (de->builder,"file_new_syntax"),
1448 G_CALLBACK (create_syntax_window),
1453 GtkAction *abt = get_action_assert (de->builder, "help_about");
1455 g_signal_connect (abt,
1457 G_CALLBACK (about_new),
1462 g_signal_connect (get_action_assert (de->builder,"help_reference"),
1464 G_CALLBACK (reference_manual),
1468 g_signal_connect (de->data_editor,
1470 G_CALLBACK (enable_delete_cases),
1473 g_signal_connect (de->data_editor,
1474 "variables-selected",
1475 G_CALLBACK (enable_delete_variables),
1479 g_signal_connect (de->data_editor,
1481 G_CALLBACK (on_switch_sheet), de);
1483 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1484 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1486 g_signal_connect (get_action_assert (de->builder, "view_statusbar"),
1488 G_CALLBACK (status_bar_activate), de);
1491 g_signal_connect (get_action_assert (de->builder, "view_gridlines"),
1493 G_CALLBACK (grid_lines_activate), de);
1497 g_signal_connect (get_action_assert (de->builder, "view_data"),
1499 G_CALLBACK (data_view_activate), de);
1501 g_signal_connect (get_action_assert (de->builder, "view_variables"),
1503 G_CALLBACK (variable_view_activate), de);
1507 GtkAction *font_action = get_action_assert (de->builder, "view_fonts");
1509 g_signal_connect (font_action,
1511 G_CALLBACK (fonts_activate), de);
1516 g_signal_connect (get_action_assert (de->builder, "file_quit"),
1518 G_CALLBACK (file_quit), de);
1520 g_signal_connect (get_action_assert (de->builder, "transform_run-pending"),
1522 G_CALLBACK (execute), de);
1525 g_signal_connect (get_action_assert (de->builder, "windows_minimise_all"),
1527 G_CALLBACK (psppire_window_minimise_all), NULL);
1531 GtkAction *split_window_action =
1532 get_action_assert (de->builder, "windows_split");
1535 g_signal_connect (split_window_action, "toggled",
1536 G_CALLBACK (toggle_split_window),
1541 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1543 PSPPIRE_WINDOW (de)->menu =
1544 GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
1548 GtkWidget *data_sheet_cases_popup_menu = get_widget_assert (de->builder,
1549 "datasheet-cases-popup");
1551 GtkWidget *var_sheet_variable_popup_menu = get_widget_assert (de->builder,
1552 "varsheet-variable-popup");
1554 GtkWidget *data_sheet_variable_popup_menu = get_widget_assert (de->builder,
1555 "datasheet-variable-popup");
1557 g_signal_connect_swapped (get_action_assert (de->builder, "sort-up"), "activate",
1558 G_CALLBACK (psppire_data_editor_sort_ascending),
1561 g_signal_connect_swapped (get_action_assert (de->builder, "sort-down"), "activate",
1562 G_CALLBACK (psppire_data_editor_sort_descending),
1565 g_object_set (de->data_editor,
1566 "datasheet-column-menu", data_sheet_variable_popup_menu,
1567 "datasheet-row-menu", data_sheet_cases_popup_menu,
1568 "varsheet-row-menu", var_sheet_variable_popup_menu,
1572 gtk_widget_show (GTK_WIDGET (de->data_editor));
1573 gtk_widget_show (box);
1578 psppire_data_window_new (void)
1580 return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
1581 "description", _("Data Editor"),
1591 psppire_data_window_iface_init (PsppireWindowIface *iface)
1593 iface->save = save_file;
1594 iface->load = load_file;