X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-data-window.c;h=647d073bf993d7cebdf27d45332597492680dd5f;hb=1aa87f10e686eb09df296411d8ebfa28fa151860;hp=3698a7af3f1b5fe1efd6bb59b32f9947a931c997;hpb=c969e0cddd76560ea7020acdc6037fe7b426502f;p=pspp-builds.git diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 3698a7af..647d073b 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -23,12 +23,14 @@ #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/binomial-dialog.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" @@ -41,6 +43,7 @@ #include "ui/gui/help-menu.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" @@ -63,6 +66,8 @@ #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 @@ -152,9 +157,6 @@ psppire_data_window_class_init (PsppireDataWindowClass *class) G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); } - -extern GtkRecentManager *the_recent_mgr; - static void set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x) { @@ -337,12 +339,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 +383,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 @@ -753,21 +766,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); @@ -1033,6 +1088,8 @@ 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)); @@ -1061,6 +1118,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "binomial", G_CALLBACK (binomial_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 +1131,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);