如何获取VS Server Explorer窗口DDEX选中的连接节点对象

编程入门 行业动态 更新时间:2024-10-25 12:25:59
本文介绍了如何获取VS Server Explorer窗口DDEX选中的连接节点对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-27 04:33:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1148589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   对象   窗口   Server   Explorer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!