显示模态NSWindow,而不激活其他应用程序窗口 [英] Showing a modal NSWindow, without activating the other application windows

查看:1236
本文介绍了显示模态NSWindow,而不激活其他应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSStatusItem 正确显示在MenuBar。其中一个项目(当点击)显示一个模态NSWindow从我的应用程序,这意味着执行一次性任务,然后消失。 (例如,用户输入一小段文本,点击保存,模式NSWindow消失。)

I have an NSStatusItem that is properly displaying in the MenuBar. One of the items (when clicked) displays a modal NSWindow from my application, which is meant to perform a one-off task, then disappear. (Eg. the user enters a small bit of text, clicks "Save", and the modal NSWindow goes away.)

当应用程序运行在背景。模态窗口适当地出现在任何在前台运行的应用程序之上,但是当用户单击保存按钮时,应用程序的其余窗口也被激活。这是不可取的,因为用户然后必须点击回到他们使用的任何应用程序。 (显示NSStatusItem的方便。)我使用以下方式显示模态窗口:

The issue occurs when the application is running in the background. The modal window properly appears above whatever application is running in the foreground, but when the user clicks the "Save" button, the rest of the application's windows also are made active. This is undesirable, as the user then has to click back to whatever app they were using. (Destroying the convenience of the NSStatusItem.) I'm displaying the modal window using:

[myWindow setFrame:finalRect display:YES animate:NO];
[myWindow setLevel:NSPopUpMenuWindowLevel];
[NSApp runModalForWindow:myWindow];

有没有办法防止我的弹出窗口中的点击/事件导致应用程序的其余部分变得活跃?还是一种方法让NSApp知道这个特定的面板不应该自动激活其余的应用程序?谢谢!

Is there any way to prevent clicks/events in my popup window from causing the rest of the application to become active? Or a way to let NSApp know that this particular panel shouldn't automatically activate the rest of the app? Thanks!

推荐答案

不要创建 NSWindow c $ c> NSPanel 与风格 NSNonactivatingPanelMask 。然后,您可以根据需要使用常用的 makeKeyAndOrderFront: orderOut:显示/隐藏面板。

Instead of creating an NSWindow, create an NSPanel with the style NSNonactivatingPanelMask. You can then do the usual makeKeyAndOrderFront: and orderOut: to show/hide panel as needed.

这篇关于显示模态NSWindow,而不激活其他应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆