0

我正在尝试使用 Visual Studio 扩展过滤项目元素,我想加载文档可能对其进行编辑(这部分有效),然后在进行了一些修改时显示代码编辑器。

修改部分已在已打开的编辑器上进行了测试,但对于未打开的文件,我无法显示编辑器。我正在使用以下代码:

public class C
{
    // MEF import omitted for clarity.
    private ITextDocumentFactoryService _textDocumentFactory;
    private IFileToContentTypeService _contentAssoc;
    private ITextEditorFactoryService _editorFactory;

    private bool OnDocument(ITextDocument doc) { /* return true if we modified the document */  }

    public void ProcessFile(string path)
    {
        var contentType = _contentAssoc.GetContentTypeForFilePath(path);
        var textDoc = _textDocumentFactory.CreateAndLoadTextDocument(path, contentType);

        if (OnDocument(textDoc))
        {
            var view = _editorFactory.CreateTextView(textDoc.TextBuffer);
            var host = _editorFactory.CreateTextViewHost(view, true); // I don't know if I need it

            // and nothing shows up
        }
    }
}

显然我错过了一些东西,我怎样才能让编辑器出现,或者我应该完全改变工作流程?

4

0 回答 0