/// <summary> /// Fired when the user navigates to this task in the list. /// </summary> /// <param name="e">Parameter is not used.</param> protected override void OnNavigate(System.EventArgs e) { Param.Ignore(e); if (this.Document != null && this.Document.Length > 0) { try { Document document = ProjectUtilities.GetCodeDocument(this.Document); if (document == null) { AlertDialog.Show( this.Core, null, Strings.CouldNotNavigateToFile, Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { document.Activate(); TextSelection selection = (TextSelection)document.DTE.ActiveDocument.Selection; try { selection.GotoLine(this.violation.LineNumber, true); VirtualPoint vp = selection.ActivePoint; vp.TryToShow(vsPaneShowHow.vsPaneShowCentered, 0); } catch (ArgumentException) { // This happens when the line number passed to GotoLine is beyond the end of the file, or is otherwise // invalid. This can happen if the user has modified the file after StyleCop was run, and then // click an item in the error list which now points to an invalid line number. } } } catch (System.Runtime.InteropServices.COMException) { AlertDialog.Show( this.Core, null, Strings.CouldNotNavigateToFile, Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { AlertDialog.Show( this.Core, null, Strings.UnknownFile, Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } }