Search code examples
macoscocoansopenpanel

NSOpenPanel - Cmd+A shortcut doesn't work


I created an open file dialog as follows:

NSArray *fileTypes = [self fileTypes];
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.canChooseFiles = canChooseFiles;
panel.canCreateDirectories = canChooseFolders;
panel.allowsMultipleSelection = allowMultiSelection;
panel.allowedFileTypes = fileTypes;
panel.title = dialogTitle;
[panel setReleasedWhenClosed:true];

if ([panel runModal] == NSFileHandlingPanelOKButton)
    urls = [[panel URLs] copy];
else
    urls = nullptr;

It opens fine and selecting multiple files works fine too. However, + A (Select All) shortcut doesn't work. Do I have to enable any other options in our app to make it work?


Solution

  • Key equivalents are actually driven by the main menu bar.

    You have to add a menu item (e.g. named "Select All") with the +A key equivalent. Then you have to link it to the selector 'selectAll:' of First Responder.

    screenshot select all xcode