在NSStatusItem应用程序中显示NSOpenPanel

时间:2010-12-04 00:06:09

标签: cocoa macos nswindow nsstatusitem

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

感谢。

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

在状态项的IBAction方法中,请将其命名为:

window = [[NSApp currentEvent] window];

然后,您可以将该窗口传递给NSOpenPanel的beginSheetModalForWindow:completionHandler:以便将打开的面板显示为工作表。

您可能会发现状态项本身会在工作表出现时卷曲并消失,但在您关闭工作表时会再次出现。

答案 2 :(得分: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);
        }
    }