private void GenerateLayout(CommentTag tag) { //Draw lable _textBlock = new TextBlock() { Foreground = Brushes.Gray }; //Draw Line _line = new Line(); _line.Stroke = Brushes.LightGray; _line.StrokeThickness = 6; _line.SnapsToDevicePixels = true; _line.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); //Get format _typeface = _format.GetTypeface(); _fontSize = _format.GetFontSize(); if (_typeface != null) { //Set format for text block _textBlock.FontFamily = _typeface.FontFamily; _textBlock.FontStyle = _typeface.Style; _textBlock.FontStretch = _typeface.Stretch; _textBlock.FontWeight = _typeface.Weight; _textBlock.FontSize = _fontSize; } //Refresh layout RefreshLayout(tag.Comment); //Add to parent this.Children.Add(_line); this.Children.Add(_textBlock); }
/// <summary> /// 打开文件自动翻译 /// </summary> /// <param name="tag"></param> private void StartTranslate(CommentTag tag) { var comment = tag.Comment; if (!string.IsNullOrEmpty(comment.Content) && (_translatedComment == null || comment.Content != _translatedComment.Content)) { //Set translated comment _translatedComment = comment; //Display wait translate WaitTranslate("翻译中..."); //Translate comment Task.Run(() => CommentTranslatorPackage.TranslateClient.Translate(comment.Content)) .ContinueWith((data) => { //Call translate complete if (!data.IsFaulted) { TranslateComplete(new TranslatedComment(comment, data.Result.Data), null); } else { TranslateComplete(new TranslatedComment(comment, data.Result.Data), data.Exception); } }, TaskScheduler.FromCurrentSynchronizationContext()); } }
public CommentAdornment(CommentTag tag, SnapshotSpan span, IWpfTextView textView, IEditorFormatMap format, SnapshotSpan containSpan) { _tag = tag; _span = span; _view = textView; _format = format; _containSpan = containSpan; GenerateLayout(tag); Translate(tag); }
public void Update(CommentTag tag, SnapshotSpan span, SnapshotSpan containSpan) { //Set properties _span = span; _containSpan = containSpan; if (tag.Comment.Content != _tag.Comment.Content || tag.Comment.Line != _tag.Comment.Line) { //Refresh layout RefreshLayout(tag.Comment); //Request translate Translate(tag); } //Set properties _tag = tag; }
private void Translate(CommentTag tag, bool force = false) { //Set translating tag _currentTag = tag; if (force || !_isTranslating) { //Set translating _isTranslating = true; //Wait to translate if (tag.TimeWaitAfterChange <= 0) { _isTranslating = false; StartTranslate(tag); } else { Task.Delay(tag.TimeWaitAfterChange) .ContinueWith((data) => { if (!data.IsFaulted) { if (tag.Comment.Content != _currentTag.Comment.Content) { Translate(_currentTag, true); } else { _isTranslating = false; StartTranslate(tag); } } }, TaskScheduler.FromCurrentSynchronizationContext()); } } }