FileChooser and filePatternsAllowed


#1

Hi Jules,

    FileChooser myChooser ("Please select the moose you want to load...",
                               File::getSpecialLocation (File::userHomeDirectory),
                               "*.png");

Currently I can give only one extension, in this case “*.png”, it would be good if we could give multiple file extensions.

Any plans of supporting it ?


#2

Yes, eventually!


#3

Any estimate on when we can see it? :slight_smile:


#4

No idea!


#5

Hi jules,
It looks like you already have support for multiple file types option. This worked with both juce 1.50 and juce 1.39.

   juce::FileChooser	JFFFileChooser ( "Open a File",juce::File::nonexistent,"*.jpg,*.gif");
	if ( JFFFileChooser.browseForFileToOpen() )
	{
		
	}


#6

Oh, that’s good then! I don’t remember doing it though… Maybe it’s just something that happens to work on the mac when that comma-separated string gets passed through to the OS file chooser?


#7

You have actually coded for it. :smiley:

void FileChooser::showPlatformDialog (OwnedArray<File>& results,
                                      const String& title,
                                      const File& currentFileOrDirectory,
                                      const String& filter,
                                      bool selectsDirectory,
                                      bool isSaveDialogue,
                                      bool warnAboutOverwritingExistingFiles,
                                      bool selectMultipleFiles,
                                      FilePreviewComponent* extraInfoComponent)
{
    const ScopedAutoReleasePool pool;

    StringArray* filters = new StringArray();
    filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
    filters->trim();
    filters->removeEmptyStrings();

     JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
    [delegate autorelease];
     ....
}

All you need to do is to update the documentation. Pretty sure it will work on pc, will check that later.


#8

Hopefully, this is the end of it. I got it working on both Mac and windows. Final Code.

juce::FileChooser   JFFFileChooser ( "Open a File",juce::File::nonexistent,"*.jpg;*.gif");
   if ( JFFFileChooser.browseForFileToOpen() )
   {
      
   } 

Works on both mac and pc

works on mac, but not on pc.

The only thing am not sure is if it’s default support from the OS or Jules has coded it :wink:. Thanks for prompt replies Jules.


#9

Thanks @vishvesh for pointing out the difference in Win/Mac operation with multiple fileTypes.
It should be noted that the JUCE FileChooser documentation still refers to using a comma or a semicolon for fileType separation, but as I discovered (and found this thread) the comma only seems to work on Mac.