CNewFileSelector ignoring type on OSX

Hello,

I’m building a file selector using this code:

loadFileSelector = CNewFileSelector::create(getFrame(), CNewFileSelector::kSelectFile);
    
if (loadFileSelector)
{
	loadFileSelector->setDefaultExtension(CFileExtension("JSON file", "json"));
	loadFileSelector->setTitle("Choose a sound bank file...");
	loadFileSelector->run(this);
	loadFileSelector->forget();
}

When the select file dialog appears on OSX (I’m testing it on 10.10, building for 10.7 target), I keep seeing all the files as selectable, while I was expecting to see only the file with the extension specified (“json” in this case) as selectable and the rest greyed out.

I did some debugging on macfileselector.mm and this block of code is getting executed:

	
if (openPanel)
{
#if MAC_COCOA
	if (parentWindow)
	{
		setupInitalDir ();
		openPanel.allowedFileTypes = typesArray;
		remember ();
		[openPanel beginSheetModalForWindow:parentWindow completionHandler:^(NSInteger result) {
			openPanelDidEnd (openPanel, result);
			forget ();
		}];
	}
	
	...

Everything looks fine, I see the typesArray correctly containing the “json” string, but I’m still able to select all the files from the dialog window…
Am I missing something? Everything works as expected on Windows…

Thanks in advance,
Federico

Hi Federico,
have you tried to add the UTI to the file extension ?

CFileExtension("JSON file", "json", "application/json", 0, "public.json")

Cheers,
Arne

Same result, I can still select any type of file :frowning:

Can you post a screenshot of the file selector ? I’m not sure if what you see is just the way it works on macOS.

Here you go.
As you can see, all the files are selectable, regardless of the file type.
I’d like to filter out non-“json” files in order to help the user, like in Windows.

OK, this indeed looks wrong. Did you check another host, just to make sure that it is not Reaper causing this ?
Other than that I’ve no clue, I’m using the file selector successfully in many projects.

Cheers,
Arne

Damn, it works correctly in Logic and GarageBand… :angry:
Thanks for the tip, Arne!