public void Add(SnapshotSpan span, string text) { if (text.Equals("")) return; if (span.Length == 0) throw new ArgumentOutOfRangeException("span"); if (text == null) throw new ArgumentNullException("text"); //Create a post adornment given the span, and text. adornment = new TranslationAdornment(span, text); //Add it to the list of posts. translations.Add(adornment); //Raise the changed event. EventHandler<TranslationsChangedEventArgs> postsChanged = this.TranslationsChanged; if (postsChanged != null) postsChanged(this, new TranslationsChangedEventArgs(adornment, null)); }
private void DrawPost(TranslationAdornment post) { SnapshotSpan span = post.Span.GetSpan(this.view.TextSnapshot); Geometry g = this.view.TextViewLines.GetMarkerGeometry(span); if (g != null) { //Find the rightmost coordinate of all the lines that intersect the adornment. double maxRight = 0.0; foreach (ITextViewLine line in this.view.TextViewLines.GetTextViewLinesIntersectingSpan(span)) maxRight = Math.Max(maxRight, line.Right); //Create the visualization. TranslationInfoDisplay block = new TranslationInfoDisplay(maxRight, this.view.ViewportRight, g, post.Text); block.onMouseDown += RemoveAdornment; block.onMouseDown += (o, e) => { this.layer.RemoveAdornment(o as System.Windows.UIElement); this.provider.translations.Remove(post); }; //Add it to the layer. this.layer.AddAdornment(span, post, block); } }
public TranslationsChangedEventArgs(TranslationAdornment added, TranslationAdornment removed) { this.TranslationAdded = added; this.TranslationRemoved = removed; }