1

我正在编写一个没有 NSWindow 的状态项应用程序。当用户单击状态项时,我会拉出一个 NSOpenPanel。当应用程序不使用 NSWindow 时,如何做到这一点?

谢谢。

4

3 回答 3

4

将其作为模式窗口而不是工作表运行。

于 2010-12-04T00:33:58.800 回答
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.

于 2010-12-04T04:00:56.803 回答
0

您可以简单地从 NSMenuItem 的操作中调用打开的面板:

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);
        }
    }
于 2015-05-05T11:58:50.360 回答