テーブルのコンテキスト メニューにカスタム ボタンを追加する SQL Server 2012 Management Studio 用のアドインを作成しています。
ガイダンスとして、codeplex で次のプロジェクトのソース コードを使用しました。
コードは次のとおりです。
void ObjectExplorerContext_CurrentContextChanged(object sender, NodesChangedEventArgs args)
{
debug_message("ObjectExplorerContext_CurrentContextChanged::");
try
{
// Getting current node context
Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.INavigationContextProvider navigationContextProvider = (INavigationContextProvider)sender;
INavigationContext navigationContext = (INavigationContext)navigationContextProvider.CurrentContext;
// Find selected node node
ObjectExplorerService objectExplorer = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService));
INodeInformation node = objectExplorer.FindNode(navigationContext.Context);
debug_message(string.Format("ObjectExplorerContext_CurrentContextChanged::Selected Node {0}",navigationContext.Context));
// Code to add extra items to the menu
if (_tableMenu == null && _tableRegex.IsMatch(node.Context))
{
_tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));
tableMenuItem item = new tableMenuItem();
_tableMenu.AddChild(string.Empty, item);
}
}
catch (Exception ObjectExplorerContextException)
{
debug_message(String.Format("ObjectExplorerContext_CurrentContextChanged::ERROR:{0}", ObjectExplorerContextException.Message));
}
}
テーブルを一度右クリックすると、余分なボタンはありません。もう一度クリックすると、ボタンが追加されますが、2 回です。デバッグ中に、コードが 2 回実行されることがわかりました。(メソッドは非同期で呼び出されていると思います。)
残念ながら、SSMS アドインの作成に関する記事はあまりないため、グーグルで解決策を見つけることができませんでした。
誰かがこの問題を解決するのを手伝ってくれますか?