File Open dialog: disable encoding selector when not applicable
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 3 Sep 2011 12:14:50 +0000 (14:14 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 3 Sep 2011 12:14:50 +0000 (14:14 +0200)
src/ui/gui/psppire-window.c

index f6cdb7b24368f5686832569799a3beb522ec05a7..598de8930246591389a5dbdae3da7cd49e76d3e0 100644 (file)
@@ -706,6 +706,22 @@ psppire_window_load (PsppireWindow *w, const gchar *file)
   return ok;
 }
 
+
+static void
+on_selection_changed (GtkFileChooser *chooser, GtkWidget *encoding_selector)
+{
+  const gchar *sysname;
+
+  const gchar *name = gtk_file_chooser_get_filename (chooser);
+
+  if ( NULL == name )
+    return;
+
+  sysname = convert_glib_filename_to_system_filename (name, NULL);
+
+  gtk_widget_set_sensitive (encoding_selector, ! any_reader_may_open (sysname));
+}
+
 GtkWidget *
 psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
 {
@@ -769,8 +785,13 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
       free (dir_name);
     }
 
-  gtk_file_chooser_set_extra_widget (
-    GTK_FILE_CHOOSER (dialog), psppire_encoding_selector_new ("Auto", true));
+
+  {
+    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);
+  }
 
   return dialog;
 }