In my previous post on writing a SSMS Add-in for Denali I detailed the steps that you would need to take to get the Add-in loaded and running but it didn’t do a great deal.
Now we take it a step further. But not too far(!)
I’ve done a number of things;
- Hooked up to the events class in DTE, so we can get a view on what’s happening inside the Add-in.
- Added some T-SQL code formatting functionality, to show how to access the contents of a query window.
- Added a context menu to the Object Explorer
- Put all the source on Codeplex under a new project called ‘’SQL Server Management Studio Add-in for Denali (SSMS Addin)” Url: http://ssmsaddindenali.codeplex.com/ Feel free to download or/and join the project and contribute.
1) As we all know, SSMS Add-in’s only work because of a deep dark magic, but there are a few ways we can peek inside to see what’s happening.
The DTE object we get during the OnConnection method has a class full of events – so lets hook them up and see what happens.
EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.Application.ActiveDocument.Object(null);
Returns a TextDocument object from which you can get the contents of the window (SQL).
3) Just like previous versions add-ins, you use the same code to pick up Object Explorer events.
1: objExplorerService = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService));
2: cs = (ContextService)objExplorerService.Container.Components[0];
3: cs.ObjectExplorerContext.CurrentContextChanged += new NodesChangedEventHandler(ObjectExplorerContext_CurrentContextChanged);
Download the source from codeplex, check it out, play with it, check it in!