deminiaturize NSWindow without making it key

感情迁移 提交于 2019-12-23 04:58:16

问题


I have main window and several child windows, i would like to show main window when user click on dock icon, but without making it a key window, if there just was one (it will become automatically key if there is no key window).

Here is current code:

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];
        }
    }
}

回答1:


I've ended with pretty simple solution:

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];
        }
    }
}


来源:https://stackoverflow.com/questions/12843616/deminiaturize-nswindow-without-making-it-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!