VSPackage:当没有“真实”文件时如何获取选定的文件解决方案已打开
我正在用 C# 开发一个 VSPackage,我想知道当只有一个文件(或在 Visual Studio 中打开多个文件)时如何获取当前文件。
当存在层次结构时(打开一个真实解决方案),一切都可以正常工作。但是当我在 Visual Studio 中打开单个文件时,我无法获取当前选择。我的意思是打开 Visual Studio(没有解决方案)并选择文件
-> 打开
-> 文件
。
我需要获取其中之一:itemid、documentCookie、mkDocumentName 或其他。
我尝试了以下操作:
IVsMonitorSelection.GetCurrentSelection()
->它总是检索没有层次结构的解决方案项目 ID (Intpr.Zero)IVsSelectionEvents
->我尝试监听选择事件,新的 itemId 始终是解决方案 itemidRunningDocumentTable
->好吧,我很快就能找到解决方案,因为我可以枚举打开的文件,但我不确定如何确定哪个是当前文件。
I'm developing a VSPackage in C#, and I would like to know how to get the current file, when only a single file (or several files are opened in Visual Studio).
All works fine when there is a hierarchy (a real solution opened). But when I open a single file in Visual Studio, I cannot get the curren selection. I mean open Visual Studio (without solution) and select File
-> Open
-> File
.
I need to get one of these: itemid, documentCookie, mkDocumentName or whatever.
I tried the following:
IVsMonitorSelection.GetCurrentSelection()
-> It always retrieve the solution item id without hierarchy (Intpr.Zero)IVsSelectionEvents
-> I tried to listen the selection event, the new itemId is always the solution itemidRunningDocumentTable
-> Well, I'm close to find the solution, because I can enumerate the opened files, but I'm not sure how to determine which is the current one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是 DTE 可以为您解决的问题。您是否检查过 DTE2.ActiveDocument(通过查询 SDTE 检索)?
This sounds like something that the DTE can solve for you. Have you checked DTE2.ActiveDocument (retrieved by querying for SDTE)?