从OSX中基于Cocoa的插件处理主机菜单启用功能 [英] Handling host menu enabledness from Cocoa based plugin in OSX

查看:251
本文介绍了从OSX中基于Cocoa的插件处理主机菜单启用功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名Windows开发人员,为MacOS主机应用程序(Premiere Pro)开发基于Cocoa的插件.在某些时候,主机会阻塞性地调用我的插件回调函数,这时我将显示一个模式对话框,仅在该对话框关闭后才返回.

I'm a Windows developer developing a Cocoa-based plugin for a MacOS host application (Premiere Pro). At certain times, the host blockingly calls into my plugin callback function, at which time I'm supposed to show a modal dialog, only returning once the dialog is dismissed.

我已经设法建立了模式对话框,可以通过以下方式将其很好地作为主机主窗口的父项:

I've already managed to put up the modal dialog, nicely parenting it to the host's main window via:

// Get this from the host
NSWindow* parentWindowHandle = ...;

// Create this one myself, or rather have the Juce framework create it for me
NSWindow* ourWindowHandle = ...;

// Connect the two
[parentWindowHandle addChildWindow:ourWindowHandle ordered:NSWindowAbove];

这很好用;我的对话框始终位于主机的顶部,并且主机的主窗口已禁用.

This works nicely; my dialog is always on top of the host, and the host's main window is disabled.

但是...

此时主机的菜单仍处于活动状态.更糟糕的是,它甚至还具有响应能力,它允许用户在我的模式对话框启动时启动主机功能,最终导致他们的模式在我的旁边打开并出现一定的挂起(永远旋转的沙滩球).

The host's menu is still active at that time. And worse, it is even responsive as well, which allows the user to start host functionality while my modal dialog is up, which ultimately results in their modal open next to mine and a certain hang (forever spinning beachball).

我意识到我很可能会以Windows开发人员和所有人的身份错误地攻击这种方法,但是又可能这只是主机应用程序中的一个疏忽?

I realize it's quite possible I'm attacking this the wrong way being a Windows developer and all, but then again maybe this is just an oversight in the host app?

还有一个几乎可以确定的相关问题,也可能是一个线索:通过键盘进行复制/粘贴仅在插件模式对话框的文本框中不起作用,直到我手动单击主机的编辑"菜单,之后,键盘快捷键粘贴将再次起作用.在主机的整个剩余生命中,即使我的对话被取消而稍后又创建了一个新对话,也是如此.

And an almost certainly related question which might be a clue as well: Copy/Paste via the keyboard just doesn't work in text boxes in my plugin modal dialogs, right until I manually click the host's "Edit" menu open, after which keyboard shortcut pasting works again. For the rest of the host's lifetime no less, even when my dialog gets dismissed and a new one created later on.

编辑

我已尝试将[[NSApplication sharedApplication] runModalForWindow: myDialogWindow]用作链接问题中的广告,但该行恰好在该行上被阻止.似乎合法,因为它应该进入模态循环.但是,我的Cocoa窗口是通过GUI框架(Juce;这是一个多平台项目)为我创建的,因此我无法控制窗口消息的处理方式.所以我想以上方法在我的情况下不可用?

I've tried [[NSApplication sharedApplication] runModalForWindow: myDialogWindow] as advertized in the linked question, but it blocks right on that line. Seems legit, since it should enter a modal loop. However, my Cocoa window is created for me by a GUI framework (Juce; it's a multiplatform project), so I have no control over how the messages for the window are handled. So I guess the above way is unusable in my situation?

推荐答案

在追逐另一个想法时,我偶然发现可可的[NSApp beginModalSessionForWindow][NSApp runModalSession][NSApp endModalSession]结合使用.这是为了在并行模态会话中运行特定窗口,同时还要自己做一些处理(您应该在循环中调用runModalSession).

When chasing another idea I stumbled upon Cocoa's [NSApp beginModalSessionForWindow] in combination with [NSApp runModalSession] and [NSApp endModalSession]. This is meant for running a particular window in a parallel modal session while still doing some processing yourself (you're supposed to call runModalSession in a loop).

但是,由于我的代码结构如下:

However, since my code is structured like:

  1. 让跨平台GUI框架创建我们的NSWindow
  2. 将此NSWindow作为子窗口附加到宿主窗口
  3. 让跨平台GUI框架运行窗口的模态循环
  4. 从宿主窗口中分离我们的窗口
  5. 利润

我可以轻松地潜入

NSModalSession session = [NSApp beginModalSessionForWindow:ourWindow];
[NSApp runModalSession:session];

在上面2到3之间,并添加结束符

between 2 and 3 above, and add the closing

[NSApp endModalSession:session];

3到4之间.

由于beginModalSessionForWindow不会像runModalForWindow那样当场阻塞,因此GUI框架的模态循环仍然可以运行,但确实会导致主机菜单现在无响应.尚未禁用/显示为灰色,但对我而言现在反应迟钝就足够了.

Since beginModalSessionForWindow doesn't block on the spot like runModalForWindow does, the GUI framework's modal loop can still be ran, but it does have the effect that the host's menu is now unresponsive. Not disabled / greyed out, but unresponsive is good enough for me right now.

但是:由于我不是经验丰富的OSX开发人员,所以我想知道是否通过这种方式引入了任何讨厌的东西吗?

However: since I'm far from an experienced OSX developer, I wonder if I introduced any nastyness by doing it this way?

这篇关于从OSX中基于Cocoa的插件处理主机菜单启用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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