Closed ErikEJ closed 2 months ago
I ended up with this relativly unbrittle implementation:
var Dte2 = GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;
var uih = Dte2.ToolWindows.GetToolWindow(EnvDTE.Constants.vsWindowKindServerExplorer) as EnvDTE.UIHierarchy;
var selectedItems = (Array)uih.SelectedItems;
if (selectedItems != null)
{
var connectionName = ((EnvDTE.UIHierarchyItem)selectedItems.GetValue(0)).Name;
var dataConnectionsService = await VS.GetServiceAsync<IVsDataExplorerConnectionManager, IVsDataExplorerConnectionManager>();
if (dataConnectionsService.Connections.TryGetValue(connectionName, out IVsDataExplorerConnection explorerConnection))
{
var connection = explorerConnection.Connection;
if (VsDataHelper.SupportedProviders.Contains(connection.Provider))
{
menuCommand.Visible = true;
}
}
}
I am trying to get the ADO Connection object from an item selected in Server Explorer.
I found this old thing - but is there a better way with Vsix Toolkit?
https://stackoverflow.com/questions/15541438/how-to-get-the-selected-connection-node-object-of-vs-server-explorer-window-ddex
(I am fine with just getting the name of the selected node)