为只能作为键盘快捷键使用的命令添加Visual Studio工具栏按钮 [英] Adding a Visual Studio toolbar button for a command that is only available as a keyboard shortcut

查看:116
本文介绍了为只能作为键盘快捷键使用的命令添加Visual Studio工具栏按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与 ReSharper YouTrack问题有关.

在安装了ReSharper 7.1.1的Visual Studio 2010中,如果转到工具">选项">环境">键盘",则有一个名为ReSharper_SilentCleanupCode的命令.

In Visual Studio 2010 with ReSharper 7.1.1 installed, if I go to Tools > Options > Environment > Keyboard, there is a command called ReSharper_SilentCleanupCode.

我想将此命令绑定到工具栏按钮上.

I would like to bind this command to a toolbar button.

使用工具">定制">命令"似乎是不可能的,因为此对话框中唯一可用的命令用于已经具有关联菜单项的操作.我感兴趣的特定ReSharper命令(静默代码清除")没有出现在任何菜单中,因此无法使用"GUI"将其分配给工具栏按钮.

This seems to be impossible using Tools > Customize > Commands because the only commands available within this dialog are for actions that already have an associated menu item. The particular ReSharper command I'm interested in (Silent Code Cleanup) doesn't appear in any menu, so it cannot be assigned to a toolbar button using the "GUI".

还有其他方法可以将仅键盘命令绑定到工具栏按钮吗? (ReSharper的一位程序员以为可以使用"VS脚本编辑器",但我没有运气找到相关信息.)

Is there any other way to bind a keyboard-only command to a toolbar button? (One of ReSharper's programmers thought the "VS script editor" could be used, but I'm not having any luck finding info on this.)

修改

我应该首先提到这一点.尽管azhrei的宏解决方案非常适合Visual Studio 2010,但由于我不再支持宏,因此一旦升级到VS 2012,它就会失效.如果有人有可以在VS 2012中继续使用的解决方案,那将是更好的选择. (或者,VS 2012工具栏最初没有相同的限制吗?)

I should have mentioned this in the first place. While azhrei's macro solution is great for Visual Studio 2010, it will break once I upgrade to VS 2012, because macros are no longer supported. If someone has a solution that will continue to work in VS 2012, that would be preferable. (Or perhaps VS 2012 toolbars don't have the same limitation in the first place?)

推荐答案

添加一个执行命令的宏,然后将该宏添加到工具栏.

Add a macro that executes the command, then add the macro to a toolbar.

之所以起作用,是因为它使仅键盘"命令出现在自定义命令"对话框的宏"菜单中.

This works because it makes the keyboard-only command appear in the Macros menu in the Customize Commands dialog.

详细信息

Details

添加执行此操作的宏:

    Sub _ReSharper_SilentCleanupCode()
        DTE.ExecuteCommand("ReSharper_SilentCleanupCode")
    End Sub

将此宏放在出现在 Customize..Commands..AddCommand..Categories..Macros 中的模块中,例如 Samples MyMacros.RecordingModule ,但不是 MyMacros.Module1 (使用宏IDE时的默认设置).

Put this macro in a module which appears in Customize..Commands..AddCommand..Categories..Macros, such as Samples or MyMacros.RecordingModule, but not MyMacros.Module1 (the default when using the macro IDE).

转到Tools..Customize..Command并选择所需的Toolbar.

现在Add Command...并选择Macros类别.

选择您的Macros.Samples._ReSharper_SilentCleanupCode宏.

单击Modify Selection并将名称更改为#-)或任何使您认为 ReSharper静默代码清除的文本,对于您的工具栏来说都不会太长. :-)

Click Modify Selection and change the name to #-) or whatever text makes you think ReSharper Silent Code Cleanup without being too long for your toolbar. :-)

我在Visual Studio 2010和ReSharper 7.1.2中进行了尝试.

I tried this with Visual Studio 2010 and ReSharper 7.1.2.

编辑

Edit

Visual Commander显然也是在VS2012上进行此操作的一种方法-有关更多信息,请参见下面的评论.

Visual Commander is a apparently way to get this going on VS2012 as well - see comments below for more.

这篇关于为只能作为键盘快捷键使用的命令添加Visual Studio工具栏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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