private void SetupAttachCommand(OleMenuCommandService menuCommandService) { var dynamicItemRootId = new CommandID(GuidList.Commands, (int)CommandIDs.AttachToDynamicStub); var dynamicMenuCommand = new DynamicMenuCommand( (sender, e) => { var invokedCommand = (DynamicMenuCommand)sender; _controller.HandleAttachTo(invokedCommand.Text); }, dynamicItemRootId, index => _controller.GetTargets().ElementAtOrDefault(index) ); menuCommandService.AddCommand(dynamicMenuCommand); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this)); base.Initialize(); var optionsPage = (AttachTargetOptionPage)this.GetDialogPage(typeof(AttachTargetOptionPage)); this.controller = new AttachToAnythingController((DTE)GetService(typeof(DTE)), optionsPage); // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null == mcs) return; var dynamicItemRootId = new CommandID(GuidList.CommandSet, (int)PkgCmdIDList.AttachToDynamicStub); var dynamicMenuCommand = new DynamicMenuCommand( DynamicItemInvokeCallback, dynamicItemRootId, index => this.controller.GetTargets().ElementAtOrDefault(index) ); mcs.AddCommand(dynamicMenuCommand); }