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