1

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.

David
  • 14,205
  • 20
  • 97
  • 144

3 Answers3

4

Run it as a modal window instead of as a sheet.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
1

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.

Extra Savoir-Faire
  • 6,026
  • 4
  • 29
  • 47
0

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);
        }
    }
Anni S
  • 1,996
  • 19
  • 28