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