如何找到属于itextView的文档的文件名?

发布于 2025-01-18 01:30:37 字数 1006 浏览 3 评论 0原文

我目前正在编写视觉工作室扩展名,并已实现函数 textViewCreated 在实现itextViewCreationListener接口的类中。

使用itextView参数来调用该函数,该参数表示刚刚创建的编辑器窗口的内容。但是,我不仅需要对已编辑的文档的竞争,还需要其代表的文件的路径,而itextView对象显然没有获得该信息的方法。

到目前为止,我已经使用了dte2.ActivedOcument 属性,但它并不总是正常工作。尤其是如果一个人在Visual Studio中打开一个新的文本窗口,而另一个已经打开了一个窗口,则activedocument是指上一个文档。

一个人可以做什么来纠正这一点?

I am currently writing a Visual Studio extension and have implemented the function TextViewCreated in a class that implements an ITextViewCreationListener interface.

The function is called with an ITextView parameter that represent the content of the editor window that just has been created. However, I need not just the contend of the edited document but also the path the file it represents, and an ITextView object apparently has no method to get that information.

So far, I have used the DTE2.ActiveDocument property, but it does not always work correctly. Especially if one opens a new text window in Visual Studio while another one is already open, ActiveDocument refers to the previous document.

What can one do to correct this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她说她爱他 2025-01-25 01:30:37
using Microsoft.VisualStudio.Text;

public string GetDocumentPath(ITextView view)
{
    if (view.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDocument) && textDocument is not null)
    {
       return textDocument.FilePath;
    }

    return null;
}
using Microsoft.VisualStudio.Text;

public string GetDocumentPath(ITextView view)
{
    if (view.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDocument) && textDocument is not null)
    {
       return textDocument.FilePath;
    }

    return null;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文