ffa9482eb0f4b766c391e32ac7c3ecac9dca3087
[pspp] / src / ui / gui / psppire-data-window.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2008, 2009  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include <gtk/gtksignal.h>
20 #include <gtk/gtkbox.h>
21 #include "executor.h"
22 #include "helper.h"
23
24 #include "text-data-import-dialog.h"
25
26
27 #include <ui/syntax-gen.h>
28 #include <language/syntax-string-source.h>
29 #include <libpspp/message.h>
30 #include <stdlib.h>
31
32 #include <data/procedure.h>
33
34 #include "psppire.h"
35 #include "psppire-window.h"
36 #include "psppire-data-window.h"
37 #include "psppire-syntax-window.h"
38
39 #include "about.h"
40
41 #include "goto-case-dialog.h"
42 #include "weight-cases-dialog.h"
43 #include "split-file-dialog.h"
44 #include "transpose-dialog.h"
45 #include "sort-cases-dialog.h"
46 #include "select-cases-dialog.h"
47 #include "compute-dialog.h"
48 #include "find-dialog.h"
49 #include "rank-dialog.h"
50 #include "recode-dialog.h"
51 #include "comments-dialog.h"
52 #include "variable-info-dialog.h"
53 #include "descriptives-dialog.h"
54 #include "crosstabs-dialog.h"
55 #include "frequencies-dialog.h"
56 #include "examine-dialog.h"
57 #include "regression-dialog.h"
58 #include "reliability-dialog.h"
59 #include "oneway-anova-dialog.h"
60 #include "t-test-independent-samples-dialog.h"
61 #include "t-test-one-sample.h"
62 #include "t-test-paired-samples.h"
63
64
65 #include <gettext.h>
66 #define _(msgid) gettext (msgid)
67 #define N_(msgid) msgid
68
69
70
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);
75
76
77 static void psppire_data_window_iface_init (PsppireWindowIface *iface);
78
79
80 GType
81 psppire_data_window_get_type (void)
82 {
83   static GType psppire_data_window_type = 0;
84
85   if (!psppire_data_window_type)
86     {
87       static const GTypeInfo psppire_data_window_info =
88         {
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,
94           NULL,
95           sizeof (PsppireDataWindow),
96           0,
97           (GInstanceInitFunc) psppire_data_window_init,
98         };
99
100       static const GInterfaceInfo window_interface_info =
101         {
102           (GInterfaceInitFunc) psppire_data_window_iface_init,
103           NULL,
104           NULL
105         };
106
107       psppire_data_window_type =
108         g_type_register_static (PSPPIRE_TYPE_WINDOW, "PsppireDataWindow",
109                                 &psppire_data_window_info, 0);
110
111       
112       g_type_add_interface_static (psppire_data_window_type,
113                                    PSPPIRE_TYPE_WINDOW_MODEL,
114                                    &window_interface_info);
115     }
116
117   return psppire_data_window_type;
118 }
119
120 static GObjectClass *parent_class ;
121
122 static void
123 psppire_data_window_finalize (GObject *object)
124 {
125   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (object);
126
127   g_object_unref (de->builder);
128
129   if (G_OBJECT_CLASS (parent_class)->finalize)
130     (*G_OBJECT_CLASS (parent_class)->finalize) (object);
131 }
132
133
134 static void
135 psppire_data_window_class_init (PsppireDataWindowClass *class)
136 {
137   parent_class = g_type_class_peek_parent (class);
138 }
139
140
141 static void
142 psppire_data_window_base_init (PsppireDataWindowClass *class)
143 {
144   GObjectClass *object_class = G_OBJECT_CLASS (class);
145
146   object_class->finalize = psppire_data_window_finalize;
147 }
148
149
150
151 static void
152 psppire_data_window_base_finalize (PsppireDataWindowClass *class,
153                                    gpointer class_data)
154 {
155 }
156
157
158 \f
159
160
161 extern PsppireVarStore *the_var_store;
162 extern struct dataset *the_dataset;
163 extern PsppireDataStore *the_data_store ;
164
165 extern GtkRecentManager *the_recent_mgr;
166
167 static void
168 set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
169 {
170   GtkAction *edit_paste = get_action_assert (de->builder, "edit_paste");
171
172   gtk_action_set_sensitive (edit_paste, x);
173 }
174
175 static void
176 set_cut_copy_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
177 {
178   GtkAction *edit_copy = get_action_assert (de->builder, "edit_copy");
179   GtkAction *edit_cut = get_action_assert (de->builder, "edit_cut");
180
181   gtk_action_set_sensitive (edit_copy, x);
182   gtk_action_set_sensitive (edit_cut, x);
183 }
184
185 /* Run the EXECUTE command. */
186 static void
187 execute (GtkMenuItem *mi, gpointer data)
188 {
189   struct getl_interface *sss = create_syntax_string_source ("EXECUTE.");
190
191   execute_syntax (sss);
192 }
193
194 static void
195 transformation_change_callback (bool transformations_pending,
196                                 gpointer data)
197 {
198   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
199
200   GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
201
202   GtkWidget *menuitem =
203     gtk_ui_manager_get_widget (uim,"/ui/menubar/transform/transform_run-pending");
204
205   GtkWidget *status_label  =
206     get_widget_assert (de->builder, "case-counter-area");
207
208   gtk_widget_set_sensitive (menuitem, transformations_pending);
209
210
211   if ( transformations_pending)
212     gtk_label_set_text (GTK_LABEL (status_label),
213                         _("Transformations Pending"));
214   else
215     gtk_label_set_text (GTK_LABEL (status_label), "");
216 }
217
218 /* Callback for when the dictionary changes its filter variable */
219 static void
220 on_filter_change (GObject *o, gint filter_index, gpointer data)
221 {
222   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
223
224   GtkWidget *filter_status_area =
225     get_widget_assert (de->builder, "filter-use-status-area");
226
227   if ( filter_index == -1 )
228     {
229       gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
230     }
231   else
232     {
233       PsppireVarStore *vs = NULL;
234       PsppireDict *dict = NULL;
235       struct variable *var ;
236       gchar *text ;
237
238       g_object_get (de->data_editor, "var-store", &vs, NULL);
239       g_object_get (vs, "dictionary", &dict, NULL);
240
241       var = psppire_dict_get_variable (dict, filter_index);
242
243       text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
244
245       gtk_label_set_text (GTK_LABEL (filter_status_area), text);
246
247       g_free (text);
248     }
249 }
250
251 /* Callback for when the dictionary changes its split variables */
252 static void
253 on_split_change (PsppireDict *dict, gpointer data)
254 {
255   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
256
257   size_t n_split_vars = dict_get_split_cnt (dict->dict);
258
259   GtkWidget *split_status_area =
260     get_widget_assert (de->builder, "split-file-status-area");
261
262   if ( n_split_vars == 0 )
263     {
264       gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
265     }
266   else
267     {
268       gint i;
269       GString *text;
270       const struct variable *const * split_vars =
271         dict_get_split_vars (dict->dict);
272
273       text = g_string_new (_("Split by "));
274
275       for (i = 0 ; i < n_split_vars - 1; ++i )
276         {
277           g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
278         }
279       g_string_append (text, var_get_name (split_vars[i]));
280
281       gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
282
283       g_string_free (text, TRUE);
284     }
285 }
286
287
288
289
290 /* Callback for when the dictionary changes its weights */
291 static void
292 on_weight_change (GObject *o, gint weight_index, gpointer data)
293 {
294   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
295
296   GtkWidget *weight_status_area =
297     get_widget_assert (de->builder, "weight-status-area");
298
299   if ( weight_index == -1 )
300     {
301       gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
302     }
303   else
304     {
305       struct variable *var ;
306       PsppireVarStore *vs = NULL;
307       PsppireDict *dict = NULL;
308       gchar *text;
309
310       g_object_get (de->data_editor, "var-store", &vs, NULL);
311       g_object_get (vs, "dictionary", &dict, NULL);
312       
313       var = psppire_dict_get_variable (dict, weight_index);
314
315       text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
316
317       gtk_label_set_text (GTK_LABEL (weight_status_area), text);
318
319       g_free (text);
320     }
321 }
322
323 #if 0
324 static void
325 dump_rm (GtkRecentManager *rm)
326 {
327   GList *items = gtk_recent_manager_get_items (rm);
328
329   GList *i;
330
331   g_print ("Recent Items:\n");
332   for (i = items; i; i = i->next)
333     {
334       GtkRecentInfo *ri = i->data;
335
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)
341                );
342
343
344       gtk_recent_info_unref (ri);
345     }
346
347   g_list_free (items);
348 }
349 #endif
350
351
352 static gboolean
353 load_file (PsppireWindow *de, const gchar *file_name)
354 {
355   gchar *native_file_name;
356   struct getl_interface *sss;
357   struct string filename;
358
359   ds_init_empty (&filename);
360
361   native_file_name =
362     convert_glib_filename_to_system_filename (file_name, NULL);
363
364   syntax_gen_string (&filename, ss_cstr (native_file_name));
365
366   g_free (native_file_name);
367
368   sss = create_syntax_string_source ("GET FILE=%s.",
369                                      ds_cstr (&filename));
370
371   ds_destroy (&filename);
372
373   if (execute_syntax (sss) )
374     return TRUE;
375
376   return FALSE;
377 }
378
379 static GtkWidget *
380 sysfile_chooser_dialog (PsppireWindow *toplevel)
381 {
382   GtkWidget *dialog =
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,
388                                  NULL);
389
390   GtkFileFilter *filter = gtk_file_filter_new ();
391   gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
392   gtk_file_filter_add_pattern (filter, "*.sav");
393   gtk_file_filter_add_pattern (filter, "*.SAV");
394   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
395
396   filter = gtk_file_filter_new ();
397   gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
398   gtk_file_filter_add_pattern (filter, "*.por");
399   gtk_file_filter_add_pattern (filter, "*.POR");
400   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
401
402   filter = gtk_file_filter_new ();
403   gtk_file_filter_set_name (filter, _("All Files"));
404   gtk_file_filter_add_pattern (filter, "*");
405   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
406
407   {
408     gchar *dir_name;
409     gchar *filename = NULL;
410     g_object_get (toplevel, "filename", &filename, NULL);
411
412     if ( ! g_path_is_absolute (filename))
413       {
414         gchar *path =
415           g_build_filename (g_get_current_dir (), filename, NULL);
416         dir_name = g_path_get_dirname (path);
417         g_free (path);
418       }
419     else
420       {
421         dir_name = g_path_get_dirname (filename);
422       }
423     gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
424                                          dir_name);
425     free (dir_name);
426   }
427
428   return dialog;
429 }
430
431 /* Callback for the data_open action.
432    Prompts for a filename and opens it */
433 static void
434 open_data_dialog (GtkAction *action, PsppireWindow *de)
435 {
436   GtkWidget *dialog = sysfile_chooser_dialog (de);
437
438   switch (gtk_dialog_run (GTK_DIALOG (dialog)))
439     {
440     case GTK_RESPONSE_ACCEPT:
441       {
442         gchar *name =
443           gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
444
445         psppire_window_load (de, name);
446
447         g_free (name);
448       }
449       break;
450     default:
451       break;
452     }
453
454   gtk_widget_destroy (dialog);
455 }
456
457 /* Returns true if NAME has a suffix which might denote a PSPP file */
458 static gboolean
459 name_has_suffix (const gchar *name)
460 {
461   if ( g_str_has_suffix (name, ".sav"))
462     return TRUE;
463   if ( g_str_has_suffix (name, ".SAV"))
464     return TRUE;
465   if ( g_str_has_suffix (name, ".por"))
466     return TRUE;
467   if ( g_str_has_suffix (name, ".POR"))
468     return TRUE;
469
470   return FALSE;
471 }
472
473
474 /* Save DE to file */
475 static void
476 save_file (PsppireWindow *w)
477 {
478   gchar *native_file_name = NULL;
479   gchar *file_name = NULL;
480   GString *fnx;
481   struct getl_interface *sss;
482   struct string filename ;
483   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (w);
484
485   g_object_get (w, "filename", &file_name, NULL);
486
487   fnx = g_string_new (file_name);
488
489   if ( ! name_has_suffix (fnx->str))
490     {
491       if ( de->save_as_portable)
492         g_string_append (fnx, ".por");
493       else
494         g_string_append (fnx, ".sav");
495     }
496
497   ds_init_empty (&filename);
498
499   native_file_name =
500     convert_glib_filename_to_system_filename (fnx->str, NULL);
501
502   g_string_free (fnx, TRUE);
503
504   syntax_gen_string (&filename, ss_cstr (native_file_name));
505   g_free (native_file_name);
506
507   if ( de->save_as_portable )
508     {
509       sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
510                                          ds_cstr (&filename));
511     }
512   else
513     {
514       sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
515                                          ds_cstr (&filename));
516     }
517
518   ds_destroy (&filename);
519
520   execute_syntax (sss);
521 }
522
523
524 static void
525 insert_case (GtkAction *action, gpointer data)
526 {
527   PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (data);
528   psppire_data_editor_insert_case (dw->data_editor);
529 }
530
531 static void
532 on_insert_variable (GtkAction *action, gpointer data)
533 {
534   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
535   psppire_data_editor_insert_variable (de);
536 }
537
538
539 static void
540 display_dict (PsppireDataWindow *de)
541 {
542
543   struct getl_interface *sss =
544     create_syntax_string_source ("DISPLAY DICTIONARY.");
545
546   execute_syntax (sss);
547 }
548
549 static void
550 sysfile_info (PsppireDataWindow *de)
551 {
552   GtkWidget *dialog = sysfile_chooser_dialog (PSPPIRE_WINDOW (de));
553
554   if  ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (dialog)))
555     {
556       struct string filename;
557       struct getl_interface *sss;
558       gchar *file_name =
559         gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
560
561       gchar *native_file_name =
562         convert_glib_filename_to_system_filename (file_name, NULL);
563
564       ds_init_empty (&filename);
565
566       syntax_gen_string (&filename, ss_cstr (native_file_name));
567
568       g_free (native_file_name);
569
570       sss = create_syntax_string_source ("SYSFILE INFO %s.",
571                                          ds_cstr (&filename));
572       execute_syntax (sss);
573     }
574
575   gtk_widget_destroy (dialog);
576 }
577
578
579 /* Callback for data_save_as action. Prompt for a filename and save */
580 static void
581 data_save_as_dialog (PsppireDataWindow *de)
582 {
583   GtkWidget *button_sys;
584   GtkWidget *dialog =
585     gtk_file_chooser_dialog_new (_("Save"),
586                                  GTK_WINDOW (de),
587                                  GTK_FILE_CHOOSER_ACTION_SAVE,
588                                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
589                                  GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
590                                  NULL);
591
592   GtkFileFilter *filter = gtk_file_filter_new ();
593   gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
594   gtk_file_filter_add_pattern (filter, "*.sav");
595   gtk_file_filter_add_pattern (filter, "*.SAV");
596   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
597
598   filter = gtk_file_filter_new ();
599   gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
600   gtk_file_filter_add_pattern (filter, "*.por");
601   gtk_file_filter_add_pattern (filter, "*.POR");
602   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
603
604   filter = gtk_file_filter_new ();
605   gtk_file_filter_set_name (filter, _("All Files"));
606   gtk_file_filter_add_pattern (filter, "*");
607   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
608
609   {
610     GtkWidget *button_por;
611     GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
612     button_sys =
613       gtk_radio_button_new_with_label (NULL, _("System File"));
614
615     button_por =
616       gtk_radio_button_new_with_label
617       (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
618        _("Portable File"));
619
620     gtk_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
621     gtk_box_pack_start_defaults (GTK_BOX (vbox), button_por);
622
623     gtk_widget_show_all (vbox);
624
625     gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
626   }
627
628   switch (gtk_dialog_run (GTK_DIALOG (dialog)))
629     {
630     case GTK_RESPONSE_ACCEPT:
631       {
632         GString *filename =
633           g_string_new
634           (
635            gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog))
636            );
637
638         de->save_as_portable =
639           ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
640
641         if ( ! name_has_suffix (filename->str))
642           {
643             if ( de->save_as_portable)
644               g_string_append (filename, ".por");
645             else
646               g_string_append (filename, ".sav");
647           }
648
649         psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str);
650
651         save_file (PSPPIRE_WINDOW (de));
652
653         g_string_free (filename, TRUE);
654       }
655       break;
656     default:
657       break;
658     }
659
660   gtk_widget_destroy (dialog);
661 }
662
663
664 /* Callback for data_save action.
665  */
666 static void
667 data_save (PsppireWindow *de)
668 {
669   const gchar *fn = psppire_window_get_filename (de);
670
671   if ( NULL != fn)
672     psppire_window_save (de);
673   else
674     data_save_as_dialog (PSPPIRE_DATA_WINDOW (de));
675 }
676
677
678 /* Callback for data_new action.
679    Performs the NEW FILE command */
680 static void
681 new_file (GtkAction *action, PsppireDataWindow *de)
682 {
683   struct getl_interface *sss =
684     create_syntax_string_source ("NEW FILE.");
685
686   execute_syntax (sss);
687
688   psppire_window_set_filename (PSPPIRE_WINDOW (de), NULL);
689 }
690
691
692
693 static void
694 on_edit_paste (GtkAction *a, gpointer data)
695 {
696   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
697
698   psppire_data_editor_clip_paste (de->data_editor);
699 }
700
701 static void
702 on_edit_copy (GtkMenuItem *m, gpointer data)
703 {
704   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
705
706   psppire_data_editor_clip_copy (de->data_editor);
707 }
708
709
710
711 static void
712 on_edit_cut (GtkMenuItem *m, gpointer data)
713 {
714   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
715
716   psppire_data_editor_clip_cut (de->data_editor);
717 }
718
719
720 static void
721 status_bar_activate (GtkToggleAction *action, gpointer data)
722 {
723   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
724   GtkWidget *statusbar = get_widget_assert (de->builder, "status-bar");
725
726   if ( gtk_toggle_action_get_active (action) )
727     gtk_widget_show (statusbar);
728   else
729     gtk_widget_hide (statusbar);
730 }
731
732
733 static void
734 grid_lines_activate (GtkToggleAction *action, gpointer data)
735 {
736   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
737   const gboolean grid_visible = gtk_toggle_action_get_active (action);
738
739   psppire_data_editor_show_grid (de->data_editor, grid_visible);
740 }
741
742 static void
743 data_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
744 {
745   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
746
747   gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
748 }
749
750
751 static void
752 variable_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
753 {
754   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
755
756   gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
757 }
758
759
760 static void
761 fonts_activate (GtkMenuItem *menuitem, gpointer data)
762 {
763   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
764   GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (de));
765   PangoFontDescription *current_font;
766   gchar *font_name;
767   GtkWidget *dialog =
768     gtk_font_selection_dialog_new (_("Font Selection"));
769
770
771   current_font = GTK_WIDGET(de->data_editor)->style->font_desc;
772   font_name = pango_font_description_to_string (current_font);
773
774   gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (dialog), font_name);
775
776   g_free (font_name);
777
778   gtk_window_set_transient_for (GTK_WINDOW (dialog),
779                                 GTK_WINDOW (toplevel));
780
781   if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
782     {
783       const gchar *font = gtk_font_selection_dialog_get_font_name
784         (GTK_FONT_SELECTION_DIALOG (dialog));
785
786       PangoFontDescription* font_desc =
787         pango_font_description_from_string (font);
788
789       psppire_data_editor_set_font (de->data_editor, font_desc);
790     }
791
792   gtk_widget_hide (dialog);
793 }
794
795
796
797 /* Callback for the value labels action */
798 static void
799 toggle_value_labels (GtkToggleAction *ta, gpointer data)
800 {
801   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
802
803   g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
804 }
805
806 static void
807 toggle_split_window (GtkToggleAction *ta, gpointer data)
808 {
809   PsppireDataWindow  *de = PSPPIRE_DATA_WINDOW (data);
810
811   psppire_data_editor_split_window (de->data_editor,
812                                     gtk_toggle_action_get_active (ta));
813 }
814
815
816 static void
817 file_quit (GtkCheckMenuItem *menuitem, gpointer data)
818 {
819   /* FIXME: Need to be more intelligent here.
820      Give the user the opportunity to save any unsaved data.
821   */
822   g_object_unref (the_data_store);
823
824   psppire_quit ();
825 }
826
827
828
829 static GtkWidget *
830 create_data_sheet_variable_popup_menu (PsppireDataWindow *de)
831 {
832   GtkWidget *menu = gtk_menu_new ();
833
834   GtkWidget *sort_ascending =
835     gtk_action_create_menu_item (gtk_action_new ("sort-up",
836                                                  _("Sort Ascending"),
837                                                  NULL,
838                                                  "gtk-sort-ascending"));
839
840   GtkWidget *sort_descending =
841     gtk_action_create_menu_item (gtk_action_new ("sort-down",
842                                                  _("Sort Descending"),
843                                                  NULL,
844                                                  "gtk-sort-descending"));
845
846   GtkWidget *insert_variable =
847     gtk_menu_item_new_with_label (_("Insert Variable"));
848
849   GtkWidget *clear_variable =
850     gtk_menu_item_new_with_label (_("Clear"));
851
852
853   gtk_action_connect_proxy (de->delete_variables,
854                             clear_variable );
855
856
857   gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
858
859
860   gtk_menu_shell_append (GTK_MENU_SHELL (menu),
861                          gtk_separator_menu_item_new ());
862
863
864   gtk_menu_shell_append (GTK_MENU_SHELL (menu), clear_variable);
865
866
867   gtk_menu_shell_append (GTK_MENU_SHELL (menu),
868                          gtk_separator_menu_item_new ());
869
870
871   gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_ascending);
872
873
874   g_signal_connect_swapped (sort_ascending, "activate",
875                             G_CALLBACK (psppire_data_editor_sort_ascending),
876                             de->data_editor);
877
878   g_signal_connect_swapped (sort_descending, "activate",
879                             G_CALLBACK (psppire_data_editor_sort_descending),
880                             de->data_editor);
881
882   g_signal_connect_swapped (insert_variable, "activate",
883                             G_CALLBACK (gtk_action_activate),
884                             de->insert_variable);
885
886
887   gtk_menu_shell_append (GTK_MENU_SHELL (menu), sort_descending);
888
889   gtk_widget_show_all (menu);
890
891   return menu;
892 }
893
894
895 static GtkWidget *
896 create_data_sheet_cases_popup_menu (PsppireDataWindow *de)
897 {
898   GtkWidget *menu = gtk_menu_new ();
899
900   GtkWidget *insert_case =
901     gtk_menu_item_new_with_label (_("Insert Case"));
902
903   GtkWidget *delete_case =
904     gtk_menu_item_new_with_label (_("Clear"));
905
906
907   gtk_action_connect_proxy (de->delete_cases,
908                             delete_case);
909
910
911   gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_case);
912
913   g_signal_connect_swapped (insert_case, "activate",
914                             G_CALLBACK (gtk_action_activate),
915                             de->insert_case);
916
917
918   gtk_menu_shell_append (GTK_MENU_SHELL (menu),
919                          gtk_separator_menu_item_new ());
920
921
922   gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_case);
923
924
925   gtk_widget_show_all (menu);
926
927   return menu;
928 }
929
930
931 static GtkWidget *
932 create_var_sheet_variable_popup_menu (PsppireDataWindow *de)
933 {
934   GtkWidget *menu = gtk_menu_new ();
935
936   GtkWidget *insert_variable =
937     gtk_menu_item_new_with_label (_("Insert Variable"));
938
939   GtkWidget *delete_variable =
940     gtk_menu_item_new_with_label (_("Clear"));
941
942
943   gtk_action_connect_proxy (de->delete_variables,
944                             delete_variable);
945
946
947   gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
948
949   g_signal_connect_swapped (insert_variable, "activate",
950                             G_CALLBACK (gtk_action_activate),
951                             de->insert_variable);
952
953
954   gtk_menu_shell_append (GTK_MENU_SHELL (menu),
955                          gtk_separator_menu_item_new ());
956
957
958   gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_variable);
959
960
961   gtk_widget_show_all (menu);
962
963   return menu;
964 }
965
966
967 static void
968 on_recent_data_select (GtkMenuShell *menushell,
969                        PsppireWindow *window)
970 {
971   gchar *file;
972
973   gchar *uri =
974     gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
975
976   file = g_filename_from_uri (uri, NULL, NULL);
977
978   g_free (uri);
979
980   psppire_window_load (window, file);
981
982   g_free (file);
983 }
984
985 static void
986 on_recent_files_select (GtkMenuShell *menushell,   gpointer user_data)
987 {
988   gchar *file;
989
990   GtkWidget *se ;
991
992   gchar *uri =
993     gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
994
995   file = g_filename_from_uri (uri, NULL, NULL);
996
997   g_free (uri);
998
999   se = psppire_syntax_window_new ();
1000
1001   if ( psppire_window_load (PSPPIRE_WINDOW (se), file) ) 
1002     gtk_widget_show (se);
1003   else
1004     gtk_widget_destroy (se);
1005
1006   g_free (file);
1007 }
1008
1009
1010 static void
1011 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
1012 {
1013   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
1014
1015   gtk_action_set_visible (de->delete_cases, case_num != -1);
1016 }
1017
1018
1019 static void
1020 enable_delete_variables (GtkWidget *w, gint var, gpointer data)
1021 {
1022   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
1023
1024   gtk_action_set_visible (de->delete_variables, var != -1);
1025 }
1026
1027 /* Callback for when the datasheet/varsheet is selected */
1028 static void
1029 on_switch_sheet (GtkNotebook *notebook,
1030                  GtkNotebookPage *page,
1031                  guint page_num,
1032                  gpointer user_data)
1033 {
1034   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
1035
1036   GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1037
1038   GtkWidget *view_data =
1039     gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_data");
1040
1041   GtkWidget *view_variables =
1042     gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_variables");
1043
1044   switch (page_num)
1045     {
1046     case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1047       gtk_widget_hide (view_variables);
1048       gtk_widget_show (view_data);
1049       gtk_action_set_sensitive (de->insert_variable, TRUE);
1050       gtk_action_set_sensitive (de->insert_case, FALSE);
1051       gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
1052       break;
1053     case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1054       gtk_widget_show (view_variables);
1055       gtk_widget_hide (view_data);
1056       gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
1057       gtk_action_set_sensitive (de->insert_case, TRUE);
1058       break;
1059     default:
1060       g_assert_not_reached ();
1061       break;
1062     }
1063
1064 #if 0
1065   update_paste_menuitem (de, page_num);
1066 #endif
1067 }
1068
1069
1070 static GtkAction *
1071 resolve_action (GtkBuilder *builder, const gchar *action, const gchar *proxy)
1072 {
1073   GtkWidget *pr = NULL;
1074   GtkAction *act = get_action_assert (builder, action);
1075   g_assert (GTK_IS_ACTION (act));
1076
1077   if ( proxy )
1078     pr = get_widget_assert (builder, proxy);
1079
1080   if ( pr )
1081     gtk_action_connect_proxy (act, pr);
1082
1083   return act;
1084 }
1085
1086
1087 static void
1088 set_unsaved (gpointer w)
1089 {
1090   psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
1091 }
1092
1093 static void
1094 psppire_data_window_init (PsppireDataWindow *de)
1095 {
1096   PsppireVarStore *vs;
1097   PsppireDict *dict = NULL;
1098
1099   GtkWidget *menubar;
1100   GtkWidget *hb ;
1101   GtkWidget *sb ;
1102
1103   GtkWidget *box = gtk_vbox_new (FALSE, 0);
1104   de->builder = builder_new ("data-editor.ui");
1105
1106   menubar = get_widget_assert (de->builder, "menubar");
1107   hb = get_widget_assert (de->builder, "handlebox1");
1108   sb = get_widget_assert (de->builder, "status-bar");
1109
1110   de->data_editor =
1111     PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
1112
1113   g_signal_connect_swapped (the_data_store, "case-changed",
1114                             G_CALLBACK (set_unsaved), de);
1115
1116   g_signal_connect_swapped (the_data_store, "case-inserted",
1117                             G_CALLBACK (set_unsaved), de);
1118
1119   g_signal_connect_swapped (the_data_store, "cases-deleted",
1120                             G_CALLBACK (set_unsaved), de);
1121
1122   dataset_set_callback (the_dataset, set_unsaved, de);
1123
1124   connect_help (de->builder);
1125
1126   gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0);
1127   gtk_box_pack_start (GTK_BOX (box), hb, FALSE, TRUE, 0);
1128   gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (de->data_editor), TRUE, TRUE, 0);
1129   gtk_box_pack_start (GTK_BOX (box), sb, FALSE, TRUE, 0);
1130
1131   gtk_container_add (GTK_CONTAINER (de), box);
1132
1133   set_cut_copy_menuitem_sensitivity (de, FALSE);
1134
1135   g_signal_connect_swapped (de->data_editor, "data-selection-changed",
1136                     G_CALLBACK (set_cut_copy_menuitem_sensitivity), de);
1137
1138
1139   set_paste_menuitem_sensitivity (de, FALSE);
1140
1141   g_signal_connect_swapped (de->data_editor, "data-available-changed",
1142                     G_CALLBACK (set_paste_menuitem_sensitivity), de);
1143
1144   dataset_add_transform_change_callback (the_dataset,
1145                                          transformation_change_callback,
1146                                          de);
1147
1148
1149   vs = the_var_store;
1150
1151   g_assert(vs); /* Traps a possible bug in w32 build */
1152
1153   g_object_get (vs, "dictionary", &dict, NULL);
1154
1155   g_signal_connect (dict, "weight-changed",
1156                     G_CALLBACK (on_weight_change),
1157                     de);
1158
1159   g_signal_connect (dict, "filter-changed",
1160                     G_CALLBACK (on_filter_change),
1161                     de);
1162
1163   g_signal_connect (dict, "split-changed",
1164                     G_CALLBACK (on_split_change),
1165                     de);
1166
1167
1168   g_signal_connect (get_action_assert (de->builder, "edit_copy"),
1169                     "activate",
1170                     G_CALLBACK (on_edit_copy), de);
1171
1172   g_signal_connect (get_action_assert (de->builder, "edit_cut"),
1173                     "activate",
1174                     G_CALLBACK (on_edit_cut), de);
1175
1176
1177
1178   {
1179     GtkWidget *toolbarbutton = get_widget_assert (de->builder, "button-open");
1180
1181     GtkAction *action_data_open =
1182       resolve_action (de->builder, "file_open_data", NULL);
1183
1184     g_object_set (action_data_open,
1185                   "tooltip",  _("Open a data file"),
1186                   "stock-id", "gtk-open",
1187                   NULL);
1188
1189     g_signal_connect (action_data_open, "activate",
1190                       G_CALLBACK (open_data_dialog), de);
1191
1192     g_signal_connect_swapped (toolbarbutton, "clicked",
1193                       G_CALLBACK (gtk_action_activate), action_data_open);
1194   }
1195
1196
1197
1198   {
1199     GtkAction *action_data_new =
1200       resolve_action (de->builder, "file_new_data", NULL);
1201
1202     g_object_set (action_data_new,
1203                   "tooltip", _("New data file"),
1204                   "stock-id", "gtk-new",
1205                   NULL);
1206
1207     g_signal_connect (action_data_new, "activate",
1208                       G_CALLBACK (new_file), de);
1209   }
1210
1211
1212
1213   {
1214     GtkAction *invoke_text_import_assistant =
1215       resolve_action (de->builder, "file_import-text", NULL);
1216
1217     g_object_set (invoke_text_import_assistant,
1218                   "tooltip",  _("Import text data file"),
1219                   "stock-id", "gtk-convert",
1220                   NULL);
1221
1222     g_signal_connect (invoke_text_import_assistant, "activate",
1223                       G_CALLBACK (text_data_import_assistant), de);
1224   }
1225
1226
1227
1228   {
1229     GtkAction *action_data_save =
1230       resolve_action (de->builder, "file_save", "button-save");
1231
1232
1233     g_object_set (action_data_save,
1234                   "tooltip", _("Save data to file"),
1235                   "stock-id", "gtk-save",
1236                   NULL);
1237
1238     g_signal_connect_swapped (action_data_save, "activate",
1239                               G_CALLBACK (data_save), de);
1240   }
1241
1242
1243
1244
1245   {
1246     GtkAction *action_data_save_as =
1247       resolve_action (de->builder, "file_save_as", NULL);
1248
1249     g_object_set (action_data_save_as,
1250                   "label", _("Save As"),
1251                   "tooltip", _("Save data to file"),
1252                   "stock-id", "gtk-save-as",
1253                   NULL);
1254
1255     g_signal_connect_swapped (action_data_save_as, "activate",
1256                       G_CALLBACK (data_save_as_dialog), de);
1257   }
1258
1259
1260   {
1261     GtkAction *action_info_working_file =
1262       resolve_action (de->builder,
1263                       "file_information_working-file", NULL);
1264
1265
1266     g_signal_connect_swapped (action_info_working_file, "activate",
1267                       G_CALLBACK (display_dict), de);
1268   }
1269
1270
1271   {
1272     GtkAction *action_info_external_file =
1273       resolve_action (de->builder,
1274                       "file_information_external-file", NULL);
1275
1276
1277     g_signal_connect_swapped (action_info_external_file, "activate",
1278                       G_CALLBACK (sysfile_info), de);
1279   }
1280
1281
1282
1283   {
1284     GtkAction *value_labels_action =
1285       resolve_action (de->builder,
1286                       "view_value-labels", "togglebutton-value-labels");
1287
1288     g_object_set (value_labels_action,
1289                   "tooltip",  _("Show/hide value labels"),
1290                   "stock-id", "pspp-value-labels",
1291                   NULL);
1292
1293     g_signal_connect (value_labels_action, "toggled",
1294                       G_CALLBACK (toggle_value_labels), de);
1295   }
1296
1297
1298   g_signal_connect (get_action_assert (de->builder, "edit_paste"), "activate",
1299                     G_CALLBACK (on_edit_paste),
1300                     de);
1301
1302   {
1303     de->delete_cases =
1304       resolve_action (de->builder, "edit_clear-cases", NULL);
1305
1306
1307     g_object_set (de->delete_cases,
1308                   "label", _("Clear"),
1309                   "tooltip", _("Delete the cases at the selected position(s)"),
1310                   "stock-id", "gtk-clear",
1311                   NULL);
1312
1313     g_signal_connect_swapped (de->delete_cases, "activate",
1314                               G_CALLBACK (psppire_data_editor_delete_cases),
1315                               de->data_editor);
1316
1317     gtk_action_set_visible (de->delete_cases, FALSE);
1318   }
1319
1320
1321   {
1322     de->delete_variables =
1323       resolve_action (de->builder, "edit_clear-variables", NULL);
1324
1325     g_object_set (de->delete_variables,
1326                   "label", _("Clear"),
1327                   "tooltip", _("Delete the variables at the selected position(s)"),
1328                   "stock-id", "gtk-clear",
1329                   NULL);
1330
1331
1332     g_signal_connect_swapped (de->delete_variables, "activate",
1333                               G_CALLBACK (psppire_data_editor_delete_variables),
1334                               de->data_editor);
1335
1336     gtk_action_set_visible (de->delete_variables, FALSE);
1337   }
1338
1339
1340   de->insert_variable =
1341     resolve_action (de->builder, "edit_insert-variable",
1342                     "button-insert-variable");
1343
1344   g_object_set (de->insert_variable,
1345                 "tooltip", _("Create a new variable at the current position"),
1346                 "stock-id", "pspp-insert-variable",
1347                 NULL);
1348
1349   g_signal_connect (de->insert_variable, "activate",
1350                     G_CALLBACK (on_insert_variable), de->data_editor);
1351
1352
1353
1354
1355
1356   de->insert_case =
1357     resolve_action (de->builder, "edit_insert-case", "button-insert-case");
1358
1359   g_object_set (de->insert_case,
1360                 "tooltip", _("Create a new case at the current position"),
1361                 "stock-id", "pspp-insert-case",
1362                 NULL);
1363
1364   g_signal_connect (de->insert_case, "activate",
1365                     G_CALLBACK (insert_case), de);
1366
1367
1368
1369
1370
1371   de->invoke_goto_dialog =
1372     resolve_action (de->builder, "edit_goto-case", "button-goto-case");
1373
1374
1375   g_object_set (de->invoke_goto_dialog,
1376                 "tooltip", _("Jump to a Case in the Data Sheet"),
1377                 "stock-id", "gtk-jump-to",
1378                 NULL);
1379
1380   g_signal_connect (de->invoke_goto_dialog, "activate",
1381                     G_CALLBACK (goto_case_dialog), de);
1382
1383
1384
1385   {
1386     GtkAction *invoke_weight_cases_dialog =
1387       resolve_action (de->builder, "data_weight-cases", "button-weight-cases");
1388
1389
1390     g_object_set (invoke_weight_cases_dialog,
1391                   "stock-id", "pspp-weight-cases",
1392                   "tooltip", _("Weight cases by variable"),
1393                   NULL);
1394
1395     g_signal_connect (invoke_weight_cases_dialog, "activate",
1396                       G_CALLBACK (weight_cases_dialog), de);
1397   }
1398
1399
1400   {
1401     GtkAction *invoke_transpose_dialog =
1402       resolve_action (de->builder, "data_transpose", NULL);
1403
1404
1405     g_object_set (invoke_transpose_dialog,
1406                   "tooltip", _("Transpose the cases with the variables"),
1407                   "stock-id", "pspp-transpose",
1408                   NULL);
1409
1410     g_signal_connect (invoke_transpose_dialog, "activate",
1411                       G_CALLBACK (transpose_dialog), de);
1412   }
1413
1414
1415   {
1416     GtkAction *invoke_split_file_dialog =
1417       resolve_action (de->builder, "data_split-file", "button-split-file");
1418
1419     g_object_set (invoke_split_file_dialog,
1420                   "tooltip", _("Split the active file"),
1421                   "stock-id", "pspp-split-file",
1422                   NULL);
1423
1424     g_signal_connect (invoke_split_file_dialog, "activate",
1425                       G_CALLBACK (split_file_dialog), de);
1426   }
1427
1428
1429   {
1430     GtkAction *invoke_sort_cases_dialog =
1431       resolve_action (de->builder, "data_sort-cases", NULL);
1432
1433
1434     g_object_set (invoke_sort_cases_dialog,
1435                   "tooltip", _("Sort cases in the active file"),
1436                   "stock-id", "gtk-sort-ascending",
1437                   NULL);
1438
1439     g_signal_connect (invoke_sort_cases_dialog, "activate",
1440                       G_CALLBACK (sort_cases_dialog), de);
1441   }
1442
1443
1444   {
1445     GtkAction *invoke_select_cases_dialog =
1446       resolve_action (de->builder, "data_select-cases", "button-select-cases");
1447
1448     g_object_set (invoke_select_cases_dialog,
1449                   "tooltip", _("Select cases from the active file"),
1450                   "stock-id", "pspp-select-cases",
1451                   NULL);
1452
1453     g_signal_connect (invoke_select_cases_dialog, "activate",
1454                       G_CALLBACK (select_cases_dialog), de);
1455   }
1456
1457
1458   {
1459     GtkAction *invoke_compute_dialog =
1460       resolve_action (de->builder, "transform_compute", NULL);
1461
1462     g_object_set (invoke_compute_dialog,
1463                   "tooltip", _("Compute new values for a variable"),
1464                   "stock-id", "pspp-compute",
1465                   NULL);
1466
1467     g_signal_connect (invoke_compute_dialog, "activate",
1468                       G_CALLBACK (compute_dialog), de);
1469   }
1470
1471
1472   {
1473     GtkAction *invoke_oneway_anova_dialog =
1474       resolve_action (de->builder, "oneway-anova", NULL);
1475
1476     g_object_set (invoke_oneway_anova_dialog,
1477                   "tooltip", _("Perform one way analysis of variance"),
1478                   NULL);
1479
1480     g_signal_connect (invoke_oneway_anova_dialog, "activate",
1481                       G_CALLBACK (oneway_anova_dialog), de);
1482   }
1483
1484
1485   {
1486     GtkAction *invoke_t_test_independent_samples_dialog =
1487       resolve_action (de->builder, "indep-t-test", NULL);
1488
1489
1490     g_object_set (invoke_t_test_independent_samples_dialog,
1491                   "tooltip",
1492                   _("Calculate T Test for samples from independent groups"),
1493                   NULL);
1494
1495     g_signal_connect (invoke_t_test_independent_samples_dialog, "activate",
1496                       G_CALLBACK (t_test_independent_samples_dialog), de);
1497   }
1498
1499
1500   {
1501     GtkAction *invoke_t_test_paired_samples_dialog =
1502       resolve_action (de->builder, "paired-t-test", NULL);
1503
1504     g_object_set (invoke_t_test_paired_samples_dialog,
1505                   "tooltip",
1506                   _("Calculate T Test for paired samples"),
1507                   NULL);
1508
1509     g_signal_connect (invoke_t_test_paired_samples_dialog, "activate",
1510                       G_CALLBACK (t_test_paired_samples_dialog), de);
1511   }
1512
1513
1514   {
1515     GtkAction *invoke_t_test_one_sample_dialog =
1516       resolve_action (de->builder, "one-sample-t-test", NULL);
1517
1518     g_object_set (invoke_t_test_one_sample_dialog,
1519                   "tooltip",
1520                   _("Calculate T Test for sample from a single distribution"),
1521                   NULL);
1522
1523     g_signal_connect (invoke_t_test_one_sample_dialog, "activate",
1524                       G_CALLBACK (t_test_one_sample_dialog), de);
1525   }
1526
1527
1528   {
1529     GtkAction *invoke_comments_dialog =
1530       resolve_action (de->builder, "utilities_comments", NULL);
1531
1532
1533     g_object_set (invoke_comments_dialog,
1534                   "tooltip",
1535                   _("Commentary text for the data file"),
1536                   NULL);
1537
1538     g_signal_connect (invoke_comments_dialog, "activate",
1539                       G_CALLBACK (comments_dialog), de);
1540   }
1541
1542
1543
1544   {
1545     GtkAction *invoke_find_dialog =
1546       resolve_action (de->builder, "edit_find", "button-find");
1547
1548     g_object_set (invoke_find_dialog, "stock-id", "gtk-find", NULL);
1549
1550     g_signal_connect (invoke_find_dialog, "activate",
1551                       G_CALLBACK (find_dialog), de);
1552   }
1553
1554
1555   {
1556     GtkAction *invoke_rank_dialog =
1557       resolve_action (de->builder, "transform_rank", NULL);
1558
1559     g_object_set (invoke_rank_dialog,
1560                   "stock-id", "pspp-rank-cases",
1561                   "tooltip", _("Rank Cases"),
1562                   NULL);
1563
1564     g_signal_connect (invoke_rank_dialog, "activate",
1565                       G_CALLBACK (rank_dialog), de);
1566   }
1567
1568
1569   {
1570     GtkAction *invoke_recode_same_dialog =
1571       resolve_action (de->builder, "transform_recode-same", NULL);
1572
1573     g_object_set (invoke_recode_same_dialog,
1574                   "stock-id", "pspp-recode-same",
1575                   "tooltip", _("Recode values into the same variables"),
1576                   NULL);
1577
1578     g_signal_connect (invoke_recode_same_dialog, "activate",
1579                       G_CALLBACK (recode_same_dialog), de);
1580   }
1581
1582
1583   {
1584     GtkAction *invoke_recode_different_dialog  =
1585       resolve_action (de->builder, "transform_recode-different", NULL);
1586
1587     g_object_set (invoke_recode_different_dialog,
1588                   "stock-id", "pspp-recode-different",
1589                   "tooltip", _("Recode values into different variables"),
1590                   NULL);
1591
1592     g_signal_connect (invoke_recode_different_dialog, "activate",
1593                       G_CALLBACK (recode_different_dialog), de);
1594   }
1595
1596
1597   {
1598     GtkAction *invoke_variable_info_dialog  =
1599       resolve_action (de->builder, "utilities_variables", "button-goto-variable");
1600
1601     g_object_set (invoke_variable_info_dialog,
1602                   "stock-id", "pspp-goto-variable",
1603                   "tooltip", _("Jump to variable"),
1604                   NULL);
1605
1606     g_signal_connect (invoke_variable_info_dialog, "activate",
1607                       G_CALLBACK (variable_info_dialog), de);
1608   }
1609
1610
1611   {
1612     GtkAction *invoke_descriptives_dialog =
1613       resolve_action (de->builder,  "analyze_descriptives", NULL);
1614
1615     g_object_set (invoke_descriptives_dialog,
1616                   "tooltip", _("Calculate descriptive statistics (mean, variance, ...)"),
1617                   "stock-id", "pspp-descriptives",
1618                   NULL);
1619
1620     g_signal_connect (invoke_descriptives_dialog, "activate",
1621                       G_CALLBACK (descriptives_dialog), de);
1622   }
1623
1624
1625   {
1626     GtkAction *invoke_frequencies_dialog =
1627       resolve_action (de->builder,  "analyze_frequencies", NULL);
1628
1629     g_object_set (invoke_frequencies_dialog,
1630                   "tooltip", _("Generate frequency statistics"),
1631                   "stock-id", "pspp-frequencies",
1632                   NULL);
1633
1634     g_signal_connect (invoke_frequencies_dialog, "activate",
1635                       G_CALLBACK (frequencies_dialog), de);
1636   }
1637
1638
1639   {
1640     GtkAction *invoke_crosstabs_dialog =
1641       resolve_action (de->builder, "crosstabs", NULL);
1642
1643     g_object_set (invoke_crosstabs_dialog,
1644                   "tooltip", _("Generate crosstabulations"),
1645                   "stock-id", "pspp-crosstabs",
1646                   NULL);
1647
1648     g_signal_connect (invoke_crosstabs_dialog, "activate",
1649                       G_CALLBACK (crosstabs_dialog), de);
1650   }
1651
1652
1653
1654   {
1655     GtkAction *invoke_examine_dialog =
1656       resolve_action (de->builder, "analyze_explore", NULL);
1657
1658     g_object_set (invoke_examine_dialog,
1659                   "tooltip", _("Examine Data by Factors"),
1660                   "stock-id", "pspp-examine",
1661                   NULL);
1662
1663     g_signal_connect (invoke_examine_dialog, "activate",
1664                       G_CALLBACK (examine_dialog), de);
1665   }
1666
1667
1668   {
1669     GtkAction *invoke_regression_dialog =
1670       resolve_action (de->builder, "linear-regression", NULL);
1671
1672     g_object_set (invoke_regression_dialog,
1673                   "tooltip", _("Estimate parameters of the linear model"),
1674                   "stock-id", "pspp-regression",
1675                   NULL
1676                   );
1677
1678     g_signal_connect (invoke_regression_dialog, "activate",
1679                       G_CALLBACK (regression_dialog), de);
1680   }
1681
1682   {
1683     GtkAction *invoke_reliability_dialog =
1684       resolve_action (de->builder, "reliability", NULL);
1685
1686     g_object_set (invoke_reliability_dialog,
1687                   "tooltip", _("Reliability Analysis"),
1688                   "stock-id", "pspp-reliability",
1689                   NULL
1690                   );
1691
1692     g_signal_connect (invoke_reliability_dialog, "activate",
1693                       G_CALLBACK (reliability_dialog), de);
1694   }
1695
1696
1697   {
1698     GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1699
1700     GtkWidget *recent_data =
1701       gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-data");
1702
1703     GtkWidget *recent_files =
1704       gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
1705
1706
1707     GtkWidget *menu_data =
1708       gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1709
1710     GtkWidget *menu_files =
1711       gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1712
1713     {
1714       GtkRecentFilter *filter = gtk_recent_filter_new ();
1715
1716       gtk_recent_filter_add_pattern (filter, "*.sav");
1717       gtk_recent_filter_add_pattern (filter, "*.SAV");
1718       gtk_recent_filter_add_pattern (filter, "*.por");
1719       gtk_recent_filter_add_pattern (filter, "*.POR");
1720
1721       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);
1722
1723       gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_data), filter);
1724     }
1725
1726     gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu_data);
1727
1728
1729     g_signal_connect (menu_data, "selection-done",
1730                       G_CALLBACK (on_recent_data_select),
1731                       de);
1732
1733     {
1734       GtkRecentFilter *filter = gtk_recent_filter_new ();
1735
1736       gtk_recent_filter_add_pattern (filter, "*.sps");
1737       gtk_recent_filter_add_pattern (filter, "*.SPS");
1738
1739       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_files), GTK_RECENT_SORT_MRU);
1740
1741       gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_files), filter);
1742     }
1743
1744     gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu_files);
1745
1746     g_signal_connect (menu_files, "selection-done",
1747                       G_CALLBACK (on_recent_files_select),
1748                       de);
1749
1750   }
1751
1752   g_signal_connect (get_action_assert (de->builder,"file_new_syntax"),
1753                     "activate",
1754                     G_CALLBACK (create_syntax_window),
1755                     NULL);
1756
1757   g_signal_connect (get_action_assert (de->builder,"file_open_syntax"),
1758                     "activate",
1759                     G_CALLBACK (open_syntax_window),
1760                     de);
1761
1762   {
1763     GtkAction *abt = get_action_assert (de->builder, "help_about");
1764     g_object_set (abt, "stock-id", "gtk-about", NULL);
1765     g_signal_connect (abt,
1766                       "activate",
1767                       G_CALLBACK (about_new),
1768                       de);
1769   }
1770
1771
1772   g_signal_connect (get_action_assert (de->builder,"help_reference"),
1773                     "activate",
1774                     G_CALLBACK (reference_manual),
1775                     de);
1776
1777
1778   g_signal_connect (de->data_editor,
1779                     "cases-selected",
1780                     G_CALLBACK (enable_delete_cases),
1781                     de);
1782
1783   g_signal_connect (de->data_editor,
1784                     "variables-selected",
1785                     G_CALLBACK (enable_delete_variables),
1786                     de);
1787
1788
1789   g_signal_connect (de->data_editor,
1790                     "switch-page",
1791                     G_CALLBACK (on_switch_sheet), de);
1792
1793   gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1794   gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1795
1796   g_signal_connect (get_action_assert (de->builder, "view_statusbar"),
1797                     "activate",
1798                     G_CALLBACK (status_bar_activate), de);
1799
1800
1801   g_signal_connect (get_action_assert (de->builder, "view_gridlines"),
1802                     "activate",
1803                     G_CALLBACK (grid_lines_activate), de);
1804
1805
1806
1807   g_signal_connect (get_action_assert (de->builder, "view_data"),
1808                     "activate",
1809                     G_CALLBACK (data_view_activate), de);
1810
1811   g_signal_connect (get_action_assert (de->builder, "view_variables"),
1812                     "activate",
1813                     G_CALLBACK (variable_view_activate), de);
1814
1815
1816   {
1817     GtkAction *font_action =
1818       resolve_action (de->builder, "view_fonts", NULL);
1819
1820     g_object_set (font_action,
1821                   "stock-id", "gtk-select-font",
1822                   NULL);
1823
1824     g_signal_connect (font_action,
1825                       "activate",
1826                       G_CALLBACK (fonts_activate), de);
1827   }
1828
1829
1830
1831   g_signal_connect (get_action_assert (de->builder, "file_quit"),
1832                     "activate",
1833                     G_CALLBACK (file_quit), de);
1834
1835   g_signal_connect (get_action_assert (de->builder, "transform_run-pending"),
1836                     "activate",
1837                     G_CALLBACK (execute), de);
1838
1839
1840   g_signal_connect (get_action_assert (de->builder, "windows_minimise_all"),
1841                     "activate",
1842                     G_CALLBACK (psppire_window_minimise_all), NULL);
1843
1844
1845   {
1846     GtkAction *split_window_action =
1847       resolve_action (de->builder, "windows_split", NULL);
1848
1849     g_object_set (split_window_action,
1850                   "tooltip", _("Split the window vertically and horizontally"),
1851                   "stock-id", "pspp-split-window",
1852                   NULL);
1853
1854     g_signal_connect (split_window_action, "toggled",
1855                       G_CALLBACK (toggle_split_window),
1856                       de);
1857   }
1858
1859   {
1860     GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1861
1862     PSPPIRE_WINDOW (de)->menu =
1863       GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
1864   }
1865
1866   {
1867     GtkMenu *data_sheet_variable_popup_menu =
1868       GTK_MENU (create_data_sheet_variable_popup_menu (de));
1869
1870     GtkMenu *var_sheet_variable_popup_menu =
1871       GTK_MENU (create_var_sheet_variable_popup_menu (de));
1872
1873     GtkMenu *data_sheet_cases_popup_menu =
1874       GTK_MENU (create_data_sheet_cases_popup_menu (de));
1875
1876     g_object_set (de->data_editor,
1877                   "datasheet-column-menu", data_sheet_variable_popup_menu,
1878                   "datasheet-row-menu", data_sheet_cases_popup_menu,
1879                   "varsheet-row-menu", var_sheet_variable_popup_menu,
1880                   NULL);
1881   }
1882
1883   gtk_widget_show (GTK_WIDGET (de->data_editor));
1884   gtk_widget_show (box);
1885 }
1886
1887
1888 GtkWidget*
1889 psppire_data_window_new (void)
1890 {
1891   return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
1892                                    "description", _("Data Editor"),
1893                                    NULL));
1894 }
1895
1896
1897
1898
1899 \f
1900
1901 static void
1902 psppire_data_window_iface_init (PsppireWindowIface *iface)
1903 {
1904   iface->save = save_file;
1905   iface->load = load_file;
1906 }