Reputation: 14414
I am writing a status item app that does not have an NSWindow. I to pull up an NSOpenPanel when the user clicks on the status item. How would one do this when the app does not utilize an NSWindow?
Thanks.
Upvotes: 1
Views: 562
Reputation: 2026
You can simply call your open panel from NSMenuItem's action as:
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:YES];
[panel setCanChooseDirectories:YES];
NSUInteger result = [panel runModal];
NSMutableArray *paths = [NSMutableArray array];
if(result == NSFileHandlingPanelOKButton) {
for (NSURL *url in [panel URLs]) {
NSLog(@"%@", url);
}
}
Upvotes: 0
Reputation: 6036
In your status item's IBAction method, call this:
window = [[NSApp currentEvent] window];
You can then pass that window to NSOpenPanel's beginSheetModalForWindow:completionHandler: in order to display the open panel as a sheet.
You may find that the status item itself curls up and disappears as the sheet appears, but it reappears when you dismiss the sheet.
Upvotes: 1