X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-window.c;h=6e57f5ba21f71acfc42bb97a638329e98321013c;hb=8fc40a26bebdae2b3e8870c42d2baa77680c3d36;hp=00efcb6b93a7126ce08dd31f9f767282075f181c;hpb=b73c7309c2fff2b35f406d8e0e75be3dc3621396;p=pspp diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 00efcb6b93..6e57f5ba21 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -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 @@ -23,14 +23,16 @@ #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" @@ -40,13 +42,17 @@ #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-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" @@ -59,10 +65,12 @@ #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 @@ -334,12 +342,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; @@ -357,25 +386,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 @@ -473,6 +492,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"), @@ -482,16 +502,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 (); @@ -578,7 +597,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)); @@ -750,21 +769,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 ; - - gchar *uri = - gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell)); - - file = g_filename_from_uri (uri, NULL, NULL); + /* 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); - g_free (uri); + se = psppire_syntax_window_new (encoding); - se = psppire_syntax_window_new (); + free (encoding); if ( psppire_window_load (PSPPIRE_WINDOW (se), file) ) gtk_widget_show (se); @@ -775,6 +836,7 @@ on_recent_files_select (GtkMenuShell *menushell, gpointer user_data) } + static void enable_delete_cases (GtkWidget *w, gint case_num, gpointer data) { @@ -1010,15 +1072,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)); @@ -1030,13 +1091,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)); @@ -1049,15 +1110,18 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "roc-curve", G_CALLBACK (roc_dialog)); - connect_action (de, "correlation", G_CALLBACK (correlation_dialog)); - + connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog)); + + connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); + connect_action (de, "factor-analysis", G_CALLBACK (factor_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)); { @@ -1076,13 +1140,14 @@ psppire_data_window_finish_init (PsppireDataWindow *de, GtkWidget *menu_files = gtk_recent_chooser_menu_new_for_manager ( gtk_recent_manager_get_default ()); + 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);