public void Set(TextEditor textEditor, IEnumerable<MulticastMessageViewModel> collection) { _ranges.Clear(); var document = new StringBuilder(); var settings = new List<CustomElementSetting>(); foreach (var target in collection) { int startOffset = document.Length; { string item1; if (target.Option.State.HasFlag(MulticastMessageState.IsLocked)) item1 = "#"; else if (target.Option.State.HasFlag(MulticastMessageState.IsUnread)) item1 = "!"; else item1 = "@"; var item2 = target.Item.CreationTime.ToLocalTime().ToString(LanguagesManager.Instance.DateTime_StringFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo); var item3 = target.Item.Signature; { settings.Add(new CustomElementSetting("State", document.Length, item1.Length)); document.Append(item1); document.Append(" "); settings.Add(new CustomElementSetting("CreationTime", document.Length, item2.Length)); document.Append(item2); document.Append(" - "); settings.Add(new CustomElementSetting("Signature", document.Length, item3.Length)); document.Append(item3); if (!Inspect.ContainTrustSignature(target.Item.Signature)) { document.Append(" +"); document.Append(target.Option.Cost); } } document.AppendLine(); } { document.AppendLine(); } { foreach (var line in target.Item.Comment .Trim('\r', '\n') .Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None) .Take(128)) { foreach (var match in _uriRegexes.Select(n => n.Matches(line)).SelectMany(n => n.OfType<Match>())) { settings.Add(new CustomElementSetting("Uri", document.Length + match.Index, match.Length)); } document.AppendLine(line); } } { document.AppendLine(); } _ranges.Add(new CustomElementRange(startOffset, document.Length)); } if (document.Length >= 2) document.Remove(document.Length - 2, 2); textEditor.Document.BeginUpdate(); textEditor.Document.Text = ""; textEditor.CaretOffset = 0; textEditor.SelectionLength = 0; textEditor.TextArea.TextView.ElementGenerators.Clear(); textEditor.ScrollToHome(); textEditor.Document.Text = document.ToString(); var elementGenerator = new CustomElementGenerator(settings); elementGenerator.ClickEvent += (string text) => this.OnClickEvent(text); elementGenerator.SelectEvent += (CustomElementRange range) => textEditor.Select(range.Start, range.End - range.Start); textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator); textEditor.Document.EndUpdate(); textEditor.CaretOffset = textEditor.Document.Text.Length; textEditor.TextArea.Caret.BringCaretToView(); textEditor.ScrollToEnd(); }
public void Clear(TextEditor textEditor) { _ranges.Clear(); textEditor.Document.BeginUpdate(); textEditor.Document.Text = ""; textEditor.CaretOffset = 0; textEditor.SelectionLength = 0; textEditor.TextArea.TextView.ElementGenerators.Clear(); textEditor.ScrollToHome(); textEditor.Document.EndUpdate(); }
public void ScrollToHome() { _editor.ScrollToHome(); }