簡體   English   中英

在NSStatusItem應用中顯示NSOpenPanel

[英]Show NSOpenPanel in a NSStatusItem app

我正在編寫一個沒有NSWindow的狀態項應用。 我在用戶單擊狀態項時拉起NSOpenPanel。 當應用程序不使用NSWindow時,該怎么辦?

謝謝。

將其作為模式窗口而不是工作表運行。

在狀態項的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);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM