dict: Make dict_clone_var(), dict_clone_var_assert() not rename variables.
[pspp] / 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   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
553   psppire_data_editor_insert_variable (de);
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 static GtkAction *
1089 resolve_action (GtkBuilder *builder, const gchar *action, const gchar *proxy)
1090 {
1091   GtkWidget *pr = NULL;
1092   GtkAction *act = get_action_assert (builder, action);
1093   g_assert (GTK_IS_ACTION (act));
1094
1095   if ( proxy )
1096     pr = get_widget_assert (builder, proxy);
1097
1098   if ( pr )
1099     gtk_action_connect_proxy (act, pr);
1100
1101   return act;
1102 }
1103
1104
1105 static void
1106 set_unsaved (gpointer w)
1107 {
1108   psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
1109 }
1110
1111 static void
1112 psppire_data_window_init (PsppireDataWindow *de)
1113 {
1114   PsppireVarStore *vs;
1115   PsppireDict *dict = NULL;
1116
1117   GtkWidget *menubar;
1118   GtkWidget *hb ;
1119   GtkWidget *sb ;
1120
1121   GtkWidget *box = gtk_vbox_new (FALSE, 0);
1122   de->builder = builder_new ("data-editor.ui");
1123
1124   menubar = get_widget_assert (de->builder, "menubar");
1125   hb = get_widget_assert (de->builder, "handlebox1");
1126   sb = get_widget_assert (de->builder, "status-bar");
1127
1128   de->data_editor =
1129     PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
1130
1131   g_signal_connect_swapped (the_data_store, "case-changed",
1132                             G_CALLBACK (set_unsaved), de);
1133
1134   g_signal_connect_swapped (the_data_store, "case-inserted",
1135                             G_CALLBACK (set_unsaved), de);
1136
1137   g_signal_connect_swapped (the_data_store, "cases-deleted",
1138                             G_CALLBACK (set_unsaved), de);
1139
1140   dataset_set_callback (the_dataset, set_unsaved, de);
1141
1142   connect_help (de->builder);
1143
1144   gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0);
1145   gtk_box_pack_start (GTK_BOX (box), hb, FALSE, TRUE, 0);
1146   gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (de->data_editor), TRUE, TRUE, 0);
1147   gtk_box_pack_start (GTK_BOX (box), sb, FALSE, TRUE, 0);
1148
1149   gtk_container_add (GTK_CONTAINER (de), box);
1150
1151   set_cut_copy_menuitem_sensitivity (de, FALSE);
1152
1153   g_signal_connect_swapped (de->data_editor, "data-selection-changed",
1154                     G_CALLBACK (set_cut_copy_menuitem_sensitivity), de);
1155
1156
1157   set_paste_menuitem_sensitivity (de, FALSE);
1158
1159   g_signal_connect_swapped (de->data_editor, "data-available-changed",
1160                     G_CALLBACK (set_paste_menuitem_sensitivity), de);
1161
1162   dataset_add_transform_change_callback (the_dataset,
1163                                          transformation_change_callback,
1164                                          de);
1165
1166
1167   vs = the_var_store;
1168
1169   g_assert(vs); /* Traps a possible bug in w32 build */
1170
1171   g_object_get (vs, "dictionary", &dict, NULL);
1172
1173   g_signal_connect (dict, "weight-changed",
1174                     G_CALLBACK (on_weight_change),
1175                     de);
1176
1177   g_signal_connect (dict, "filter-changed",
1178                     G_CALLBACK (on_filter_change),
1179                     de);
1180
1181   g_signal_connect (dict, "split-changed",
1182                     G_CALLBACK (on_split_change),
1183                     de);
1184
1185
1186   g_signal_connect (get_action_assert (de->builder, "edit_copy"),
1187                     "activate",
1188                     G_CALLBACK (on_edit_copy), de);
1189
1190   g_signal_connect (get_action_assert (de->builder, "edit_cut"),
1191                     "activate",
1192                     G_CALLBACK (on_edit_cut), de);
1193
1194
1195
1196   {
1197     GtkWidget *toolbarbutton = get_widget_assert (de->builder, "button-open");
1198
1199     GtkAction *action_data_open =
1200       resolve_action (de->builder, "file_open", NULL);
1201
1202     g_object_set (action_data_open,
1203                   "tooltip",  _("Open a data or syntax file"),
1204                   "stock-id", "gtk-open",
1205                   NULL);
1206
1207     g_signal_connect (action_data_open, "activate",
1208                       G_CALLBACK (open_window), de);
1209
1210     g_signal_connect_swapped (toolbarbutton, "clicked",
1211                       G_CALLBACK (gtk_action_activate), action_data_open);
1212   }
1213
1214
1215
1216   {
1217     GtkAction *action_data_new =
1218       resolve_action (de->builder, "file_new_data", NULL);
1219
1220     g_object_set (action_data_new,
1221                   "tooltip", _("New data file"),
1222                   "stock-id", "gtk-new",
1223                   NULL);
1224
1225     g_signal_connect (action_data_new, "activate",
1226                       G_CALLBACK (new_file), de);
1227   }
1228
1229
1230
1231   {
1232     GtkAction *invoke_text_import_assistant =
1233       resolve_action (de->builder, "file_import-text", NULL);
1234
1235     g_object_set (invoke_text_import_assistant,
1236                   "tooltip",  _("Import text data file"),
1237                   "stock-id", "gtk-convert",
1238                   NULL);
1239
1240     g_signal_connect (invoke_text_import_assistant, "activate",
1241                       G_CALLBACK (text_data_import_assistant), de);
1242   }
1243
1244
1245
1246   {
1247     GtkAction *action_data_save =
1248       resolve_action (de->builder, "file_save", "button-save");
1249
1250
1251     g_object_set (action_data_save,
1252                   "tooltip", _("Save data to file"),
1253                   "stock-id", "gtk-save",
1254                   NULL);
1255
1256     g_signal_connect_swapped (action_data_save, "activate",
1257                               G_CALLBACK (data_save), de);
1258   }
1259
1260
1261
1262
1263   {
1264     GtkAction *action_data_save_as =
1265       resolve_action (de->builder, "file_save_as", NULL);
1266
1267     g_object_set (action_data_save_as,
1268                   "tooltip", _("Save data to file"),
1269                   "stock-id", "gtk-save-as",
1270                   NULL);
1271
1272     g_signal_connect_swapped (action_data_save_as, "activate",
1273                       G_CALLBACK (data_save_as_dialog), de);
1274   }
1275
1276
1277   {
1278     GtkAction *action_info_working_file =
1279       resolve_action (de->builder,
1280                       "file_information_working-file", NULL);
1281
1282
1283     g_signal_connect_swapped (action_info_working_file, "activate",
1284                       G_CALLBACK (display_dict), de);
1285   }
1286
1287
1288   {
1289     GtkAction *action_info_external_file =
1290       resolve_action (de->builder,
1291                       "file_information_external-file", NULL);
1292
1293
1294     g_signal_connect_swapped (action_info_external_file, "activate",
1295                       G_CALLBACK (sysfile_info), de);
1296   }
1297
1298
1299
1300   {
1301     GtkAction *value_labels_action =
1302       resolve_action (de->builder,
1303                       "view_value-labels", "togglebutton-value-labels");
1304
1305     g_object_set (value_labels_action,
1306                   "tooltip",  _("Show/hide value labels"),
1307                   "stock-id", "pspp-value-labels",
1308                   NULL);
1309
1310     g_signal_connect (value_labels_action, "toggled",
1311                       G_CALLBACK (toggle_value_labels), de);
1312   }
1313
1314
1315   g_signal_connect (get_action_assert (de->builder, "edit_paste"), "activate",
1316                     G_CALLBACK (on_edit_paste),
1317                     de);
1318
1319   {
1320     de->delete_cases =
1321       resolve_action (de->builder, "edit_clear-cases", NULL);
1322
1323
1324     g_object_set (de->delete_cases,
1325                   "label", _("Clear"),
1326                   "tooltip", _("Delete the cases at the selected position(s)"),
1327                   "stock-id", "gtk-clear",
1328                   NULL);
1329
1330     g_signal_connect_swapped (de->delete_cases, "activate",
1331                               G_CALLBACK (psppire_data_editor_delete_cases),
1332                               de->data_editor);
1333
1334     gtk_action_set_visible (de->delete_cases, FALSE);
1335   }
1336
1337
1338   {
1339     de->delete_variables =
1340       resolve_action (de->builder, "edit_clear-variables", NULL);
1341
1342     g_object_set (de->delete_variables,
1343                   "label", _("Clear"),
1344                   "tooltip", _("Delete the variables at the selected position(s)"),
1345                   "stock-id", "gtk-clear",
1346                   NULL);
1347
1348
1349     g_signal_connect_swapped (de->delete_variables, "activate",
1350                               G_CALLBACK (psppire_data_editor_delete_variables),
1351                               de->data_editor);
1352
1353     gtk_action_set_visible (de->delete_variables, FALSE);
1354   }
1355
1356
1357   de->insert_variable =
1358     resolve_action (de->builder, "edit_insert-variable",
1359                     "button-insert-variable");
1360
1361   g_object_set (de->insert_variable,
1362                 "tooltip", _("Create a new variable at the current position"),
1363                 "stock-id", "pspp-insert-variable",
1364                 NULL);
1365
1366   g_signal_connect (de->insert_variable, "activate",
1367                     G_CALLBACK (on_insert_variable), de->data_editor);
1368
1369
1370
1371
1372
1373   de->insert_case =
1374     resolve_action (de->builder, "edit_insert-case", "button-insert-case");
1375
1376   g_object_set (de->insert_case,
1377                 "tooltip", _("Create a new case at the current position"),
1378                 "stock-id", "pspp-insert-case",
1379                 NULL);
1380
1381   g_signal_connect (de->insert_case, "activate",
1382                     G_CALLBACK (insert_case), de);
1383
1384
1385
1386
1387
1388   de->invoke_goto_dialog =
1389     resolve_action (de->builder, "edit_goto-case", "button-goto-case");
1390
1391
1392   g_object_set (de->invoke_goto_dialog,
1393                 "tooltip", _("Jump to a Case in the Data Sheet"),
1394                 "stock-id", "gtk-jump-to",
1395                 NULL);
1396
1397   g_signal_connect (de->invoke_goto_dialog, "activate",
1398                     G_CALLBACK (goto_case_dialog), de);
1399
1400
1401
1402   {
1403     GtkAction *invoke_weight_cases_dialog =
1404       resolve_action (de->builder, "data_weight-cases", "button-weight-cases");
1405
1406
1407     g_object_set (invoke_weight_cases_dialog,
1408                   "stock-id", "pspp-weight-cases",
1409                   "tooltip", _("Weight cases by variable"),
1410                   NULL);
1411
1412     g_signal_connect (invoke_weight_cases_dialog, "activate",
1413                       G_CALLBACK (weight_cases_dialog), de);
1414   }
1415
1416
1417   {
1418     GtkAction *invoke_transpose_dialog =
1419       resolve_action (de->builder, "data_transpose", NULL);
1420
1421
1422     g_object_set (invoke_transpose_dialog,
1423                   "tooltip", _("Transpose the cases with the variables"),
1424                   "stock-id", "pspp-transpose",
1425                   NULL);
1426
1427     g_signal_connect (invoke_transpose_dialog, "activate",
1428                       G_CALLBACK (transpose_dialog), de);
1429   }
1430
1431
1432   {
1433     GtkAction *invoke_split_file_dialog =
1434       resolve_action (de->builder, "data_split-file", "button-split-file");
1435
1436     g_object_set (invoke_split_file_dialog,
1437                   "tooltip", _("Split the active file"),
1438                   "stock-id", "pspp-split-file",
1439                   NULL);
1440
1441     g_signal_connect (invoke_split_file_dialog, "activate",
1442                       G_CALLBACK (split_file_dialog), de);
1443   }
1444
1445
1446   {
1447     GtkAction *invoke_sort_cases_dialog =
1448       resolve_action (de->builder, "data_sort-cases", NULL);
1449
1450
1451     g_object_set (invoke_sort_cases_dialog,
1452                   "tooltip", _("Sort cases in the active file"),
1453                   "stock-id", "gtk-sort-ascending",
1454                   NULL);
1455
1456     g_signal_connect (invoke_sort_cases_dialog, "activate",
1457                       G_CALLBACK (sort_cases_dialog), de);
1458   }
1459
1460
1461   {
1462     GtkAction *invoke_select_cases_dialog =
1463       resolve_action (de->builder, "data_select-cases", "button-select-cases");
1464
1465     g_object_set (invoke_select_cases_dialog,
1466                   "tooltip", _("Select cases from the active file"),
1467                   "stock-id", "pspp-select-cases",
1468                   NULL);
1469
1470     g_signal_connect (invoke_select_cases_dialog, "activate",
1471                       G_CALLBACK (select_cases_dialog), de);
1472   }
1473
1474
1475   {
1476     GtkAction *invoke_compute_dialog =
1477       resolve_action (de->builder, "transform_compute", NULL);
1478
1479     g_object_set (invoke_compute_dialog,
1480                   "tooltip", _("Compute new values for a variable"),
1481                   "stock-id", "pspp-compute",
1482                   NULL);
1483
1484     g_signal_connect (invoke_compute_dialog, "activate",
1485                       G_CALLBACK (compute_dialog), de);
1486   }
1487
1488
1489   {
1490     GtkAction *invoke_oneway_anova_dialog =
1491       resolve_action (de->builder, "oneway-anova", NULL);
1492
1493     g_object_set (invoke_oneway_anova_dialog,
1494                   "tooltip", _("Perform one way analysis of variance"),
1495                   NULL);
1496
1497     g_signal_connect (invoke_oneway_anova_dialog, "activate",
1498                       G_CALLBACK (oneway_anova_dialog), de);
1499   }
1500
1501
1502   {
1503     GtkAction *invoke_t_test_independent_samples_dialog =
1504       resolve_action (de->builder, "indep-t-test", NULL);
1505
1506
1507     g_object_set (invoke_t_test_independent_samples_dialog,
1508                   "tooltip",
1509                   _("Calculate T Test for samples from independent groups"),
1510                   NULL);
1511
1512     g_signal_connect (invoke_t_test_independent_samples_dialog, "activate",
1513                       G_CALLBACK (t_test_independent_samples_dialog), de);
1514   }
1515
1516
1517   {
1518     GtkAction *invoke_t_test_paired_samples_dialog =
1519       resolve_action (de->builder, "paired-t-test", NULL);
1520
1521     g_object_set (invoke_t_test_paired_samples_dialog,
1522                   "tooltip",
1523                   _("Calculate T Test for paired samples"),
1524                   NULL);
1525
1526     g_signal_connect (invoke_t_test_paired_samples_dialog, "activate",
1527                       G_CALLBACK (t_test_paired_samples_dialog), de);
1528   }
1529
1530
1531   {
1532     GtkAction *invoke_t_test_one_sample_dialog =
1533       resolve_action (de->builder, "one-sample-t-test", NULL);
1534
1535     g_object_set (invoke_t_test_one_sample_dialog,
1536                   "tooltip",
1537                   _("Calculate T Test for sample from a single distribution"),
1538                   NULL);
1539
1540     g_signal_connect (invoke_t_test_one_sample_dialog, "activate",
1541                       G_CALLBACK (t_test_one_sample_dialog), de);
1542   }
1543
1544
1545   {
1546     GtkAction *invoke_comments_dialog =
1547       resolve_action (de->builder, "utilities_comments", NULL);
1548
1549
1550     g_object_set (invoke_comments_dialog,
1551                   "tooltip",
1552                   _("Commentary text for the data file"),
1553                   NULL);
1554
1555     g_signal_connect (invoke_comments_dialog, "activate",
1556                       G_CALLBACK (comments_dialog), de);
1557   }
1558
1559
1560
1561   {
1562     GtkAction *invoke_find_dialog =
1563       resolve_action (de->builder, "edit_find", "button-find");
1564
1565     g_object_set (invoke_find_dialog, "stock-id", "gtk-find", NULL);
1566
1567     g_signal_connect (invoke_find_dialog, "activate",
1568                       G_CALLBACK (find_dialog), de);
1569   }
1570
1571
1572   {
1573     GtkAction *invoke_rank_dialog =
1574       resolve_action (de->builder, "transform_rank", NULL);
1575
1576     g_object_set (invoke_rank_dialog,
1577                   "stock-id", "pspp-rank-cases",
1578                   "tooltip", _("Rank Cases"),
1579                   NULL);
1580
1581     g_signal_connect (invoke_rank_dialog, "activate",
1582                       G_CALLBACK (rank_dialog), de);
1583   }
1584
1585
1586   {
1587     GtkAction *invoke_recode_same_dialog =
1588       resolve_action (de->builder, "transform_recode-same", NULL);
1589
1590     g_object_set (invoke_recode_same_dialog,
1591                   "stock-id", "pspp-recode-same",
1592                   "tooltip", _("Recode values into the same variables"),
1593                   NULL);
1594
1595     g_signal_connect (invoke_recode_same_dialog, "activate",
1596                       G_CALLBACK (recode_same_dialog), de);
1597   }
1598
1599
1600   {
1601     GtkAction *invoke_recode_different_dialog  =
1602       resolve_action (de->builder, "transform_recode-different", NULL);
1603
1604     g_object_set (invoke_recode_different_dialog,
1605                   "stock-id", "pspp-recode-different",
1606                   "tooltip", _("Recode values into different variables"),
1607                   NULL);
1608
1609     g_signal_connect (invoke_recode_different_dialog, "activate",
1610                       G_CALLBACK (recode_different_dialog), de);
1611   }
1612
1613
1614   {
1615     GtkAction *invoke_variable_info_dialog  =
1616       resolve_action (de->builder, "utilities_variables", "button-goto-variable");
1617
1618     g_object_set (invoke_variable_info_dialog,
1619                   "stock-id", "pspp-goto-variable",
1620                   "tooltip", _("Jump to variable"),
1621                   NULL);
1622
1623     g_signal_connect (invoke_variable_info_dialog, "activate",
1624                       G_CALLBACK (variable_info_dialog), de);
1625   }
1626
1627
1628   {
1629     GtkAction *invoke_descriptives_dialog =
1630       resolve_action (de->builder,  "analyze_descriptives", NULL);
1631
1632     g_object_set (invoke_descriptives_dialog,
1633                   "tooltip", _("Calculate descriptive statistics (mean, variance, ...)"),
1634                   "stock-id", "pspp-descriptives",
1635                   NULL);
1636
1637     g_signal_connect (invoke_descriptives_dialog, "activate",
1638                       G_CALLBACK (descriptives_dialog), de);
1639   }
1640
1641
1642   {
1643     GtkAction *invoke_frequencies_dialog =
1644       resolve_action (de->builder,  "analyze_frequencies", NULL);
1645
1646     g_object_set (invoke_frequencies_dialog,
1647                   "tooltip", _("Generate frequency statistics"),
1648                   "stock-id", "pspp-frequencies",
1649                   NULL);
1650
1651     g_signal_connect (invoke_frequencies_dialog, "activate",
1652                       G_CALLBACK (frequencies_dialog), de);
1653   }
1654
1655
1656   {
1657     GtkAction *invoke_crosstabs_dialog =
1658       resolve_action (de->builder, "crosstabs", NULL);
1659
1660     g_object_set (invoke_crosstabs_dialog,
1661                   "tooltip", _("Generate crosstabulations"),
1662                   "stock-id", "pspp-crosstabs",
1663                   NULL);
1664
1665     g_signal_connect (invoke_crosstabs_dialog, "activate",
1666                       G_CALLBACK (crosstabs_dialog), de);
1667   }
1668
1669
1670
1671   {
1672     GtkAction *invoke_examine_dialog =
1673       resolve_action (de->builder, "analyze_explore", NULL);
1674
1675     g_object_set (invoke_examine_dialog,
1676                   "tooltip", _("Examine Data by Factors"),
1677                   "stock-id", "pspp-examine",
1678                   NULL);
1679
1680     g_signal_connect (invoke_examine_dialog, "activate",
1681                       G_CALLBACK (examine_dialog), de);
1682   }
1683
1684
1685   {
1686     GtkAction *invoke_regression_dialog =
1687       resolve_action (de->builder, "linear-regression", NULL);
1688
1689     g_object_set (invoke_regression_dialog,
1690                   "tooltip", _("Estimate parameters of the linear model"),
1691                   "stock-id", "pspp-regression",
1692                   NULL
1693                   );
1694
1695     g_signal_connect (invoke_regression_dialog, "activate",
1696                       G_CALLBACK (regression_dialog), de);
1697   }
1698
1699   {
1700     GtkAction *invoke_reliability_dialog =
1701       resolve_action (de->builder, "reliability", NULL);
1702
1703     g_object_set (invoke_reliability_dialog,
1704                   "tooltip", _("Reliability Analysis"),
1705                   "stock-id", "pspp-reliability",
1706                   NULL
1707                   );
1708
1709     g_signal_connect (invoke_reliability_dialog, "activate",
1710                       G_CALLBACK (reliability_dialog), de);
1711   }
1712
1713   {
1714     GtkAction *invoke_roc_dialog =
1715       resolve_action (de->builder, "roc-curve", NULL);
1716
1717     g_object_set (invoke_roc_dialog,
1718                   "tooltip", _("ROC Curve"),
1719                   "stock-id", "pspp-roc",
1720                   NULL
1721                   );
1722
1723     g_signal_connect (invoke_roc_dialog, "activate",
1724                       G_CALLBACK (roc_dialog), de);
1725   }
1726
1727   {
1728     GtkAction *invoke_correlation_dialog =
1729       resolve_action (de->builder, "correlation", NULL);
1730
1731     g_object_set (invoke_correlation_dialog,
1732                   "tooltip", _("Bivariate Correlation"),
1733                   "stock-id", "pspp-correlation",
1734                   NULL
1735                   );
1736
1737     g_signal_connect (invoke_correlation_dialog, "activate",
1738                       G_CALLBACK (correlation_dialog), de);
1739   }
1740
1741   {
1742     GtkAction *invoke_factor_dialog =
1743       resolve_action (de->builder, "factor-analysis", NULL);
1744
1745     g_object_set (invoke_factor_dialog,
1746                   "tooltip", _("Principal Axis Factoring and Principal Components Analysis"),
1747                   "stock-id", "pspp-factor",
1748                   NULL
1749                   );
1750
1751     g_signal_connect (invoke_factor_dialog, "activate",
1752                       G_CALLBACK (factor_dialog), de);
1753   }
1754
1755
1756   {
1757     GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1758
1759     GtkWidget *recent_data =
1760       gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-data");
1761
1762     GtkWidget *recent_files =
1763       gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
1764
1765
1766     GtkWidget *menu_data =
1767       gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1768
1769     GtkWidget *menu_files =
1770       gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
1771
1772     {
1773       GtkRecentFilter *filter = gtk_recent_filter_new ();
1774
1775       gtk_recent_filter_add_pattern (filter, "*.sav");
1776       gtk_recent_filter_add_pattern (filter, "*.SAV");
1777       gtk_recent_filter_add_pattern (filter, "*.por");
1778       gtk_recent_filter_add_pattern (filter, "*.POR");
1779
1780       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);
1781
1782       gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_data), filter);
1783     }
1784
1785     gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu_data);
1786
1787
1788     g_signal_connect (menu_data, "selection-done",
1789                       G_CALLBACK (on_recent_data_select),
1790                       de);
1791
1792     {
1793       GtkRecentFilter *filter = gtk_recent_filter_new ();
1794
1795       gtk_recent_filter_add_pattern (filter, "*.sps");
1796       gtk_recent_filter_add_pattern (filter, "*.SPS");
1797
1798       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_files), GTK_RECENT_SORT_MRU);
1799
1800       gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_files), filter);
1801     }
1802
1803     gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu_files);
1804
1805     g_signal_connect (menu_files, "selection-done",
1806                       G_CALLBACK (on_recent_files_select),
1807                       de);
1808
1809   }
1810
1811   g_signal_connect (get_action_assert (de->builder,"file_new_syntax"),
1812                     "activate",
1813                     G_CALLBACK (create_syntax_window),
1814                     NULL);
1815
1816
1817   {
1818     GtkAction *abt = get_action_assert (de->builder, "help_about");
1819     g_object_set (abt, "stock-id", "gtk-about", NULL);
1820     g_signal_connect (abt,
1821                       "activate",
1822                       G_CALLBACK (about_new),
1823                       de);
1824   }
1825
1826
1827   g_signal_connect (get_action_assert (de->builder,"help_reference"),
1828                     "activate",
1829                     G_CALLBACK (reference_manual),
1830                     de);
1831
1832
1833   g_signal_connect (de->data_editor,
1834                     "cases-selected",
1835                     G_CALLBACK (enable_delete_cases),
1836                     de);
1837
1838   g_signal_connect (de->data_editor,
1839                     "variables-selected",
1840                     G_CALLBACK (enable_delete_variables),
1841                     de);
1842
1843
1844   g_signal_connect (de->data_editor,
1845                     "switch-page",
1846                     G_CALLBACK (on_switch_sheet), de);
1847
1848   gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
1849   gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
1850
1851   g_signal_connect (get_action_assert (de->builder, "view_statusbar"),
1852                     "activate",
1853                     G_CALLBACK (status_bar_activate), de);
1854
1855
1856   g_signal_connect (get_action_assert (de->builder, "view_gridlines"),
1857                     "activate",
1858                     G_CALLBACK (grid_lines_activate), de);
1859
1860
1861
1862   g_signal_connect (get_action_assert (de->builder, "view_data"),
1863                     "activate",
1864                     G_CALLBACK (data_view_activate), de);
1865
1866   g_signal_connect (get_action_assert (de->builder, "view_variables"),
1867                     "activate",
1868                     G_CALLBACK (variable_view_activate), de);
1869
1870
1871   {
1872     GtkAction *font_action =
1873       resolve_action (de->builder, "view_fonts", NULL);
1874
1875     g_object_set (font_action,
1876                   "stock-id", "gtk-select-font",
1877                   NULL);
1878
1879     g_signal_connect (font_action,
1880                       "activate",
1881                       G_CALLBACK (fonts_activate), de);
1882   }
1883
1884
1885
1886   g_signal_connect (get_action_assert (de->builder, "file_quit"),
1887                     "activate",
1888                     G_CALLBACK (file_quit), de);
1889
1890   g_signal_connect (get_action_assert (de->builder, "transform_run-pending"),
1891                     "activate",
1892                     G_CALLBACK (execute), de);
1893
1894
1895   g_signal_connect (get_action_assert (de->builder, "windows_minimise_all"),
1896                     "activate",
1897                     G_CALLBACK (psppire_window_minimise_all), NULL);
1898
1899
1900   {
1901     GtkAction *split_window_action =
1902       resolve_action (de->builder, "windows_split", NULL);
1903
1904     g_object_set (split_window_action,
1905                   "tooltip", _("Split the window vertically and horizontally"),
1906                   "stock-id", "pspp-split-window",
1907                   NULL);
1908
1909     g_signal_connect (split_window_action, "toggled",
1910                       G_CALLBACK (toggle_split_window),
1911                       de);
1912   }
1913
1914   {
1915     GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
1916
1917     PSPPIRE_WINDOW (de)->menu =
1918       GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
1919   }
1920
1921   {
1922     GtkMenu *data_sheet_variable_popup_menu =
1923       GTK_MENU (create_data_sheet_variable_popup_menu (de));
1924
1925     GtkMenu *var_sheet_variable_popup_menu =
1926       GTK_MENU (create_var_sheet_variable_popup_menu (de));
1927
1928     GtkMenu *data_sheet_cases_popup_menu =
1929       GTK_MENU (create_data_sheet_cases_popup_menu (de));
1930
1931     g_object_set (de->data_editor,
1932                   "datasheet-column-menu", data_sheet_variable_popup_menu,
1933                   "datasheet-row-menu", data_sheet_cases_popup_menu,
1934                   "varsheet-row-menu", var_sheet_variable_popup_menu,
1935                   NULL);
1936   }
1937
1938   gtk_widget_show (GTK_WIDGET (de->data_editor));
1939   gtk_widget_show (box);
1940 }
1941
1942
1943 GtkWidget*
1944 psppire_data_window_new (void)
1945 {
1946   return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
1947                                    "description", _("Data Editor"),
1948                                    NULL));
1949 }
1950
1951
1952
1953
1954 \f
1955
1956 static void
1957 psppire_data_window_iface_init (PsppireWindowIface *iface)
1958 {
1959   iface->save = save_file;
1960   iface->load = load_file;
1961 }