New abstract class PsppireDialogAction
[pspp-builds.git] / src / ui / gui / psppire-data-window.c
index 3698a7af3f1b5fe1efd6bb59b32f9947a931c997..7d58540425a586ecb77fd1380a22e6c129358fe5 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2010, 2011  Free Software Foundation
+   Copyright (C) 2008, 2009, 2010, 2011, 2012  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "data/session.h"
 #include "language/lexer/lexer.h"
 #include "libpspp/message.h"
+#include "libpspp/str.h"
 #include "ui/gui/aggregate-dialog.h"
+#include "ui/gui/autorecode-dialog.h"
 #include "ui/gui/binomial-dialog.h"
+#include "ui/gui/builder-wrapper.h"
 #include "ui/gui/chi-square-dialog.h"
 #include "ui/gui/comments-dialog.h"
 #include "ui/gui/compute-dialog.h"
 #include "ui/gui/correlation-dialog.h"
+#include "ui/gui/count-dialog.h"
 #include "ui/gui/crosstabs-dialog.h"
-#include "ui/gui/descriptives-dialog.h"
 #include "ui/gui/entry-dialog.h"
 #include "ui/gui/examine-dialog.h"
 #include "ui/gui/executor.h"
 #include "ui/gui/goto-case-dialog.h"
 #include "ui/gui/help-menu.h"
 #include "ui/gui/helper.h"
+#include "ui/gui/helper.h"
+#include "ui/gui/k-means-dialog.h"
 #include "ui/gui/k-related-dialog.h"
+#include "ui/gui/npar-two-sample-related.h"
 #include "ui/gui/oneway-anova-dialog.h"
 #include "ui/gui/psppire-data-window.h"
 #include "ui/gui/psppire-syntax-window.h"
 #include "ui/gui/psppire-window.h"
 #include "ui/gui/psppire.h"
 #include "ui/gui/rank-dialog.h"
+#include "ui/gui/runs-dialog.h"
+#include "ui/gui/ks-one-sample-dialog.h"
 #include "ui/gui/recode-dialog.h"
 #include "ui/gui/regression-dialog.h"
 #include "ui/gui/reliability-dialog.h"
 #include "ui/gui/t-test-paired-samples.h"
 #include "ui/gui/text-data-import-dialog.h"
 #include "ui/gui/transpose-dialog.h"
-#include "ui/gui/variable-info-dialog.h"
+#include "ui/gui/univariate-dialog.h"
 #include "ui/gui/weight-cases-dialog.h"
 #include "ui/syntax-gen.h"
 
+#include "gl/c-strcase.h"
+#include "gl/c-strcasestr.h"
 #include "gl/xvasprintf.h"
 
 #include <gettext.h>
@@ -152,9 +162,6 @@ psppire_data_window_class_init (PsppireDataWindowClass *class)
                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
 }
 \f
-
-extern GtkRecentManager *the_recent_mgr;
-
 static void
 set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
 {
@@ -337,12 +344,33 @@ dump_rm (GtkRecentManager *rm)
 }
 #endif
 
+static gboolean
+name_has_por_suffix (const gchar *name)
+{
+  size_t length = strlen (name);
+  return length > 4 && !c_strcasecmp (&name[length - 4], ".por");
+}
+
+static gboolean
+name_has_sav_suffix (const gchar *name)
+{
+  size_t length = strlen (name);
+  return length > 4 && !c_strcasecmp (&name[length - 4], ".sav");
+}
+
+/* Returns true if NAME has a suffix which might denote a PSPP file */
+static gboolean
+name_has_suffix (const gchar *name)
+{
+  return name_has_por_suffix (name) || name_has_sav_suffix (name);
+}
 
 static gboolean
 load_file (PsppireWindow *de, const gchar *file_name)
 {
-  gchar *utf8_file_name;
   struct string filename;
+  gchar *utf8_file_name;
+  const char *mime_type;
   gchar *syntax;
   bool ok;
 
@@ -360,25 +388,15 @@ load_file (PsppireWindow *de, const gchar *file_name)
   ok = execute_syntax (PSPPIRE_DATA_WINDOW (de),
                        lex_reader_for_string (syntax));
   g_free (syntax);
-  return ok;
-}
 
-/* Returns true if NAME has a suffix which might denote a PSPP file */
-static gboolean
-name_has_suffix (const gchar *name)
-{
-  if ( g_str_has_suffix (name, ".sav"))
-    return TRUE;
-  if ( g_str_has_suffix (name, ".SAV"))
-    return TRUE;
-  if ( g_str_has_suffix (name, ".por"))
-    return TRUE;
-  if ( g_str_has_suffix (name, ".POR"))
-    return TRUE;
-
-  return FALSE;
-}
+  mime_type = (name_has_por_suffix (file_name)
+               ? "application/x-spss-por"
+               : "application/x-spss-sav");
+
+  add_most_recent (file_name, mime_type);
 
+  return ok;
+}
 
 /* Save DE to file */
 static void
@@ -476,6 +494,7 @@ static void
 data_pick_filename (PsppireWindow *window)
 {
   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (window);
+  GtkFileFilter *filter = gtk_file_filter_new ();
   GtkWidget *button_sys;
   GtkWidget *dialog =
     gtk_file_chooser_dialog_new (_("Save"),
@@ -485,16 +504,15 @@ data_pick_filename (PsppireWindow *window)
                                 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                                 NULL);
 
-  GtkFileFilter *filter = gtk_file_filter_new ();
+  g_object_set (dialog, "local-only", FALSE, NULL);
+
   gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
-  gtk_file_filter_add_pattern (filter, "*.sav");
-  gtk_file_filter_add_pattern (filter, "*.SAV");
+  gtk_file_filter_add_mime_type (filter, "application/x-spss-sav");
   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
 
   filter = gtk_file_filter_new ();
   gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
-  gtk_file_filter_add_pattern (filter, "*.por");
-  gtk_file_filter_add_pattern (filter, "*.POR");
+  gtk_file_filter_add_mime_type (filter, "application/x-spss-por");
   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
 
   filter = gtk_file_filter_new ();
@@ -581,7 +599,7 @@ confirm_delete_dataset (PsppireDataWindow *de,
                           GTK_STOCK_DELETE, GTK_RESPONSE_OK,
                           NULL);
 
-  g_object_set (dialog, "icon-name", "psppicon", NULL);
+  g_object_set (dialog, "icon-name", "pspp", NULL);
 
   result = gtk_dialog_run (GTK_DIALOG (dialog));
 
@@ -753,21 +771,63 @@ on_recent_data_select (GtkMenuShell *menushell,
   g_free (file);
 }
 
+static char *
+charset_from_mime_type (const char *mime_type)
+{
+  const char *charset;
+  struct string s;
+  const char *p;
+
+  if (mime_type == NULL)
+    return NULL;
+
+  charset = c_strcasestr (mime_type, "charset=");
+  if (charset == NULL)
+    return NULL;
+
+  ds_init_empty (&s);
+  p = charset + 8;
+  if (*p == '"')
+    {
+      /* Parse a "quoted-string" as defined by RFC 822. */
+      for (p++; *p != '\0' && *p != '"'; p++)
+        {
+          if (*p != '\\')
+            ds_put_byte (&s, *p);
+          else if (*++p != '\0')
+            ds_put_byte (&s, *p);
+        }
+    }
+  else
+    {
+      /* Parse a "token" as defined by RFC 2045. */
+      while (*p > 32 && *p < 127 && strchr ("()<>@,;:\\\"/[]?=", *p) == NULL)
+        ds_put_byte (&s, *p++);
+    }
+  if (!ds_is_empty (&s))
+    return ds_steal_cstr (&s);
+
+  ds_destroy (&s);
+  return NULL;
+}
+
 static void
 on_recent_files_select (GtkMenuShell *menushell,   gpointer user_data)
 {
+  GtkRecentInfo *item;
+  char *encoding;
+  GtkWidget *se;
   gchar *file;
 
-  GtkWidget *se ;
+  /* Get the file name and its encoding. */
+  item = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (menushell));
+  file = g_filename_from_uri (gtk_recent_info_get_uri (item), NULL, NULL);
+  encoding = charset_from_mime_type (gtk_recent_info_get_mime_type (item));
+  gtk_recent_info_unref (item);
 
-  gchar *uri =
-    gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
+  se = psppire_syntax_window_new (encoding);
 
-  file = g_filename_from_uri (uri, NULL, NULL);
-
-  g_free (uri);
-
-  se = psppire_syntax_window_new ();
+  free (encoding);
 
   if ( psppire_window_load (PSPPIRE_WINDOW (se), file) ) 
     gtk_widget_show (se);
@@ -778,6 +838,7 @@ on_recent_files_select (GtkMenuShell *menushell,   gpointer user_data)
 }
 
 
+
 static void
 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
 {
@@ -1013,15 +1074,14 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   connect_action (de, "transform_compute", G_CALLBACK (compute_dialog));
 
+  connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog));
+
   connect_action (de, "edit_find", G_CALLBACK (find_dialog));
 
   connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog));
 
   connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog));
 
-
-  connect_action (de, "utilities_variables", G_CALLBACK (variable_info_dialog));
   connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog));
 
   connect_action (de, "indep-t-test", G_CALLBACK (t_test_independent_samples_dialog));
@@ -1033,13 +1093,13 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
  
   connect_action (de, "transform_rank", G_CALLBACK (rank_dialog));
+
+  connect_action (de, "transform_count", G_CALLBACK (count_dialog));
  
   connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
  
   connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog));
 
-  connect_action (de, "analyze_descriptives", G_CALLBACK (descriptives_dialog));
   connect_action (de, "analyze_frequencies", G_CALLBACK (frequencies_dialog));
  
   connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog));
@@ -1052,15 +1112,22 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
  
   connect_action (de, "roc-curve", G_CALLBACK (roc_dialog));
 
+  connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog));
+
+  connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
+
   connect_action (de, "correlation", G_CALLBACK (correlation_dialog));
  
   connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
 
-  connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
+  connect_action (de, "k-means", G_CALLBACK (k_means_dialog));
 
+  connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
   connect_action (de, "binomial", G_CALLBACK (binomial_dialog));
-
+  connect_action (de, "runs", G_CALLBACK (runs_dialog));
+  connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog));
   connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
+  connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog));
  
 
   {
@@ -1073,19 +1140,20 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
       gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
 
 
-    GtkWidget *menu_data =
-      gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
+    GtkWidget *menu_data = gtk_recent_chooser_menu_new_for_manager (
+      gtk_recent_manager_get_default ());
+
+    GtkWidget *menu_files = gtk_recent_chooser_menu_new_for_manager (
+      gtk_recent_manager_get_default ());
 
-    GtkWidget *menu_files =
-      gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
+    g_object_set (menu_data, "show-tips",  TRUE, NULL);
+    g_object_set (menu_files, "show-tips",  TRUE, NULL);
 
     {
       GtkRecentFilter *filter = gtk_recent_filter_new ();
 
-      gtk_recent_filter_add_pattern (filter, "*.sav");
-      gtk_recent_filter_add_pattern (filter, "*.SAV");
-      gtk_recent_filter_add_pattern (filter, "*.por");
-      gtk_recent_filter_add_pattern (filter, "*.POR");
+      gtk_recent_filter_add_mime_type (filter, "application/x-spss-sav");
+      gtk_recent_filter_add_mime_type (filter, "application/x-spss-por");
 
       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);