How to add commands to the context menu?
I'd like to add commands to Object Explorer menu? for example: if user right-clicked on Server node - add 'command1', if it is Database node - 'command2', if it is schema node then 'command3'
I haven't tried modifying the context menu, so I can't help you there. But if you can get a reference to the TreeNode that was clicked, then I might be able to help.
The INodeInformation interface has the details you are looking for.
You will need:
Reference to SqlWorkbench.Interfaces.dll
using Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer;
The tree nodes in the Object Explorer implement IServiceProvider which can retrieve the INodeInformation. See the GetNodeInformation function in the ObjectExplorerExtender.cs for how this is done.
The property you want is INodeInformation.UrnPath. Check if it is "Server" or "Server/Database" and then add your commands. For other folders, check the ReorganizeFolders function in SsmsSchemaFoldersPackage.cs for what I am using.
Thank you very much.
Yet one note:
In which method I can catch click on a Tree node to analyze and modify menu?
In my AddIn for SSMS 2012 I redefined methods: OnConnection, OnDisconnection etc like this
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
and did menu manipulation there. To test I have added the same methods to the SSMS-Schema-Folders but they not called anymore in VS2017 Shell extension.
Finally I have made as you have described, it seems it works. Now I need to get the existing node's context menu and modify it on-the-fly.