/// <summary> /// Define a command handler. /// When the user presses the button corresponding to the CommandID, /// then the EventHandler will be called. /// </summary> /// <param name="id">The CommandID (Guid/ID pair) as defined in the .vsct file</param> /// <param name="handler">Method that should be called to implement the command</param> /// <returns>The menu command. This can be used to set parameter such as the default visibility once the package is loaded</returns> private MsVsShell.OleMenuCommand DefineCommandHandler(EventHandler handler, CommandID id) { // First add it to the package. This is to keep the visibility // of the command on the toolbar constant when the tool window does // not have focus. In addition, it creates the command object for us. PackageToolWindow package = (PackageToolWindow)this.Package; MsVsShell.OleMenuCommand command = package.DefineCommandHandler(handler, id); // Verify that the command was added if (command == null) { return(command); } // Get the OleCommandService object provided by the base window pane class; this object is the one // responsible for handling the collection of commands implemented by the package. MsVsShell.OleMenuCommandService menuService = GetService(typeof(IMenuCommandService)) as MsVsShell.OleMenuCommandService; if (null != menuService) { // Add the command handler menuService.AddCommand(command); } return(command); }
/// <summary> /// This is called after our control has been created and sited. /// This is a good place to initialize the control with data gathered /// from Visual Studio services. /// </summary> public override void OnToolWindowCreated() { base.OnToolWindowCreated(); PackageToolWindow package = (PackageToolWindow)this.Package; // Set the text that will appear in the title bar of the tool window. // Note that because we need access to the package for localization, // we have to wait to do this here. If we used a constant string, // we could do this in the constructor. this.Caption = package.GetResourceString("@110"); // Register to the window events WindowStatus windowFrameEventsHandler = new WindowStatus(this.OutputWindowPane, this.Frame as IVsWindowFrame); ErrorHandler.ThrowOnFailure(((IVsWindowFrame)this.Frame).SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, (IVsWindowFrameNotify3)windowFrameEventsHandler)); // Let our control have access to the window state control.CurrentState = windowFrameEventsHandler; }
/// <summary> /// This is called after our control has been created and sited. /// This is a good place to initialize the control with data gathered /// from Visual Studio services. /// </summary> public override void OnToolWindowCreated() { base.OnToolWindowCreated(); PackageToolWindow package = (PackageToolWindow)this.Package; // Set the text that will appear in the title bar of the tool window. // Note that because we need access to the package for localization, // we have to wait to do this here. If we used a constant string, // we could do this in the consturctor. this.Caption = package.GetResourceString("@100"); // Add the handler for our toolbar button CommandID id = new CommandID(GuidsList.guidClientCmdSet, PkgCmdId.cmdidRefreshWindowsList); MsVsShell.OleMenuCommand command = DefineCommandHandler(new EventHandler(this.RefreshList), id); // Get the selection tracking service and pass it to the control so that it can push the // active selection. Only needed if you want to display something in the Properties window. // Note that this service is only available for windows (not in the global service provider) // Additionally, each window has its own (so you should not be sharing one between multiple windows) control.TrackSelection = (ITrackSelection)this.GetService(typeof(STrackSelection)); // Ensure the control's handle has been created; otherwise, BeginInvoke cannot be called. // Note that during runtime this should have no effect when running inside Visual Studio, // as the control's handle should already be created, but unit tests can end up calling // this method without the control being created. control.InitializeComponent(); // Delay initialization of the list until other tool windows have also had a chance to be // initialized control.Dispatcher.BeginInvoke((Action) delegate { // Populate the list view this.RefreshList(this, null); }); }