问题描述
限时送ChatGPT账号..我正在为我的 VS 扩展的服务器资源管理器中的连接节点添加一些选项.对于我添加的菜单选项之一,我需要获取所选连接的连接字符串,因此我尝试通过在 BeforeQueryStatus 事件和命令处理程序方法中添加一些代码来实现这一点.但看起来我错过了一些东西,因为每次我想获得 DataViewHierarchyAccessor 的实例时,我总是得到一个空值.虽然如果我做同样的事情但在较低级别的节点中工作正常.我使用了以下代码但没有运气:
I'm adding some options for the Connection Node in the server explorer for my VS extension. For one of the menu options that I have added I need to get the connection string of the very selected connection, So I have tried this by adding some code in the BeforeQueryStatus event and also in the command handler method. But looks like I'm missing something since every time I want to get an Instance of the DataViewHierarchyAccessor I always get a null value. Although if I do the same thing but in a lower level node works fine. I have used the following code with no luck:
IVsDataExplorerNodeSelection nodeSelection = (IVsDataExplorerNodeSelection)Package.GetGlobalService(typeof(IVsDataExplorerNodeSelection));
IVsDataExplorerNodeSelection nodeSelection = (IVsDataExplorerNodeSelection)Package.GetGlobalService(typeof(IVsDataExplorerNodeSelection));
IVsUIHierarchyhierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsUIHierarchy)) as IVsUIHierarchy;
IVsUIHierarchy hierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsUIHierarchy)) as IVsUIHierarchy;
有没有人为服务器浏览器窗口的连接节点做过类似的事情?
Has anybody done something similar for the Connection Node of the Server Explorer Window?
更新:
看起来我在这方面取得了一些进展,我只是尝试了这个:
Looks like I got some progress on this, I just tried this:
EnvDTE80.DTE2 _applicationObject = GetDTE2();
UIHierarchy uih = _applicationObject.ToolWindows.GetToolWindow("Server Explorer") as UIHierarchy;
Array selectedItems = (Array)uih.SelectedItems;
if (null != selectedItems)
{
foreach (UIHierarchyItem selItem in selectedItems)
{
SelectedItem prjItem = selItem.Object as EnvDTE.SelectedItem;
string name = prjItem.Name;
}
}
现在我的问题是是否有更好的类型来投射 selectedItems 列表?而不是 EnvDTE.SelectedItem.
Now my question is if there's a better type to cast the list of selectedItems? instead of EnvDTE.SelectedItem.
提前致谢.
推荐答案
将我的问题标记为已回答,因为我发布的代码起到了作用.
Marking my question as answered since the code that I posted did the trick.
EnvDTE80.DTE2 _applicationObject = GetDTE2();
UIHierarchy uih = _applicationObject.ToolWindows.GetToolWindow("Server Explorer") as UIHierarchy;
Array selectedItems = (Array)uih.SelectedItems;
if (null != selectedItems)
{
foreach (UIHierarchyItem selItem in selectedItems)
{
SelectedItem prjItem = selItem.Object as EnvDTE.SelectedItem;
string name = prjItem.Name;
}
}
这篇关于如何获取VS Server Explorer窗口DDEX选中的连接节点对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论