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-Tag: v0.7.9~93 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99732245d610cf363429f1b67a8b2b2e15a9a734;p=pspp-builds.git 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 5e4080b1..9eeb4b1c 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 598de893..4eb274b5 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;