禁止单击 FinderSync 扩展子菜单

发布于 2025-01-16 07:28:05 字数 656 浏览 1 评论 0原文

我正在用 Swift 编写一个 FinderSync 扩展,并创建一个像这样的子菜单:

let menu = NSMenu(title: "")
let newsub = NSMenu();
newsub.addItem(withTitle: "Folder", action: #selector(createFolder(_:)), keyEquivalent: "")
newsub.addItem(withTitle: "Empty File", action: #selector(createEmptyFile(_:)), keyEquivalent: "")
let new = menu.addItem(withTitle: "New", action: nil, keyEquivalent: "")
menu.setSubmenu(newsub, for: new)

一切正常,但有一个非常烦人的怪癖。在我在 MacOS 上测试过的任何其他子菜单中,如果单击子菜单行本身(因此不是其条目之一,而是本例中的“新建”),则不会发生任何情况。但不适用于此子菜单。当您单击子菜单而不是像平常一样立即展开子菜单时,上下文菜单会完全消失,并且会发出咔嗒声,表明没有发生任何事情(就像您按下了无效的热键一样)。

如何防止这种情况发生,并使子菜单不可点击?我尝试禁用它,但这会完全禁用子菜单,而不仅仅是使其不可单击。

I am writing a FinderSync extension in Swift, and am creating a submenu like such:

let menu = NSMenu(title: "")
let newsub = NSMenu();
newsub.addItem(withTitle: "Folder", action: #selector(createFolder(_:)), keyEquivalent: "")
newsub.addItem(withTitle: "Empty File", action: #selector(createEmptyFile(_:)), keyEquivalent: "")
let new = menu.addItem(withTitle: "New", action: nil, keyEquivalent: "")
menu.setSubmenu(newsub, for: new)

Everything works fine but there's one very annoying quirk. In any other submenu I've tested on MacOS, if you click on the submenu line itself (so not one of its entries, but "New" in this example), nothing happens. But not for this submenu. When you click on the submenu instead of instantly expanding the submenu as normal, the context menu disappears entirely, and a clicking noise plays indicating nothing happened (as if you press an invalid hotkey).

How do I prevent this, and make the submenu non-clickable? I've tried disabling it, but that disables the submenu entirely instead of just making it non-clickable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文