/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); if (!(Package.GetGlobalService(typeof(DTE)) is DTE dte)) { MessageBox.Show("Could not generate port comments because dte is null."); return; } Document activeDocument = dte.ActiveDocument; if (activeDocument == null) { MessageBox.Show("Could not generate port comments because there is no active document."); return; } if (!(activeDocument.Selection is TextSelection selection)) { MessageBox.Show("Could not generate port comments because no selection was found."); return; } VirtualPoint activePoint = selection.ActivePoint; string line = activePoint.CreateEditPoint().GetLines(activePoint.Line, activePoint.Line + 1); GeneratePortCommentViewModel vm = new GeneratePortCommentViewModel(line); GeneratePortCommentControl dialog = new GeneratePortCommentControl(vm); bool?result = dialog.ShowModal(); if (result == true) { selection.LineUp(); selection.EndOfLine(); selection.NewLine(); selection.Insert(vm.Preview); } vm.Dispose(); }
public GeneratePortCommentControl(GeneratePortCommentViewModel viewModel) { DataContext = viewModel; InitializeComponent(); }