public void TextViewCreated(IWpfTextView textView) { // HookVisualStudioUI(); var layer = textView.GetAdornmentLayer("UiAdornmentLayer"); if (layer == null) { return; } SimpleAdroner box; if (!textView.Properties.TryGetProperty(typeof(SimpleAdroner), out box)) { var grid = new Grid() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Width = textView.ViewportWidth, Height = textView.ViewportHeight, Tag = "ASMTooltipBox" }; box = new SimpleAdroner() { Background = Brushes.White, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Width = 400.0, Height = 120.0 }; grid.Children.Add(box); textView.Properties.AddProperty(typeof(SimpleAdroner), box); layer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, textView, grid, null); textView.ViewportWidthChanged += TextView_ViewportWidthChanged; textView.ViewportHeightChanged += TextView_ViewportHeightChanged; textView.LayoutChanged += TextView_LayoutChanged; } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; // Map the trigger point down to our buffer. SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(m_textBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot; SnapshotSpan querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); //look for occurrences of our QuickInfo words in the span ITextStructureNavigator navigator = m_provider.NavigatorService.GetTextStructureNavigator(m_textBuffer); TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value); var spans = m_classifier.GetClassificationSpans(extent.Span); var textView = session.TextView as IWpfTextView; SimpleAdroner box = null; if (textView != null) { if (textView.Properties.TryGetProperty(typeof(SimpleAdroner), out box)) { box.CleanUp(); } } if (box != null && spans.Count != 0) { var spobj = (HurunaClassificationSpan)spans.FirstOrDefault(sp => sp is HurunaClassificationSpan); if (spobj != null && spobj.Definition != null) { applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, querySpan.Length, SpanTrackingMode.EdgeExclusive); if (!string.IsNullOrEmpty(spobj.Definition.brief)) { qiContent.Add(spobj.Definition.brief); } if (!string.IsNullOrEmpty(spobj.Definition.usage)) { box.SetText(spobj.Definition.usage); } // Debug.WriteLine("QuickInfo: {0}", new[] { spobj.Span.GetText() }); return; } } if (HasSpecialChar(extent.Span.GetText())) { return; } var t = subjectTriggerPoint.Value.GetContainingLine(); var line = t.GetText(); if (string.IsNullOrEmpty(line)) { return; } int i = subjectTriggerPoint.Value.Position; for (; i >= t.Start.Position; i--) { if (IsSpecialChar(line[i - t.Start.Position])) { break; } } if (i < t.Start.Position) { i = t.Start.Position; } else { i++; } int j = subjectTriggerPoint.Value.Position; for (; j <= t.End.Position; j++) { if (j == t.End.Position || IsSpecialChar(line[j - t.Start.Position])) { break; } } if (j > t.End.Position) { j = t.End.Position; } var k = line.Substring(i - t.Start.Position, j - i); if (char.IsNumber(k[0])) { ulong u; if (ParseULong(k, out u)) { applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, querySpan.Length, SpanTrackingMode.EdgeInclusive); qiContent.Add(string.Format("DEC: {0:D}\nHEX: {0:X}", u)); } } else if (k[0] == '?') { string str; if (s_dictUndname.TryGetValue(k, out str) == false) { Process ps = new Process(); ps.StartInfo = new ProcessStartInfo() { FileName = mutable.Loader.UndnamePath, Arguments = k, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; ps.Start(); str = ps.StandardOutput.ReadLine(); while (str != null) { if (str.StartsWith("is :- ")) { str = str.Substring(7).Trim(' ', '"'); s_dictUndname[k] = str; break; } str = ps.StandardOutput.ReadLine(); } } applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, querySpan.Length, SpanTrackingMode.EdgeInclusive); qiContent.Add("UNDECORATED TO"); qiContent.Add(str); // the content can be string or WPF element. } else if (i != t.Start) { if (line[i - t.Start.Position - 1] == '.') { NasmClassifier nasmclassifier; if (m_textBuffer.Properties.TryGetProperty(typeof(NasmClassifier), out nasmclassifier)) { var lbs = nasmclassifier.GetLabels(); if (lbs.Count != 0) { int?z = lbs.Keys.Where(y => y <= t.LineNumber).Max(p => (int?)p); if (z.HasValue && lbs.ContainsKey(z.Value)) { applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, querySpan.Length, SpanTrackingMode.EdgeInclusive); qiContent.Add("LOCAL LABEL FOR"); qiContent.Add(string.Format("{0}\nAT LINE #{1}", lbs[z.Value], z.Value + 1)); } } } } } }