public void Inactivate() { this.textView.ViewportHeightChanged -= OnViewportHeightChanged; this.textView.Selection.SelectionChanged -= OnSelectionChanged; this.textView.LayoutChanged -= OnLayoutChanged; this.treeView.Items.Clear(); var tagger = CurrentTagMarkerProvider.GetCurrentTagMarkerForView(this.textView); Debug.Assert(tagger != null); tagger.RemoveTagSpans(s => true); }
private void UpdateVisuals() { var tagger = CurrentTagMarkerProvider.GetCurrentTagMarkerForView(this.textView); Debug.Assert(tagger != null); tagger.RemoveTagSpans(s => true); this.treeView.Items.Clear(); if (this.textView.Selection.SelectedSpans.Count == 0) { return; } // Don't do any work if we aren't visible if (ActualHeight < 5) { return; } Dictionary <Type, List <IMappingTagSpan <ITag> > > tagSpansByType = new Dictionary <Type, List <IMappingTagSpan <ITag> > >(); foreach (var tagSpan in this.aggregator.GetTags(this.textView.Selection.SelectedSpans)) { Type type = tagSpan.Tag.GetType(); // Ignore our own tags. if (type == typeof(CurrentTagMarker)) { continue; } if (!tagSpansByType.ContainsKey(type)) { tagSpansByType[type] = new List <IMappingTagSpan <ITag> >(); } tagSpansByType[type].Add(tagSpan); } foreach (var type in tagSpansByType.Keys.OrderBy(type => type.Name)) { List <IMappingTagSpan <ITag> > tagSpans = tagSpansByType[type]; TreeViewItem typeItem = new TreeViewItem() { Header = string.Format("{0} ({1})", type.Name, tagSpans.Count) }; List <SnapshotSpan> snapshotSpans = new List <SnapshotSpan>(); foreach (var tagSpan in tagSpans) { TreeViewItem tagSpanItem = new TreeViewItem(); var spansInView = tagSpan.Span.GetSpans(this.textView.TextSnapshot); // This should never happen, since we asked for tags over the selection, which // we know is in the view. if (spansInView.Count == 0) { continue; } var snapshotSpan = new SnapshotSpan(spansInView[0].Start, spansInView[spansInView.Count - 1].End); snapshotSpans.Add(snapshotSpan); object toolTipContent; string displayString = DisplayStringForTag(tagSpan.Tag, out toolTipContent); if (displayString != null) { tagSpanItem.Header = string.Format("Tag: {0}, Span: {1}", displayString, snapshotSpan.Span); if (toolTipContent != null) { tagSpanItem.ToolTip = toolTipContent; } } else { tagSpanItem.Header = string.Format("Span: {0}", snapshotSpan.Span); } tagSpanItem.Selected += (sender, args) => { tagger.RemoveTagSpans(s => true); tagger.CreateTagSpan(snapshotSpan.Snapshot.CreateTrackingSpan(snapshotSpan, SpanTrackingMode.EdgeExclusive), new CurrentTagMarker()); args.Handled = true; }; typeItem.Items.Add(tagSpanItem); } typeItem.Selected += (sender, args) => { tagger.RemoveTagSpans(s => true); foreach (var snapshotSpan in snapshotSpans) { tagger.CreateTagSpan(snapshotSpan.Snapshot.CreateTrackingSpan(snapshotSpan, SpanTrackingMode.EdgeExclusive), new CurrentTagMarker()); } }; this.treeView.Items.Add(typeItem); } }