Exemple #1
0
 public static NSAttributedString CreateString(this string text, NSColor color)
 {
     var defaults = new DefaultSettings ();
     return CreateString (text, color, defaults.Font);
 }
        public void Append(TextTag tag)
        {
            _textView.BeginInvokeOnMainThread(() => {
                var text = tag.Text.Replace("&lt;", "<").Replace("&gt;", ">");

                var defaultSettings = new DefaultSettings();

                var defaultColor = _highlightSettings.Get(HighlightKeys.Default).Color;

                var color = !string.IsNullOrWhiteSpace(tag.Color) ? tag.Color : defaultColor;
                var font = tag.Mono ? defaultSettings.MonoFont : defaultSettings.Font;

                var scroll = _textView.EnclosingScrollView.VerticalScroller.FloatValue == 1.0f;

                //textView.TextStorage.BeginEditing();
                _textView.TextStorage.Append(text.CreateString(color.ToNSColor(), font));
                //textView.TextStorage.EndEditing();

                if(scroll)
                    _textView.ScrollRangeToVisible(new NSRange(_textView.Value.Length, 0));
            });
        }
        public void ReplaceText(IEnumerable<TextTag> tags)
        {
            _textView.BeginInvokeOnMainThread(() => {

                var defaultSettings = new DefaultSettings();
                var defaultColor = _highlightSettings.Get(HighlightKeys.Default).Color;

                //textView.TextStorage.BeginEditing();
                _textView.TextStorage.SetString("".CreateString(defaultColor.ToNSColor()));
                tags.Apply(tag => {
                    var color = !string.IsNullOrWhiteSpace(tag.Color) ? tag.Color : defaultColor;
                    var font = tag.Mono ? defaultSettings.MonoFont : defaultSettings.Font;
                    _textView.TextStorage.Append(tag.Text.CreateString(color.ToNSColor(), font));
                });
                //textView.TextStorage.EndEditing();
            });
        }
        private void LogRoom(string text, NSTextView textView)
        {
            var defaultSettings = new DefaultSettings();
            var defaultColor = _highlightSettings.Get(HighlightKeys.Default).Color;

            //textView.TextStorage.BeginEditing();
            textView.TextStorage.SetString("".CreateString(defaultColor.ToNSColor(), defaultSettings.Font));
            //textView.TextStorage.EndEditing();

            var highlights = _services.Get<Highlights>();
            highlights.For(TextTag.For(text)).Apply(t => Append(t, textView));
        }