0

我有主窗口和几个子窗口,我想在用户单击停靠图标时显示主窗口,但如果只有一个,则不将其设为关键窗口(如果没有关键窗口,它将自动成为关键窗口)。

这是当前代码:

if ( fMainWinDelegate ) {
    if (not [NSApp keyWindow]) {
        NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate showWindow]");
        [fMainWinDelegate showWindow];
    }
    else {
        if ([fMainWinDelegate.window isMiniaturized]) {
            NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window deminiaturize:self]");
            [fMainWinDelegate.window deminiaturize:self];
            //this one is not working, it make window also the key window
        }
        else if (not [fMainWinDelegate.window isVisible] && not [fMainWinDelegate.window isMiniaturized]) {
            NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window orderFront:self]");
            [fMainWinDelegate.window orderFront:self];
        }
    }
}
4

1 回答 1

0

我以非常简单的解决方案结束:

if ( fMainWinDelegate ) {
    if (not [NSApp keyWindow]) {
        NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate showWindow]");
        [fMainWinDelegate showWindow];
    }
    else {
        if ([fMainWinDelegate.window isMiniaturized]) {
            NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window deminiaturize:self]");
            // save current key window
            NSWindow *currKey = [NSApp keyWindow];
            [fMainWinDelegate.window deminiaturize:self];
            // restore saved key window
            [currKey makeKeyWindow];
        }
        else if (not [fMainWinDelegate.window isVisible] && not [fMainWinDelegate.window isMiniaturized]) {
            NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window orderFront:self]");
            [fMainWinDelegate.window orderFront:self];
        }
    }
}
于 2012-10-12T16:25:56.453 回答