From: John Darrington Date: Thu, 10 Nov 2011 20:13:32 +0000 (+0100) Subject: File Open: Don't try to analyse the file if it's a directory. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fbuilds%2F20111111030502%2Fpspp;hp=09648bd73c7511f3c70c941b77f559569edae292;p=pspp File Open: Don't try to analyse the file if it's a directory. The File Open dialog box looks at the contents of the selected file in order to decide whether to set the sensitivity of the encoding selector. But if the file was a directory this caused error messages on windoze. Closes bug #34773 --- diff --git a/src/data/file-name.c b/src/data/file-name.c index 5e4080b11f..9eeb4b1cfc 100644 --- a/src/data/file-name.c +++ b/src/data/file-name.c @@ -128,12 +128,16 @@ fn_is_special (const char *file_name) return false; } -/* Returns true if file with name NAME exists. */ +/* Returns true if file with name NAME exists, and that file is not a + directory */ bool fn_exists (const char *name) { struct stat temp; - return stat (name, &temp) == 0; + if ( stat (name, &temp) != 0 ) + return false; + + return ! S_ISDIR (temp.st_mode); } /* Environment variables. */ diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 598de89302..4eb274b528 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -28,6 +28,7 @@ #define N_(msgid) msgid #include "data/any-reader.h" +#include "data/file-name.h" #include "data/dataset.h" #include "helper.h" @@ -719,6 +720,12 @@ on_selection_changed (GtkFileChooser *chooser, GtkWidget *encoding_selector) sysname = convert_glib_filename_to_system_filename (name, NULL); + if ( ! fn_exists (sysname)) + { + gtk_widget_set_sensitive (encoding_selector, FALSE); + return; + } + gtk_widget_set_sensitive (encoding_selector, ! any_reader_may_open (sysname)); } @@ -788,9 +795,13 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel) { GtkWidget *encoding_selector = psppire_encoding_selector_new ("Auto", true); - gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), encoding_selector); - g_signal_connect (dialog, "selection-changed", G_CALLBACK (on_selection_changed), encoding_selector); + gtk_widget_set_sensitive (encoding_selector, FALSE); + + g_signal_connect (dialog, "selection-changed", G_CALLBACK (on_selection_changed), + encoding_selector); + + gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), encoding_selector); } return dialog;