110,534
社区成员
发帖
与我相关
我的任务
分享
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object[] contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
string menuName = "Code Window";
//获取右键菜单的命令组。
CommandBar contextCommandBar = ((CommandBars)_applicationObject.CommandBars)[menuName];
try
{
//将一个命令添加到 Commands 集合:
Command command = commands.AddNamedCommand2(_addInInstance, "DoWithConfirm", "排序代码(带确认)", "显示一个排序窗口,供手动排序",
true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//将对应于该命令的控件添加到“工具”菜单:
if ((command != null) && (contextCommandBar != null))
{
command.AddControl(contextCommandBar, 1);
}
}
catch (System.ArgumentException)
{
//如果出现此异常,原因很可能是由于具有该名称的命令
// 已存在。如果确实如此,则无需重新创建此命令,并且
// 可以放心忽略此异常。
}
try
{
Command command = commands.AddNamedCommand2(_addInInstance, "DoWithoutConfirm", "排序代码", "不显示排序窗口,直接按设置的规则排序",
true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//将对应于该命令的控件添加到“工具”菜单:
if ((command != null) && (contextCommandBar != null))
{
command.AddControl(contextCommandBar, 1);
}
}
catch (System.ArgumentException)
{ }
}
}
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if (commandName == "AutoPropertyAddin.Connect.DoWithConfirm")
{
//处理事件
handled = true;
return;
}
if (commandName == "AutoPropertyAddin.Connect.DoWithoutConfirm")
{
//处理事件
handled = true;
return;
}
}
}
if(poWatchContextMenu == null)
{
_CommandBars commandBars = Application.CommandBars;
CommandBar vsBarProject = Application.CommandBars["Code Window"];
poWatchContextMenu = vsBarProject.Controls.Add(MsoControlType.msoControlButton, 1, "", 1, true);
poWatchContextMenu.Caption = "My Watch";
poWatchContextMenu.TooltipText = "";
CommandBarEvents menuItemHandler = (CommandBarEvents)Application.DTE.Events.get_CommandBarEvents(poWatchContextMenu);
menuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(Watch_Click);
}