I would like to add a checkbox to NSOpenPanel, and then query its state when receiving the selected files. How can I do this?
Additionally, it would be desirable to be able to enable or disable the checkbox based on the current file selection.
The complete solution based on the answers of Joshua Nozzi and Mark Alldritt:
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
NSButton *button = [[NSButton alloc] init];
[button setButtonType:NSSwitchButton];
button.title = NSLocalizedString(@"I am a checkbox", @"");
[button sizeToFit];
[openDlg setAccessoryView:button];
openDlg.delegate = self;
[openDlg beginSheetModalForWindow:self.window completionHandler:^(NSInteger result)
{
openDlg.delegate = nil; // TODO: Check if this is necessary
if (result != NSFileHandlingPanelOKButton) return;
BOOL checkboxOn = (((NSButton*)openDlg.accessoryView).state == NSOnState);
// Do something
}];
The NSOpenSavePanelDelegate:
- (void)panelSelectionDidChange:(id)sender {
NSOpenPanel *panel = sender;
NSButton *button = (NSButton*)panel.accessoryView;
// Update button based on panel selection
}
NSOpenPanel is a subclass of NSSavePanel, which has -setAccessoryView:.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With