VS 2013 SDK:如何开发可通过编辑器上下文菜单访问的扩展?
VS 2013 SDK: How to develop an extension accesible through the editor's contextmenu?
我正在使用 Visual Studio 2013.
Visual Studio Package
项目的项目向导给出了这三个选项:
然而,我假装做的是创建一个非常简单的扩展(它修改了 selected 文本)并且它应该可以通过文本编辑器的上下文菜单中的命令访问,而不是菜单命令既不是工具 window 也不是自定义编辑器(...我认为)。
首先,我应该 select 满足自己需求的项目是什么? (我正在使用菜单命令)。
其次,修改扩展行为以仅将其添加到文本编辑器的上下文菜单中的必要步骤是什么?
private void CreateContextMenu()
{
// Get a reference to the context menu of code windows.
CommandBars commandBars = (CommandBars)applicationObject.CommandBars;
CommandBar codeWindowCommandBar = commandBars["Code Window"];
// Add a popup command bar.
CommandBarControl myCommandBarControl = codeWindowCommandBar.Controls.Add(MsoControlType.msoControlPopup,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
CommandBarPopup myPopup = (CommandBarPopup)myCommandBarControl;
// Change its caption
myPopup.Caption = "My popup";
// Add controls to the popup command bar
CommandBarButton myButton = (CommandBarButton)myPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
myButton.Caption = "Click Me";
myButton.Click += myButton_Click;
}
void myButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("What's up?");
}
我正在使用 Visual Studio 2013.
Visual Studio Package
项目的项目向导给出了这三个选项:
然而,我假装做的是创建一个非常简单的扩展(它修改了 selected 文本)并且它应该可以通过文本编辑器的上下文菜单中的命令访问,而不是菜单命令既不是工具 window 也不是自定义编辑器(...我认为)。
首先,我应该 select 满足自己需求的项目是什么? (我正在使用菜单命令)。
其次,修改扩展行为以仅将其添加到文本编辑器的上下文菜单中的必要步骤是什么?
private void CreateContextMenu()
{
// Get a reference to the context menu of code windows.
CommandBars commandBars = (CommandBars)applicationObject.CommandBars;
CommandBar codeWindowCommandBar = commandBars["Code Window"];
// Add a popup command bar.
CommandBarControl myCommandBarControl = codeWindowCommandBar.Controls.Add(MsoControlType.msoControlPopup,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
CommandBarPopup myPopup = (CommandBarPopup)myCommandBarControl;
// Change its caption
myPopup.Caption = "My popup";
// Add controls to the popup command bar
CommandBarButton myButton = (CommandBarButton)myPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
myButton.Caption = "Click Me";
myButton.Click += myButton_Click;
}
void myButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("What's up?");
}