注册自定义语言服务扩展时,Visual Studio会在Text Editor
节点(在Visual Studio选项对话框中)中为该语言创建新的选项条目。在该节点下面创建了两个名为General
和Tabs
的默认节点,其中General
选项卡包含语句完成和显示设置......
在Dispay
组中有三种选择;其中一个是Navigation Bar
复选框(显示/隐藏编辑器的导航栏)。对于我的自定义语言服务,此选项已禁用。当然,它还没有实现。
我想知道,我必须做什么,为我的自定义编辑器提供一个导航栏...我想我必须在编辑器工厂或语言服务中实现某个界面包必须导出某个MEF组件,或者,或......
答案 0 :(得分:2)
OnSynchronizeDropdowns
方法(在这种情况下SDK文档是错误的)。最后的技巧是至少覆盖GetComboAttributes
,GetEntryAttributes
和GetEntryText
以获取两个组合框的纯文本项目......
[ComVisible(true)]
public sealed class CustomTypeAndMemberDropdownBars : TypeAndMemberDropdownBars
{
private readonly IList<string> declarations;
private readonly IList<string> members;
public CustomTypeAndMemberDropdownBars(
LanguageService languageService,
IVsTextView view)
: base(languageService)
{
// TODO: initialize declarations and members from the given text view...
this.declarations = ...
this.members = ...
}
private enum ComboIndex
{
Types = 0,
Members = 1
}
public override int GetComboAttributes(
int combo,
out uint entries,
out uint entryType,
out IntPtr imageList)
{
entries = 0;
imageList = IntPtr.Zero;
entryType = (uint)DROPDOWNENTRYTYPE.ENTRY_TEXT;
var comboType = (ComboIndex)combo;
switch (comboType)
{
case ComboIndex.Types:
entries = (uint)this.declarations.Count();
break;
case ComboIndex.Members:
entries = (uint)this.members.Count();
break;
}
return VSConstants.S_OK;
}
public override int GetEntryAttributes(
int combo,
int entry,
out uint fontAttrs)
{
fontAttrs = (uint)DROPDOWNFONTATTR.FONTATTR_PLAIN;
return VSConstants.S_OK;
}
public override int GetEntryText(
int combo,
int entry,
out string text)
{
text = null;
var comboType = (ComboIndex)combo;
switch (comboType)
{
case ComboIndex.Types:
text = this.declarations[entry];
break;
case ComboIndex.Members:
text = this.members[entry];
break;
}
return VSConstants.S_OK;
}
public override bool OnSynchronizeDropdowns(
LanguageService languageService,
IVsTextView textView,
int line,
int col,
ArrayList dropDownTypes,
ArrayList dropDownMembers,
ref int selectedType,
ref int selectedMember)
{
return false;
}
}
答案 1 :(得分:1)
我相信以下步骤应该是您所需要的:
Package
班级中,在ShowDropDownOptions
属性ProvideLanguageService
属性设置为true
TypeAndMemberDropdownBars
LanguageService
课程中,实施CreateDropDownHelper
功能并让其返回TypeAndMemberDropdownBars