SSMS-Schema-Folders icon indicating copy to clipboard operation
SSMS-Schema-Folders copied to clipboard

How to add commands to the context menu?

Open win32nipuh opened this issue 5 years ago • 2 comments

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'

win32nipuh avatar Jul 01 '19 10:07 win32nipuh

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.

nicholas-ross avatar Jul 03 '19 07:07 nicholas-ross

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.

win32nipuh avatar Jul 03 '19 08:07 win32nipuh