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/help-menu.h"
28 #include "ui/gui/binomial-dialog.h"
29 #include "ui/gui/comments-dialog.h"
30 #include "ui/gui/compute-dialog.h"
31 #include "ui/gui/correlation-dialog.h"
32 #include "ui/gui/chi-square-dialog.h"
33 #include "ui/gui/crosstabs-dialog.h"
34 #include "ui/gui/descriptives-dialog.h"
35 #include "ui/gui/examine-dialog.h"
36 #include "ui/gui/executor.h"
37 #include "ui/gui/factor-dialog.h"
38 #include "ui/gui/find-dialog.h"
39 #include "ui/gui/frequencies-dialog.h"
40 #include "ui/gui/goto-case-dialog.h"
41 #include "ui/gui/helper.h"
42 #include "ui/gui/oneway-anova-dialog.h"
43 #include "ui/gui/psppire-data-window.h"
44 #include "ui/gui/psppire-syntax-window.h"
45 #include "ui/gui/psppire-window.h"
46 #include "ui/gui/psppire.h"
47 #include "ui/gui/rank-dialog.h"
48 #include "ui/gui/recode-dialog.h"
49 #include "ui/gui/regression-dialog.h"
50 #include "ui/gui/reliability-dialog.h"
51 #include "ui/gui/roc-dialog.h"
52 #include "ui/gui/select-cases-dialog.h"
53 #include "ui/gui/sort-cases-dialog.h"
54 #include "ui/gui/split-file-dialog.h"
55 #include "ui/gui/t-test-independent-samples-dialog.h"
56 #include "ui/gui/t-test-one-sample.h"
57 #include "ui/gui/t-test-paired-samples.h"
58 #include "ui/gui/text-data-import-dialog.h"
59 #include "ui/gui/transpose-dialog.h"
60 #include "ui/gui/aggregate-dialog.h"
61 #include "ui/gui/variable-info-dialog.h"
62 #include "ui/gui/weight-cases-dialog.h"
63 #include "ui/syntax-gen.h"
66 #define _(msgid) gettext (msgid)
67 #define N_(msgid) msgid
71 static void psppire_data_window_base_finalize (PsppireDataWindowClass *, gpointer);
72 static void psppire_data_window_base_init (PsppireDataWindowClass *class);
73 static void psppire_data_window_class_init (PsppireDataWindowClass *class);
74 static void psppire_data_window_init (PsppireDataWindow *data_editor);
77 static void psppire_data_window_iface_init (PsppireWindowIface *iface);
81 psppire_data_window_get_type (void)
83 static GType psppire_data_window_type = 0;
85 if (!psppire_data_window_type)
87 static const GTypeInfo psppire_data_window_info =
89 sizeof (PsppireDataWindowClass),
90 (GBaseInitFunc) psppire_data_window_base_init,
91 (GBaseFinalizeFunc) psppire_data_window_base_finalize,
92 (GClassInitFunc)psppire_data_window_class_init,
93 (GClassFinalizeFunc) NULL,
95 sizeof (PsppireDataWindow),
97 (GInstanceInitFunc) psppire_data_window_init,
100 static const GInterfaceInfo window_interface_info =
102 (GInterfaceInitFunc) psppire_data_window_iface_init,
107 psppire_data_window_type =
108 g_type_register_static (PSPPIRE_TYPE_WINDOW, "PsppireDataWindow",
109 &psppire_data_window_info, 0);
112 g_type_add_interface_static (psppire_data_window_type,
113 PSPPIRE_TYPE_WINDOW_MODEL,
114 &window_interface_info);
117 return psppire_data_window_type;
120 static GObjectClass *parent_class ;
123 psppire_data_window_finalize (GObject *object)
125 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (object);
127 g_object_unref (de->builder);
129 if (G_OBJECT_CLASS (parent_class)->finalize)
130 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
135 psppire_data_window_class_init (PsppireDataWindowClass *class)
137 parent_class = g_type_class_peek_parent (class);
142 psppire_data_window_base_init (PsppireDataWindowClass *class)
144 GObjectClass *object_class = G_OBJECT_CLASS (class);
146 object_class->finalize = psppire_data_window_finalize;
152 psppire_data_window_base_finalize (PsppireDataWindowClass *class,
161 extern PsppireVarStore *the_var_store;
162 extern struct dataset *the_dataset;
163 extern PsppireDataStore *the_data_store ;
165 extern GtkRecentManager *the_recent_mgr;
168 set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
170 GtkAction *edit_paste = get_action_assert (de->builder, "edit_paste");
172 gtk_action_set_sensitive (edit_paste, x);
176 set_cut_copy_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
178 GtkAction *edit_copy = get_action_assert (de->builder, "edit_copy");
179 GtkAction *edit_cut = get_action_assert (de->builder, "edit_cut");
181 gtk_action_set_sensitive (edit_copy, x);
182 gtk_action_set_sensitive (edit_cut, x);
185 /* Run the EXECUTE command. */
189 struct getl_interface *sss = create_syntax_string_source ("EXECUTE.");
191 execute_syntax (sss);
195 transformation_change_callback (bool transformations_pending,
198 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
200 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
202 GtkWidget *menuitem =
203 gtk_ui_manager_get_widget (uim,"/ui/menubar/transform/transform_run-pending");
205 GtkWidget *status_label =
206 get_widget_assert (de->builder, "case-counter-area");
208 gtk_widget_set_sensitive (menuitem, transformations_pending);
211 if ( transformations_pending)
212 gtk_label_set_text (GTK_LABEL (status_label),
213 _("Transformations Pending"));
215 gtk_label_set_text (GTK_LABEL (status_label), "");
218 /* Callback for when the dictionary changes its filter variable */
220 on_filter_change (GObject *o, gint filter_index, gpointer data)
222 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
224 GtkWidget *filter_status_area =
225 get_widget_assert (de->builder, "filter-use-status-area");
227 if ( filter_index == -1 )
229 gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
233 PsppireVarStore *vs = NULL;
234 PsppireDict *dict = NULL;
235 struct variable *var ;
238 g_object_get (de->data_editor, "var-store", &vs, NULL);
239 g_object_get (vs, "dictionary", &dict, NULL);
241 var = psppire_dict_get_variable (dict, filter_index);
243 text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
245 gtk_label_set_text (GTK_LABEL (filter_status_area), text);
251 /* Callback for when the dictionary changes its split variables */
253 on_split_change (PsppireDict *dict, gpointer data)
255 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
257 size_t n_split_vars = dict_get_split_cnt (dict->dict);
259 GtkWidget *split_status_area =
260 get_widget_assert (de->builder, "split-file-status-area");
262 if ( n_split_vars == 0 )
264 gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
270 const struct variable *const * split_vars =
271 dict_get_split_vars (dict->dict);
273 text = g_string_new (_("Split by "));
275 for (i = 0 ; i < n_split_vars - 1; ++i )
277 g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
279 g_string_append (text, var_get_name (split_vars[i]));
281 gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
283 g_string_free (text, TRUE);
290 /* Callback for when the dictionary changes its weights */
292 on_weight_change (GObject *o, gint weight_index, gpointer data)
294 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
296 GtkWidget *weight_status_area =
297 get_widget_assert (de->builder, "weight-status-area");
299 if ( weight_index == -1 )
301 gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
305 struct variable *var ;
306 PsppireVarStore *vs = NULL;
307 PsppireDict *dict = NULL;
310 g_object_get (de->data_editor, "var-store", &vs, NULL);
311 g_object_get (vs, "dictionary", &dict, NULL);
313 var = psppire_dict_get_variable (dict, weight_index);
315 text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
317 gtk_label_set_text (GTK_LABEL (weight_status_area), text);
325 dump_rm (GtkRecentManager *rm)
327 GList *items = gtk_recent_manager_get_items (rm);
331 g_print ("Recent Items:\n");
332 for (i = items; i; i = i->next)
334 GtkRecentInfo *ri = i->data;
336 g_print ("Item: %s (Mime: %s) (Desc: %s) (URI: %s)\n",
337 gtk_recent_info_get_short_name (ri),
338 gtk_recent_info_get_mime_type (ri),
339 gtk_recent_info_get_description (ri),
340 gtk_recent_info_get_uri (ri)
344 gtk_recent_info_unref (ri);
353 load_file (PsppireWindow *de, const gchar *file_name)
355 gchar *native_file_name;
356 struct getl_interface *sss;
357 struct string filename;
359 ds_init_empty (&filename);
362 convert_glib_filename_to_system_filename (file_name, NULL);
364 syntax_gen_string (&filename, ss_cstr (native_file_name));
366 g_free (native_file_name);
368 sss = create_syntax_string_source ("GET FILE=%s.",
369 ds_cstr (&filename));
371 ds_destroy (&filename);
373 if (execute_syntax (sss) )
380 sysfile_chooser_dialog (PsppireWindow *toplevel)
383 gtk_file_chooser_dialog_new (_("Open"),
384 GTK_WINDOW (toplevel),
385 GTK_FILE_CHOOSER_ACTION_OPEN,
386 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
387 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
390 GtkFileFilter *filter;
392 filter = gtk_file_filter_new ();
393 gtk_file_filter_set_name (filter, _("Data and Syntax Files"));
394 gtk_file_filter_add_pattern (filter, "*.sav");
395 gtk_file_filter_add_pattern (filter, "*.SAV");
396 gtk_file_filter_add_pattern (filter, "*.por");
397 gtk_file_filter_add_pattern (filter, "*.POR");
398 gtk_file_filter_add_pattern (filter, "*.sps");
399 gtk_file_filter_add_pattern (filter, "*.SPS");
400 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
402 filter = gtk_file_filter_new ();
403 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
404 gtk_file_filter_add_pattern (filter, "*.sav");
405 gtk_file_filter_add_pattern (filter, "*.SAV");
406 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
408 filter = gtk_file_filter_new ();
409 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
410 gtk_file_filter_add_pattern (filter, "*.por");
411 gtk_file_filter_add_pattern (filter, "*.POR");
412 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
414 filter = gtk_file_filter_new ();
415 gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
416 gtk_file_filter_add_pattern (filter, "*.sps");
417 gtk_file_filter_add_pattern (filter, "*.SPS");
418 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
420 filter = gtk_file_filter_new ();
421 gtk_file_filter_set_name (filter, _("All Files"));
422 gtk_file_filter_add_pattern (filter, "*");
423 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
427 gchar *filename = NULL;
428 g_object_get (toplevel, "filename", &filename, NULL);
430 if ( ! g_path_is_absolute (filename))
433 g_build_filename (g_get_current_dir (), filename, NULL);
434 dir_name = g_path_get_dirname (path);
439 dir_name = g_path_get_dirname (filename);
441 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
449 /* Callback for the data_open action.
450 Prompts for a filename and opens it */
452 open_window (PsppireWindow *de)
454 GtkWidget *dialog = sysfile_chooser_dialog (de);
456 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
458 case GTK_RESPONSE_ACCEPT:
461 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
463 gchar *sysname = convert_glib_filename_to_system_filename (name, NULL);
465 if (any_reader_may_open (sysname))
466 psppire_window_load (de, name);
468 open_syntax_window (name);
478 gtk_widget_destroy (dialog);
481 /* Returns true if NAME has a suffix which might denote a PSPP file */
483 name_has_suffix (const gchar *name)
485 if ( g_str_has_suffix (name, ".sav"))
487 if ( g_str_has_suffix (name, ".SAV"))
489 if ( g_str_has_suffix (name, ".por"))
491 if ( g_str_has_suffix (name, ".POR"))
498 /* Save DE to file */
500 save_file (PsppireWindow *w)
502 gchar *native_file_name = NULL;
503 gchar *file_name = NULL;
505 struct getl_interface *sss;
506 struct string filename ;
507 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (w);
509 g_object_get (w, "filename", &file_name, NULL);
511 fnx = g_string_new (file_name);
513 if ( ! name_has_suffix (fnx->str))
515 if ( de->save_as_portable)
516 g_string_append (fnx, ".por");
518 g_string_append (fnx, ".sav");
521 ds_init_empty (&filename);
524 convert_glib_filename_to_system_filename (fnx->str, NULL);
526 g_string_free (fnx, TRUE);
528 syntax_gen_string (&filename, ss_cstr (native_file_name));
529 g_free (native_file_name);
531 if ( de->save_as_portable )
533 sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
534 ds_cstr (&filename));
538 sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
539 ds_cstr (&filename));
542 ds_destroy (&filename);
544 execute_syntax (sss);
549 insert_case (PsppireDataWindow *dw)
551 psppire_data_editor_insert_case (dw->data_editor);
555 on_insert_variable (PsppireDataWindow *dw)
557 psppire_data_editor_insert_variable (dw->data_editor);
562 display_dict (PsppireDataWindow *de)
565 struct getl_interface *sss =
566 create_syntax_string_source ("DISPLAY DICTIONARY.");
568 execute_syntax (sss);
572 sysfile_info (PsppireDataWindow *de)
574 GtkWidget *dialog = sysfile_chooser_dialog (PSPPIRE_WINDOW (de));
576 if ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (dialog)))
578 struct string filename;
579 struct getl_interface *sss;
581 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
583 gchar *native_file_name =
584 convert_glib_filename_to_system_filename (file_name, NULL);
586 ds_init_empty (&filename);
588 syntax_gen_string (&filename, ss_cstr (native_file_name));
590 g_free (native_file_name);
592 sss = create_syntax_string_source ("SYSFILE INFO %s.",
593 ds_cstr (&filename));
594 execute_syntax (sss);
597 gtk_widget_destroy (dialog);
601 /* Callback for data_save_as action. Prompt for a filename and save */
603 data_save_as_dialog (PsppireDataWindow *de)
605 GtkWidget *button_sys;
607 gtk_file_chooser_dialog_new (_("Save"),
609 GTK_FILE_CHOOSER_ACTION_SAVE,
610 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
611 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
614 GtkFileFilter *filter = gtk_file_filter_new ();
615 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
616 gtk_file_filter_add_pattern (filter, "*.sav");
617 gtk_file_filter_add_pattern (filter, "*.SAV");
618 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
620 filter = gtk_file_filter_new ();
621 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
622 gtk_file_filter_add_pattern (filter, "*.por");
623 gtk_file_filter_add_pattern (filter, "*.POR");
624 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
626 filter = gtk_file_filter_new ();
627 gtk_file_filter_set_name (filter, _("All Files"));
628 gtk_file_filter_add_pattern (filter, "*");
629 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
632 GtkWidget *button_por;
633 GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
635 gtk_radio_button_new_with_label (NULL, _("System File"));
638 gtk_radio_button_new_with_label
639 (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
642 psppire_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
643 psppire_box_pack_start_defaults (GTK_BOX (vbox), button_por);
645 gtk_widget_show_all (vbox);
647 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
650 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
652 case GTK_RESPONSE_ACCEPT:
657 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog))
660 de->save_as_portable =
661 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
663 if ( ! name_has_suffix (filename->str))
665 if ( de->save_as_portable)
666 g_string_append (filename, ".por");
668 g_string_append (filename, ".sav");
671 psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str);
673 save_file (PSPPIRE_WINDOW (de));
675 g_string_free (filename, TRUE);
682 gtk_widget_destroy (dialog);
686 /* Callback for data_save action.
689 data_save (PsppireWindow *de)
691 const gchar *fn = psppire_window_get_filename (de);
694 psppire_window_save (de);
696 data_save_as_dialog (PSPPIRE_DATA_WINDOW (de));
700 /* Callback for data_new action.
701 Performs the NEW FILE command */
703 new_file (PsppireDataWindow *de)
705 struct getl_interface *sss =
706 create_syntax_string_source ("NEW FILE.");
708 execute_syntax (sss);
710 psppire_window_set_filename (PSPPIRE_WINDOW (de), NULL);
716 on_edit_paste (PsppireDataWindow *de)
718 psppire_data_editor_clip_paste (de->data_editor);
722 on_edit_copy (PsppireDataWindow *de)
724 psppire_data_editor_clip_copy (de->data_editor);
730 on_edit_cut (PsppireDataWindow *de)
732 psppire_data_editor_clip_cut (de->data_editor);
737 status_bar_activate (PsppireDataWindow *de, GtkToggleAction *action)
739 GtkWidget *statusbar = get_widget_assert (de->builder, "status-bar");
741 if ( gtk_toggle_action_get_active (action))
742 gtk_widget_show (statusbar);
744 gtk_widget_hide (statusbar);
749 grid_lines_activate (PsppireDataWindow *de, GtkToggleAction *action)
751 const gboolean grid_visible = gtk_toggle_action_get_active (action);
753 psppire_data_editor_show_grid (de->data_editor, grid_visible);
757 data_view_activate (PsppireDataWindow *de)
759 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
764 variable_view_activate (PsppireDataWindow *de)
766 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
771 fonts_activate (PsppireDataWindow *de)
773 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (de));
774 PangoFontDescription *current_font;
777 gtk_font_selection_dialog_new (_("Font Selection"));
780 current_font = GTK_WIDGET(de->data_editor)->style->font_desc;
781 font_name = pango_font_description_to_string (current_font);
783 gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (dialog), font_name);
787 gtk_window_set_transient_for (GTK_WINDOW (dialog),
788 GTK_WINDOW (toplevel));
790 if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
792 const gchar *font = gtk_font_selection_dialog_get_font_name
793 (GTK_FONT_SELECTION_DIALOG (dialog));
795 PangoFontDescription* font_desc =
796 pango_font_description_from_string (font);
798 psppire_data_editor_set_font (de->data_editor, font_desc);
801 gtk_widget_hide (dialog);
806 /* Callback for the value labels action */
808 toggle_value_labels (PsppireDataWindow *de, GtkToggleAction *ta)
810 g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
814 toggle_split_window (PsppireDataWindow *de, GtkToggleAction *ta)
816 psppire_data_editor_split_window (de->data_editor,
817 gtk_toggle_action_get_active (ta));
824 /* FIXME: Need to be more intelligent here.
825 Give the user the opportunity to save any unsaved data.
827 g_object_unref (the_data_store);
834 on_recent_data_select (GtkMenuShell *menushell,
835 PsppireWindow *window)
840 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
842 file = g_filename_from_uri (uri, NULL, NULL);
846 psppire_window_load (window, file);
852 on_recent_files_select (GtkMenuShell *menushell, gpointer user_data)
859 gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
861 file = g_filename_from_uri (uri, NULL, NULL);
865 se = psppire_syntax_window_new ();
867 if ( psppire_window_load (PSPPIRE_WINDOW (se), file) )
868 gtk_widget_show (se);
870 gtk_widget_destroy (se);
877 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
879 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
881 gtk_action_set_visible (de->delete_cases, case_num != -1);
886 enable_delete_variables (GtkWidget *w, gint var, gpointer data)
888 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
890 gtk_action_set_visible (de->delete_variables, var != -1);
893 /* Callback for when the datasheet/varsheet is selected */
895 on_switch_sheet (GtkNotebook *notebook,
896 GtkNotebookPage *page,
900 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
902 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
904 GtkWidget *view_data =
905 gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_data");
907 GtkWidget *view_variables =
908 gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_variables");
912 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
913 gtk_widget_hide (view_variables);
914 gtk_widget_show (view_data);
915 gtk_action_set_sensitive (de->insert_variable, TRUE);
916 gtk_action_set_sensitive (de->insert_case, FALSE);
917 gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
919 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
920 gtk_widget_show (view_variables);
921 gtk_widget_hide (view_data);
922 gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
923 gtk_action_set_sensitive (de->insert_case, TRUE);
926 g_assert_not_reached ();
931 update_paste_menuitem (de, page_num);
938 set_unsaved (gpointer w)
940 psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
944 /* Connects the action called ACTION_NAME to HANDLER passing DW as the auxilliary data.
945 Returns a pointer to the action
948 connect_action (PsppireDataWindow *dw, const char *action_name,
951 GtkAction *action = get_action_assert (dw->builder, action_name);
953 g_signal_connect_swapped (action, "activate", handler, dw);
959 psppire_data_window_init (PsppireDataWindow *de)
962 PsppireDict *dict = NULL;
968 GtkWidget *box = gtk_vbox_new (FALSE, 0);
969 de->builder = builder_new ("data-editor.ui");
971 menubar = get_widget_assert (de->builder, "menubar");
972 hb = get_widget_assert (de->builder, "handlebox1");
973 sb = get_widget_assert (de->builder, "status-bar");
976 PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
978 g_signal_connect_swapped (the_data_store, "case-changed",
979 G_CALLBACK (set_unsaved), de);
981 g_signal_connect_swapped (the_data_store, "case-inserted",
982 G_CALLBACK (set_unsaved), de);
984 g_signal_connect_swapped (the_data_store, "cases-deleted",
985 G_CALLBACK (set_unsaved), de);
987 dataset_set_callback (the_dataset, set_unsaved, de);
989 connect_help (de->builder);
991 gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0);
992 gtk_box_pack_start (GTK_BOX (box), hb, FALSE, TRUE, 0);
993 gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (de->data_editor), TRUE, TRUE, 0);
994 gtk_box_pack_start (GTK_BOX (box), sb, FALSE, TRUE, 0);
996 gtk_container_add (GTK_CONTAINER (de), box);
998 set_cut_copy_menuitem_sensitivity (de, FALSE);
1000 g_signal_connect_swapped (de->data_editor, "data-selection-changed",
1001 G_CALLBACK (set_cut_copy_menuitem_sensitivity), de);
1004 set_paste_menuitem_sensitivity (de, FALSE);
1006 g_signal_connect_swapped (de->data_editor, "data-available-changed",
1007 G_CALLBACK (set_paste_menuitem_sensitivity), de);
1009 dataset_add_transform_change_callback (the_dataset,
1010 transformation_change_callback,
1016 g_assert(vs); /* Traps a possible bug in w32 build */
1018 g_object_get (vs, "dictionary", &dict, NULL);
1020 g_signal_connect (dict, "weight-changed",
1021 G_CALLBACK (on_weight_change),
1024 g_signal_connect (dict, "filter-changed",
1025 G_CALLBACK (on_filter_change),
1028 g_signal_connect (dict, "split-changed",
1029 G_CALLBACK (on_split_change),
1033 connect_action (de, "edit_copy", G_CALLBACK (on_edit_copy));
1035 connect_action (de, "edit_cut", G_CALLBACK (on_edit_cut));
1037 connect_action (de, "file_new_data", G_CALLBACK (new_file));
1039 connect_action (de, "file_import-text", G_CALLBACK (text_data_import_assistant));
1041 connect_action (de, "file_save", G_CALLBACK (data_save));
1043 connect_action (de, "file_open", G_CALLBACK (open_window));
1045 connect_action (de, "file_save_as", G_CALLBACK (data_save_as_dialog));
1047 connect_action (de, "file_information_working-file", G_CALLBACK (display_dict));
1049 connect_action (de, "file_information_external-file", G_CALLBACK (sysfile_info));
1051 connect_action (de, "edit_paste", G_CALLBACK (on_edit_paste));
1053 de->insert_case = connect_action (de, "edit_insert-case", G_CALLBACK (insert_case));
1055 de->insert_variable = connect_action (de, "action_insert-variable", G_CALLBACK (on_insert_variable));
1057 de->invoke_goto_dialog = connect_action (de, "edit_goto-case", G_CALLBACK (goto_case_dialog));
1059 g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de);
1062 de->delete_cases = get_action_assert (de->builder, "edit_clear-cases");
1064 g_signal_connect_swapped (de->delete_cases, "activate", G_CALLBACK (psppire_data_editor_delete_cases), de->data_editor);
1066 gtk_action_set_visible (de->delete_cases, FALSE);
1071 de->delete_variables = get_action_assert (de->builder, "edit_clear-variables");
1073 g_signal_connect_swapped (de->delete_variables, "activate", G_CALLBACK (psppire_data_editor_delete_variables), de->data_editor);
1075 gtk_action_set_visible (de->delete_variables, FALSE);
1079 connect_action (de, "data_transpose", G_CALLBACK (transpose_dialog));
1081 connect_action (de, "data_select-cases", G_CALLBACK (select_cases_dialog));
1083 connect_action (de, "data_sort-cases", G_CALLBACK (sort_cases_dialog));
1085 connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog));
1087 connect_action (de, "transform_compute", G_CALLBACK (compute_dialog));
1089 connect_action (de, "edit_find", G_CALLBACK (find_dialog));
1091 connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog));
1093 connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog));
1096 connect_action (de, "utilities_variables", G_CALLBACK (variable_info_dialog));
1098 connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog));
1100 connect_action (de, "indep-t-test", G_CALLBACK (t_test_independent_samples_dialog));
1102 connect_action (de, "paired-t-test", G_CALLBACK (t_test_paired_samples_dialog));
1104 connect_action (de, "one-sample-t-test", G_CALLBACK (t_test_one_sample_dialog));
1106 connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
1108 connect_action (de, "transform_rank", G_CALLBACK (rank_dialog));
1110 connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
1112 connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog));
1114 connect_action (de, "analyze_descriptives", G_CALLBACK (descriptives_dialog));
1116 connect_action (de, "analyze_frequencies", G_CALLBACK (frequencies_dialog));
1118 connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog));
1120 connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog));
1122 connect_action (de, "linear-regression", G_CALLBACK (regression_dialog));
1124 connect_action (de, "reliability", G_CALLBACK (reliability_dialog));
1126 connect_action (de, "roc-curve", G_CALLBACK (roc_dialog));
1128 connect_action (de, "correlation", G_CALLBACK (correlation_dialog));
1130 connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
1132 connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
1134 connect_action (de, "binomial", G_CALLBACK (binomial_dialog));
1138 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1140 GtkWidget *recent_data =
1141 gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-data");
1143 GtkWidget *recent_files =
1144 gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
1147 GtkWidget *menu_data =
1148 gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1150 GtkWidget *menu_files =
1151 gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1154 GtkRecentFilter *filter = gtk_recent_filter_new ();
1156 gtk_recent_filter_add_pattern (filter, "*.sav");
1157 gtk_recent_filter_add_pattern (filter, "*.SAV");
1158 gtk_recent_filter_add_pattern (filter, "*.por");
1159 gtk_recent_filter_add_pattern (filter, "*.POR");
1161 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);
1163 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_data), filter);
1166 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu_data);
1169 g_signal_connect (menu_data, "selection-done", G_CALLBACK (on_recent_data_select), de);
1172 GtkRecentFilter *filter = gtk_recent_filter_new ();
1174 gtk_recent_filter_add_pattern (filter, "*.sps");
1175 gtk_recent_filter_add_pattern (filter, "*.SPS");
1177 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_files), GTK_RECENT_SORT_MRU);
1179 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_files), filter);
1182 gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu_files);
1184 g_signal_connect (menu_files, "selection-done", G_CALLBACK (on_recent_files_select), de);
1188 connect_action (de, "file_new_syntax", G_CALLBACK (create_syntax_window));
1191 g_signal_connect (de->data_editor,
1193 G_CALLBACK (enable_delete_cases),
1196 g_signal_connect (de->data_editor,
1197 "variables-selected",
1198 G_CALLBACK (enable_delete_variables),
1202 g_signal_connect (de->data_editor,
1204 G_CALLBACK (on_switch_sheet), de);
1206 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1207 gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1209 connect_action (de, "view_statusbar", G_CALLBACK (status_bar_activate));
1211 connect_action (de, "view_gridlines", G_CALLBACK (grid_lines_activate));
1213 connect_action (de, "view_data", G_CALLBACK (data_view_activate));
1215 connect_action (de, "view_variables", G_CALLBACK (variable_view_activate));
1217 connect_action (de, "view_fonts", G_CALLBACK (fonts_activate));
1219 connect_action (de, "file_quit", G_CALLBACK (file_quit));
1221 connect_action (de, "transform_run-pending", G_CALLBACK (execute));
1223 connect_action (de, "windows_minimise_all", G_CALLBACK (psppire_window_minimise_all));
1225 g_signal_connect_swapped (get_action_assert (de->builder, "windows_split"), "toggled", G_CALLBACK (toggle_split_window), de);
1228 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1230 merge_help_menu (uim);
1232 PSPPIRE_WINDOW (de)->menu =
1233 GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
1237 GtkWidget *data_sheet_cases_popup_menu = get_widget_assert (de->builder,
1238 "datasheet-cases-popup");
1240 GtkWidget *var_sheet_variable_popup_menu = get_widget_assert (de->builder,
1241 "varsheet-variable-popup");
1243 GtkWidget *data_sheet_variable_popup_menu = get_widget_assert (de->builder,
1244 "datasheet-variable-popup");
1246 g_signal_connect_swapped (get_action_assert (de->builder, "sort-up"), "activate",
1247 G_CALLBACK (psppire_data_editor_sort_ascending),
1250 g_signal_connect_swapped (get_action_assert (de->builder, "sort-down"), "activate",
1251 G_CALLBACK (psppire_data_editor_sort_descending),
1254 g_object_set (de->data_editor,
1255 "datasheet-column-menu", data_sheet_variable_popup_menu,
1256 "datasheet-row-menu", data_sheet_cases_popup_menu,
1257 "varsheet-row-menu", var_sheet_variable_popup_menu,
1261 gtk_widget_show (GTK_WIDGET (de->data_editor));
1262 gtk_widget_show (box);
1267 psppire_data_window_new (void)
1269 return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
1270 "description", _("Data Editor"),
1276 psppire_data_window_iface_init (PsppireWindowIface *iface)
1278 iface->save = save_file;
1279 iface->load = load_file;