Using the Apple OS X Cocoa framework, how can I post a sheet (slide-down modal dialog) on the window of another process?
使用Apple OS X Cocoa框架,如何在另一个进程的窗口上发布工作表(向下滑动模式对话框)?
Edit: Clarified a bit:
编辑:澄清一下:
My application is a Finder extension to do Subversion version control (http://scplugin.tigris.org/). Part of my application is a plug-in (a Contextual Menu Item for Finder); the bulk of my application, however, is in a separate daemon proces. For several reasons, we've chosen to put virtually all the code into the daemon; the plug-in only defines the menu itself, and Apple-Events over to the Daemon.
我的应用程序是一个Finder扩展,可以进行Subversion版本控制(http://scplugin.tigris.org/)。我的应用程序的一部分是插件(Finder的上下文菜单项);然而,我的应用程序的大部分是在一个单独的守护进程中。出于几个原因,我们选择将几乎所有代码放入守护进程;插件只定义菜单本身,Apple-Events定义到守护进程。
Sometimes, the daemon needs to prompt the user for further information. It can toss a window on-screen for this, but that's disruptive (randomly positioned), and it seems to me the work flow here is legitimately modal, for example "select a file, pick 'commit' from the menu, provide commit comments, do the operation."
有时,守护进程需要提示用户提供进一步的信息。它可以在屏幕上为此抛出一个窗口,但这是破坏性的(随机定位),在我看来这里的工作流程是合法的模态,例如“从菜单中选择一个文件,选择'提交',提供提交注释,做手术。“
Interprocess cooperation (such as passing a reference of some kind) is acceptable: both processes are mine, but I want to avoid binding the sheet's code into the primary process.
进程间协作(例如传递某种类型的引用)是可以接受的:两个进程都是我的,但我想避免将表单的代码绑定到主进程中。
4 个解决方案
#1
5
Really, it sounds like you're trying to have your inter-process communication happen at the view level, which isn't really how Cocoa generally works. Things will be much easier if you separate your layers a bit more than that.
实际上,听起来你正试图在视图级别进行进程间通信,这实际上并不是Cocoa的工作方式。如果你将你的图层分开多一点,事情会容易得多。
Why don't you want to put the sheet code into the other process? It's view code, and view code is inherently process-specific. The right thing to do here is probably to add somewhat generic modal-sheet support to your plugin code, and an IPC call that your daemon can make to summon that code. Trying to ship view objects over to the remote process is going to be nightmarish if you can make it work at all.
为什么不将表单代码放入其他进程?它是视图代码,视图代码本质上是特定于进程的。在这里做的正确的事情可能是为你的插件代码添加一些通用的模态表支持,以及你的守护进程可以用来召唤代码的IPC调用。试图将视图对象传送到远程进程将是一个噩梦,如果你可以使它工作。
You're fighting the frameworks with this approach.
你正在用这种方法对抗框架。
#2
2
You can't add a sheet to a window in another process, because you have at most only the most restricted access to the windows in the other process.
您无法在另一个进程中向窗口添加工作表,因为在其他进程中最多只能访问窗口。
#3
1
Please don't do this. Make the interaction nonmodal if at all possible. Especially in something like a commit, it's much nicer to be able to browse around your files while you're writing commit comments.
请不要这样做。尽可能使交互非模态化。特别是在提交之类的东西中,在编写提交注释时能够浏览文件会更好。
OS X does have window groups, but I don't think they can (easily) span applications.
OS X确实有窗口组,但我认为它们不能(轻松)跨越应用程序。
#4
1
Another thing to consider is that in OS X it's possible to have many Finder windows open on the same folder (unlike in OS 9). Even if you did have sufficient privileges/APIs to add a sheet to a Finder window, it's not like the modality of that window would prevent the user from being able to continue working with the files.
另一件需要考虑的事情是,在OS X中,可以在同一文件夹上打开许多Finder窗口(与OS 9不同)。即使您确实拥有足够的权限/ API来向Finder窗口添加工作表,但它不像该窗口的模式会阻止用户继续使用这些文件。
(My personal opinion as a long-time Mac user is that this kind of interaction would drive me right up the wall.)
(我个人认为,作为一个长期的Mac用户,这种互动会把我推到墙上。)
#1
5
Really, it sounds like you're trying to have your inter-process communication happen at the view level, which isn't really how Cocoa generally works. Things will be much easier if you separate your layers a bit more than that.
实际上,听起来你正试图在视图级别进行进程间通信,这实际上并不是Cocoa的工作方式。如果你将你的图层分开多一点,事情会容易得多。
Why don't you want to put the sheet code into the other process? It's view code, and view code is inherently process-specific. The right thing to do here is probably to add somewhat generic modal-sheet support to your plugin code, and an IPC call that your daemon can make to summon that code. Trying to ship view objects over to the remote process is going to be nightmarish if you can make it work at all.
为什么不将表单代码放入其他进程?它是视图代码,视图代码本质上是特定于进程的。在这里做的正确的事情可能是为你的插件代码添加一些通用的模态表支持,以及你的守护进程可以用来召唤代码的IPC调用。试图将视图对象传送到远程进程将是一个噩梦,如果你可以使它工作。
You're fighting the frameworks with this approach.
你正在用这种方法对抗框架。
#2
2
You can't add a sheet to a window in another process, because you have at most only the most restricted access to the windows in the other process.
您无法在另一个进程中向窗口添加工作表,因为在其他进程中最多只能访问窗口。
#3
1
Please don't do this. Make the interaction nonmodal if at all possible. Especially in something like a commit, it's much nicer to be able to browse around your files while you're writing commit comments.
请不要这样做。尽可能使交互非模态化。特别是在提交之类的东西中,在编写提交注释时能够浏览文件会更好。
OS X does have window groups, but I don't think they can (easily) span applications.
OS X确实有窗口组,但我认为它们不能(轻松)跨越应用程序。
#4
1
Another thing to consider is that in OS X it's possible to have many Finder windows open on the same folder (unlike in OS 9). Even if you did have sufficient privileges/APIs to add a sheet to a Finder window, it's not like the modality of that window would prevent the user from being able to continue working with the files.
另一件需要考虑的事情是,在OS X中,可以在同一文件夹上打开许多Finder窗口(与OS 9不同)。即使您确实拥有足够的权限/ API来向Finder窗口添加工作表,但它不像该窗口的模式会阻止用户继续使用这些文件。
(My personal opinion as a long-time Mac user is that this kind of interaction would drive me right up the wall.)
(我个人认为,作为一个长期的Mac用户,这种互动会把我推到墙上。)