我在寫一個沒有NSWindow的狀態項應用程序。我在用戶點擊狀態項時拉起一個NSOpenPanel。當應用程序不使用NSWindow時,如何做到這一點?在NSStatusItem應用程序中顯示NSOpenPanel
謝謝。
我在寫一個沒有NSWindow的狀態項應用程序。我在用戶點擊狀態項時拉起一個NSOpenPanel。當應用程序不使用NSWindow時,如何做到這一點?在NSStatusItem應用程序中顯示NSOpenPanel
謝謝。
將其作爲模式窗口而不是作爲工作表運行。
在你的狀態項的IBAction爲方法,稱之爲:
window = [[NSApp currentEvent] window];
然後,您可以通過該窗口NSOpenPanel的beginSheetModalForWindow:completionHandler:爲了顯示開啓面板如紙。
您可能會發現狀態項本身會捲曲並隨着工作表出現消失,但當您關閉工作表時它會再次出現。
您可以簡單地從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);
}
}
完美,這正是我需要的。 – David 2010-12-04 07:13:07