/// <summary> /// Occurs when a menu item is clicked. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> that contains data related to this event.</param> private void OnRemoveNote(object sender, RoutedEventArgs e) { MenuItem item = (MenuItem)sender; // Get the tag range TagSnapshotRange <IntraTextNoteTag> tagRange = (TagSnapshotRange <IntraTextNoteTag>)item.Tag; // Get the tagger from the code document ICodeDocument document = tagRange.SnapshotRange.Snapshot.Document as ICodeDocument; if (document != null) { IntraTextNoteTagger tagger = null; if (document.Properties.TryGetValue(typeof(IntraTextNoteTagger), out tagger)) { // Try and find the tag version range that contains the tag TagVersionRange <IIntraTextSpacerTag> tagVersionRange = tagger[tagRange.Tag]; if (tagVersionRange != null) { // Remove the tag version range from the tagger tagger.Remove(tagVersionRange); } } } }
/// <summary> /// Occurs when the button is clicked. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private void OnAddNoteButtonClick(object sender, RoutedEventArgs e) { // Get the tagger that was created by the language and has been persisted in the document's properties // while the language is active on the document IntraTextNoteTagger tagger = null; if (editor.Document.Properties.TryGetValue(typeof(IntraTextNoteTagger), out tagger)) { // Create a version range ITextVersionRange versionRange = editor.ActiveView.Selection.SnapshotRange.ToVersionRange(TextRangeTrackingModes.ExpandFirstEdge | TextRangeTrackingModes.DeleteWhenZeroLength); // Create a tag that will be used to reserve space between text characters... // Since the tags in this sample are persisted in a collection while active, // we can use the tag itself as the key... the key is used to retrieve // the bounds of the spacer later on so adornments can be rendered in it, thus is must be unique IntraTextNoteTag tag = new IntraTextNoteTag(); tag.Key = tag; tag.Size = new Size(30, 18); tag.Baseline = 14; tag.Author = "Actipro Customer"; tag.Created = DateTime.Now; tag.Message = noteText.Text.Trim(); tag.Status = ReviewStatus.Pending; // Add the tag to the tagger tagger.Add(new TagVersionRange <IIntraTextSpacerTag>(versionRange, tag)); } // Focus the editor editor.Focus(); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Changes the status of the specified note tag. /// </summary> /// <param name="tagRange">The tag range.</param> /// <param name="status">The new status.</param> private void ChangeNoteStatus(TagSnapshotRange <IntraTextNoteTag> tagRange, ReviewStatus status) { // Get the tagger from the code document ICodeDocument document = tagRange.SnapshotRange.Snapshot.Document as ICodeDocument; if (document != null) { IntraTextNoteTagger tagger = null; if (document.Properties.TryGetValue(typeof(IntraTextNoteTagger), out tagger)) { // Change the tag's status and raise an event so the UI knows to update tagRange.Tag.Status = status; tagger.RaiseTagsChanged(new TagsChangedEventArgs(tagRange.SnapshotRange)); } } }