3

Using GTK+'s GtkFileChooserDialog, how can I allow the user to select a file or a folder (both are valid here). The actions available are mutually exclusive.

madth3
  • 7,275
  • 12
  • 50
  • 74
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

2 Answers2

5

Unfortunately I don't think this is possible.

I played around with this a bit in the "create a torrent" dialog in Transmission, and wound up using a radibox to enable one of two chooserdialogbuttons, one in file mode and the other in folder mode.

user367660
  • 331
  • 1
  • 2
1

You could add another button. Here is a small example file-chooser window that has a button for "open" which opens files or folders and "select" button for selecting files.

void filechooser(GtkWidget* widget, gpointer gFilepath) {
   // create the dialogue with an "Open" button
   string* filepath = (string*) gFilepath;
   GtkWidget *dialog = gtk_file_chooser_dialog_new(
         "Open File",
         NULL, 
         GTK_FILE_CHOOSER_ACTION_OPEN,
         GTK_STOCK_CANCEL,
         GTK_RESPONSE_CANCEL,
         GTK_STOCK_OPEN,
         GTK_RESPONSE_ACCEPT, NULL);

   // add the additional "Select" button
   const guint MY_SELECTED = 0;
   gtk_dialog_add_button(GTK_DIALOG(dialog), "Select", MY_SELECTED);

   guint response = gtk_dialog_run(GTK_DIALOG(dialog));
   if(response == GTK_RESPONSE_ACCEPT || response == MY_SELECTED){
      *filepath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
   }
   gtk_widget_destroy(dialog);
}