如何制作运行 VSIX 方法的快捷方式? [英] How to make a shortcut to run a VSIX method?
本文介绍了如何制作运行 VSIX 方法的快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参阅这个问题.
最初的问题解决了,我的扩展中有一个方法.我希望当用户安装扩展程序时,也应该安装一个键盘快捷键,并且应该在按下时运行该方法.
The initial question was solved, and I have a method in my extension. I want that when the user installs the extension, a keyboard-shortcut should be installed as well, and should run the method when pressed.
我该怎么做?
推荐答案
您可以向 .vsct 文件添加快捷方式.当您生成一个新扩展并说它将有一个菜单命令时,该文件会在向导中自动创建.手动添加:
You can add shortcuts to the .vsct file. This file is created automatically in the wizard when you generate a new extension and say it will have a menu command. To add it manually:
- 创建 MyCommands.vsct
- 将文件属性设置为 VSCTCompile
- 卸载您的项目,右键单击并编辑项目:
<VSCTCompile Include="MyCommands.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
<SubType>Designer</SubType>
</VSCTCompile>
- 声明您的项目将具有菜单和快捷方式:
[ProvideMenuResource("Menus.ctmenu",1)]
public sealed class MyPackage : Package
- 添加一个键绑定部分:
<KeyBindings>
<KeyBinding guid="yourCmdSet" id="cmdAwesome"
editor="guidVSStd97"
key1="VK_F7" mod1="Control Alt"
key2="VK_F1">
</KeyBinding>
</KeyBindings>
- 在您的 Package.Initialize 中:
// Add our command handlers for menu/shortcut (commands must exist in the .vsct file)
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null != mcs)
{
//// Create the command for the menu item.
var menuCommandID = new CommandID(GuidList.yourCmdSet,(int)PkgCmdIDList.cmdAwesome);
var menuItem = new MenuCommand((sender, evt) =>
{
// Do stuff
}
}
更多资源:
- http://dotneteers.net/blogs/divedeeper/archive/2008/04/17/LearnVSXNowPart18A.aspx
- http://msdn.microsoft.com/de-de/library/bb165138(v=vs.90).aspx
- http://dotneteers.net/blogs/divedeeper/archive/2008/02/22/LearnVSXNowPart13.aspx
这篇关于如何制作运行 VSIX 方法的快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文