using System;
using System.ComponentModel.Design;
using System.Globalization;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace TestExecWin
{
internal sealed class TestExecWindowCommand
{
public const int CommandId = 0x0100;
public static readonly Guid CommandSet = new Guid("12b68e40-4d22-4698-b473-c2ca730f42ec");
private readonly Package package;
private TestExecWindowCommand(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.ShowToolWindow, menuCommandID);
commandService.AddCommand(menuItem);
}
}
public static TestExecWindowCommand Instance
{
get;
private set;
}
private IServiceProvider ServiceProvider
{
get
{
return this.package;
}
}
public static void Initialize(Package package)
{
Instance = new TestExecWindowCommand(package);
}
private void ShowToolWindow(object sender, EventArgs e)
{
ToolWindowPane window = this.package.FindToolWindow(typeof(TestExecWindow), 0, true);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException("Cannot create tool window");
}
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
}
}
}