如何在 Visual Studio 解决方案资源管理器中启用新的自定义上下文菜单项?
当我右键单击文件时,我希望在解决方案资源管理器的上下文菜单中将“File.CopyRelativePath”作为选项。
我正在使用 Visual Studio 2022,
我已成功将命令添加到菜单中: 工具 - 自定义 - 命令 - 上下文菜单 - 项目和解决方案上下文菜单 |项目
在那里我添加了 File.CopyRelativePath 并给了它一个快捷方式。
但是当我在上下文菜单中看到它时,它被禁用了。
如何启用该菜单项以便我可以开始使用它?
I would like to have "File.CopyRelativePath" as an option in the Context Menu of Solution Explorer when I right click a file.
I am using Visual Studio 2022
I have managed to put the command in the menu by adding it at:
Tools - Customize - Commands - Context menu - Project and Solution Context Menus | Item
There I have added File.CopyRelativePath and given it a shortcut too.
But when I see it in the context menu it is disabled.
How do I enable the menu item so I can start using it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TL;DR:您不能强制启用命令处理程序。但是,您可以为此命令(或具有相同标签的全新命令)实现您自己的处理程序。
更多详细信息:
有很多 关于命令如何在 VS 中工作的文档,但快速解释一下:命令处理程序实现一个 Execute 方法来执行操作,并可选地实现一个 QueryStatus 方法来执行操作确定命令当前是否能够执行。在这种情况下,QueryStatus 确定不应启用该命令。
该命令的 QueryStatus 的实现(我查看过)查看当前活动的 WindowFrame,并要求它与打开的文档关联。一旦焦点位于解决方案资源管理器中,它将确定不应启用该命令,因为解决方案资源管理器不是文档窗口。
(类似地,该实现使用仅为文档实例设置的框架属性。它无法理解来自其他类型窗口的输入。)
TL;DR: You can't force the command handler to be enabled. However, you could implement your own handler for this command (or a brand new command with the same label).
More details:
There's a lot of documentation about how commands work in VS, but to quickly paraphrase: command handlers implement an Execute method to do the operation and optionally a QueryStatus method to determine if the command is currently able to execute. In this case, QueryStatus is determining that the command should not be enabled.
The implementation of this command's QueryStatus (I peeked) looks at the currently active WindowFrame, and requires that it be associated with an open document. Once the focus is in Solution Explorer, it would determine that the command should not be enabled as Solution Explorer is not a document window.
(The implementation, similarly, uses properties of the frame that are only set for a document instance. It wouldn't understand an input from another type of window.)