我正在编写一个没有 NSWindow 的状态项应用程序。当用户单击状态项时,我会拉出一个 NSOpenPanel。当应用程序不使用 NSWindow 时,如何做到这一点?
谢谢。
我正在编写一个没有 NSWindow 的状态项应用程序。当用户单击状态项时,我会拉出一个 NSOpenPanel。当应用程序不使用 NSWindow 时,如何做到这一点?
谢谢。
将其作为模式窗口而不是工作表运行。
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.
您可以简单地从 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);
}
}