Page 1 of 1

CNewFileSelector ignoring type on OSX

Posted: Mon Dec 18, 2017 10:57 pm
by f.berti
Hello,

I'm building a file selector using this code:

Code: Select all

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:

Code: Select all

	
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

Re: CNewFileSelector ignoring type on OSX

Posted: Tue Dec 19, 2017 10:02 am
by Arne Scheffler
Hi Federico,
have you tried to add the UTI to the file extension ?

Code: Select all

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

Re: CNewFileSelector ignoring type on OSX

Posted: Tue Dec 19, 2017 8:24 pm
by f.berti
Arne Scheffler wrote:Hi Federico,
have you tried to add the UTI to the file extension ?

Code: Select all

CFileExtension("JSON file", "json", "application/json", 0, "public.json")
Cheers,
Arne
Same result, I can still select any type of file :(

Re: CNewFileSelector ignoring type on OSX

Posted: Wed Dec 20, 2017 12:08 pm
by Arne Scheffler
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.

Re: CNewFileSelector ignoring type on OSX

Posted: Wed Dec 20, 2017 9:54 pm
by f.berti
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.

Re: CNewFileSelector ignoring type on OSX

Posted: Thu Dec 21, 2017 7:55 am
by Arne Scheffler
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

Re: CNewFileSelector ignoring type on OSX

Posted: Thu Dec 21, 2017 9:41 pm
by f.berti
Arne Scheffler wrote:OK, this indeed looks wrong. Did you check another host, just to make sure that it is not Reaper causing this ?
Damn, it works correctly in Logic and GarageBand... :x
Thanks for the tip, Arne!