(LearnVSXNow又开始继续翻译了,为了提高翻译速度,不再对每句话进行翻译,并且会用自己的理解来代替不好翻译的句子。理解不一定正确,见谅。)
前面那篇文章介绍了Visual Studio的自定义编辑器的基本概念,并用一个例子来说明如何创建自定义编辑器,今天我们继续这个例子。
1. 注册Editor
Editor需要注册到Visual Studio中才能使用。通常会注册下面三个东西:
Editor Factory:告诉Visual Studio我们的package可以提供哪些Editor Factory。
Editor支持的文件扩展名:告诉Visual Studio哪种扩展名的文件会关联到我们的Editor。
Editor的逻辑视图(Logic View):下面的段落中会提到什么是Logic View
// --- Other attributes have been omitted
[ProvideEditorFactory(typeof(BlogItemEditorFactory), 200,
TrustLevel = __VSEDITORTRUSTLEVEL.ETL_AlwaysTrusted)]
[ProvideEditorExtension(typeof(BlogItemEditorFactory),
HowToPackage.BlogFileExtension,
32,
ProjectGuid = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}",
TemplateDir = @"..\..\BlogItemEditor\Templates",
NameResourceID = 200)]
[ProvideEditorLogicalView(typeof(BlogItemEditorFactory),
GuidList.GuidBlogItemEditorLogicalView)]
public sealed class HowToPackage : Package
{
public const string BlogFileExtension = ".blit";
protected override void Initialize()
{
base.Initialize();
// --- Other initialization code
// --- Register the blog item editor
RegisterEditorFactory(new BlogItemEditorFactory());
// --- Other initialization code
}
}