gpt4 book ai didi

visual-studio-2010 - 将自定义编辑器添加到 Visual Studio 编辑器列表

转载 作者:行者123 更新时间:2023-12-04 14:31:22 25 4
gpt4 key购买 nike

我正在为 Visual Studio 编写自定义编辑器。我已经为新语言实现了一些基本功能,例如语法突出显示,我使用生成的 .vsix 文件成功安装了 tha 包。一切都很好,但是我的自定义编辑器需要能够与不同的文件扩展名相关联。

我错误地认为,因为我安装了编辑器,它会出现在

工具->选项..->文本编辑器->文件扩展名->编辑器列表:

enter image description here

但是它不会出现在那里。所以问题是:如何将自定义编辑器添加到此列表中?

谢谢你的帮助!

最佳答案

好吧,至少我得到了这个问题的风滚草徽章。

经过大量逆向工程后,我找到了解决方案......没有记录......任何地方......

第 1 步:

首先,您需要创建一个带有所有功能的编辑器工厂——MSVS 有一个扩展。

第 2 步:
那么你必须创建这样一个类

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
class ProvideFileExtensionMapping : RegistrationAttribute
{
private readonly string _name, _id, _editorGuid, _package;
private readonly int _sortPriority;

public ProvideFileExtensionMapping(string id, string name, object editorGuid, string package, int sortPriority)
{
_id = id;
_name = name;
if (editorGuid is Type)
{
_editorGuid = ((Type)editorGuid).GUID.ToString("B");
}
else
{
_editorGuid = editorGuid.ToString();
}
_package = package;
_sortPriority = sortPriority;
}

public override void Register(RegistrationContext context)
{
using (Key mappingKey = context.CreateKey("FileExtensionMapping\\" + _id))
{
mappingKey.SetValue("", _name);
mappingKey.SetValue("DisplayName", _name);
mappingKey.SetValue("EditorGuid", _editorGuid);
mappingKey.SetValue("Package", _package);
mappingKey.SetValue("SortPriority", _sortPriority);
}
}

public override void Unregister(RegistrationAttribute.RegistrationContext context)
{
}
}

第 3 步:
然后您需要将此类作为属性添加到您的编辑器工厂(您在步骤 1 中创建):
[ProvideFileExtensionMapping("{E23E32ED-3467-4401-A364-1352666A3502}", "RText Editor", typeof(EditorFactory), GuidList.guidRTextEditorPluginEditorFactoryString, 100)]
public sealed class EditorFactory : IVsEditorFactory, IDisposable{...}

就是这样。您现在应该能够在 Visual Studio 的编辑器列表中看到您的编辑器。

当文件映射正确时,将调用您的编辑器。

希望这篇文章可以为其他人节省很多时间。

关于visual-studio-2010 - 将自定义编辑器添加到 Visual Studio 编辑器列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12902972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com