Resolved (Cocoa) File (open) dialog hiding extensions in searches

Discussion in 'Mac Programming' started by 0002378, Aug 12, 2017.

  1. 0002378 Suspended


    May 28, 2017
    My app uses a file dialog (i.e. NSOpenPanel) to allow the user to choose audio files such as mp3's.

    Now, the open panel works just fine when browsing through files normally, i.e. it displays all mp3 files and allows them to be selected.

    However, if, the search bar within the dialog is used to search for songs, and the results are files that have ID3 metadata (artist/title), then, the dialog's search results hide the file extension. This is a problem because I'm no longer able to select a perfectly valid mp3 file just because it has ID3 metadata and the dialog is hiding its extension in the search view. Please see image below.


    This is a bad user experience, because, if the user has a large collection of songs, he/she will definitely use the search feature within the dialog when choosing files, and, if most of his/her songs have ID3 tags, those files' extensions will be hidden, thus preventing the user from selecting those files in the search results.

    I checked the behavior of other audio apps like Vox, iTunes, and VLC. Vox has identical behavior to my app, because it filters the allowed file types to audio file types. However, iTunes and VLC allow any kind of files to be chosen, so they get around this problem. However, allowing all file types is a really ugly workaround. I would, ideally, like to be able to filter my allowed file types (by extension), and yet allow the user to select files in search results.

    I checked all properties of NSOpenPanel to see if I can tweak the behavior. But, I didn't see anything of help.

    Please help. Thank you.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Please post your code. In particular, the allowed types, and any delegate.

    If you don't have a delegate, please see this:

    func panel(Any, shouldEnable: URL)

    For NSOpenPanel delegates, asks the delegate whether the specified URL should be enabled in the panel. This method is not called for NSSavePanel delegates; all URLs are always disabled.​

    Without running an experiment, I can't say whether a panel delegate is applied to search results.

    Finally, the circled item in your screenshot doesn't appear to have an extension. Other items with longer names show a ".mp3" extension, but the circled item doesn't, despite having a shorter name and thus plenty of display space to show an extension. Since other files with extensions do actually show those extensions, I'm not so sure the problem is that the search isn't showing extensions. To me, it looks more like the dimmed file lacks an extension.
  3. 0002378, Aug 12, 2017
    Last edited: Aug 12, 2017

    0002378 thread starter Suspended


    May 28, 2017
    Thanks, chown. I tried specifying a delegate and implementing shouldEnable(url). It didn't work. But I've found a proper solution to this, after all !

    I was only specifying file extensions before - e.g. "mp3". It didn't work because the search was hiding the file extension because the track had an ID3 artist/title. So, instead of showing up as "01 - Hydropoetry Cathedra.mp3", it was showing up as "Aural Planet - Hydropoetry Cathedra" (i.e. Artist - Title), omitting the extension altogether.

    I am now specifying file type UTIs. i.e.AVFileTypeMPEGLayer3, instead of just the extension, so that the dialog can detect the intrinsic type of the file without needing to check its extension. Works like a charm !

    Thanks for your help.

    // Old code
    static let supportedFileTypes_open: [String] = ["mp3", "m4a", "aac", "aif", "aiff",
    "aifc,", "wav", "m3u", "m3u8"]
    // New code
    static let supportedFileTypes_open: [String] = ["mp3", "m4a", "aac", "aif", "aiff",
    "aifc,", "wav", "m3u", "m3u8", AVFileTypeMPEGLayer3, AVFileTypeAIFC,
    AVFileTypeAIFF, AVFileTypeAppleM4A, AVFileTypeWAVE]
    // Unchanged code
    openDialog.allowedFileTypes  = supportedFileTypes_open

Share This Page