Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Explorer custom context menu item #498

Closed
ErikEJ opened this issue Apr 7, 2024 · 1 comment
Closed

Server Explorer custom context menu item #498

ErikEJ opened this issue Apr 7, 2024 · 1 comment

Comments

@ErikEJ
Copy link

ErikEJ commented Apr 7, 2024

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)

@ErikEJ
Copy link
Author

ErikEJ commented Apr 8, 2024

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;
                    }
                }
            }

@ErikEJ ErikEJ closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2024
@ErikEJ ErikEJ changed the title Server Explorer context Server Explorer custom context menu item Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant