Visual Studio 2010的插件 - 添加上下文菜单编辑器窗口 [英] Visual Studio 2010 Plug-in - Adding a context-menu to the Editor Window

查看:724
本文介绍了Visual Studio 2010的插件 - 添加上下文菜单编辑器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是类似以下问题:的 Visual Studio 2010的插件 - 添加上下文菜单解决方案资源管理,但是我的查询是如何将项目添加到右键菜单项,为JavaScript文件中的代码编辑器窗口

This is similar to the following question: Visual Studio 2010 Plug-in - Adding a context-menu to the Solution Explorer, however my query is how to add the item to the context menu item to the code editor window for JavaScript files.

我试图用一个Visual Studio加载项项目(而不是一个Visual Studio包)添加上下文菜单

I am attempting to add the context menu in with a Visual studio Add-in project (not a Visual studio package).

从上面的链接的代码已经千钧很有帮助。

The code from the above link has been supremely helpful. To summarise, to add an item to the context menu of the Solution Explorer and Project explorer, we do so first by retrieving the items themselves:

CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
CommandBar vsBarProject = cmdBars["Project"];
CommandBar vsBarSolution = cmdBars["Solution"];

和以后,加入他们通过增加现成的项目模板代码加入他们:

And later on, adding them adding them in by augmenting the readily available project template code:

command.AddControl(vsBarProject);
command.AddControl(vsBarSolution);

现在我的查询关于该 cmdBars 元素我要补充的命令,为了我的项目出现的编辑脚本文件

Now my query is regarding which of the cmdBars elements I have to add the command to, in order for my item to appear on the context menu for editing script files

我已经建立了它不是<$ C $上下文菜单上C> cmdBars [代码窗口] 。有没有对所有文件的一个项目,或者我需要添加它为每个编辑器类型(如ASPX,脚本,HTML等)?

I have already established its not cmdBars["Code Window"]. Is there one item for all files, or do I have to add it for each editor type (e.g. ASPX, Script, HTML, etc)?

推荐答案

专门处理的脚本文件(通过联想,JavaScript文件)编辑相关的上下文菜单 cmdBars [脚本上下文]

The context menu associated specifically with editing of Script files (and by association, JavaScript files) is cmdBars["Script Context"]

为了找到这一点,我添加了新的菜单项全部(465)菜单控制在Visual Studio与下面的循环

In order to find this, I added the new menu item to all (465) menu controls in visual studio with the following loop

foreach (CommandBar cc in cmdBars)
{
    if (cc.Index >= 1 && cc.Index <= 465)
    {
        command.AddControl(cmdBars[cc.NameLocal]);
    }
}



我再缩小这种使用鸿沟和征服的技术调整循环的边界

I then narrowed this using a divide and conquer technique by adjusting the bounds of the loop:

    if (cc.Index >= 1 && cc.Index <= 256)
    ...
    if (cc.Index >= 1 && cc.Index <= 128)
    ...
    if (cc.Index >= 64 && cc.Index <= 128)
    ...etc...

直到我终于找到了我要找的东西。

Until I eventually found what I was looking for.

这篇关于Visual Studio 2010的插件 - 添加上下文菜单编辑器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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