Beispiel #1
0
        public void Save(Stream stream, RichTextAreaFormat format)
        {
            switch (format)
            {
            case RichTextAreaFormat.PlainText:
                var bytes = Encoding.UTF8.GetBytes(Control.Buffer.Text);
                stream.Write(bytes, 0, bytes.Length);
                return;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #2
0
        public void Load(Stream stream, RichTextAreaFormat format)
        {
            var range = new NSRange(0, Control.TextStorage.Length);

            switch (format)
            {
            case RichTextAreaFormat.Rtf:
            {
                var str = NSAttributedString.CreateWithRTF(NSData.FromStream(stream), out var docAttributes);
                NSMutableAttributedString mut = null;
                nint pos = 0;
                // when encountering an RTF without a defined foreground, use the system foreground for dark mode
                var textColor = TextColor.ToNSUI();
                while (pos < str.Length)
                {
                    var color = str.GetAttribute(NSStringAttributeKey.ForegroundColor, pos, out var effectiveRange);
                    pos = effectiveRange.Location + effectiveRange.Length;
                    if (color == null)
                    {
                        if (mut == null)
                        {
                            mut = new NSMutableAttributedString(str);
                        }

                        mut.AddAttribute(NSStringAttributeKey.ForegroundColor, textColor, effectiveRange);
                    }
                }

                if (mut != null)
                {
                    str = mut;
                }

                Control.TextStorage.Replace(range, str);
                break;
            }

            case RichTextAreaFormat.PlainText:
            {
                var str = new NSMutableAttributedString(new StreamReader(stream).ReadToEnd());
                Font.Apply(str);
                str.AddAttribute(NSStringAttributeKey.ForegroundColor, TextColor.ToNSUI(), new NSRange(0, str.Length));
                Control.TextStorage.Replace(range, str);
                break;
            }

            default:
                throw new NotSupportedException();
            }
            Callback.OnTextChanged(Widget, EventArgs.Empty);
        }
Beispiel #3
0
        public void Save(System.IO.Stream stream, RichTextAreaFormat format)
        {
            switch (format)
            {
            case RichTextAreaFormat.Rtf:
                Control.SaveFile(stream, swf.RichTextBoxStreamType.RichText);
                break;

            case RichTextAreaFormat.PlainText:
                Control.SaveFile(stream, swf.RichTextBoxStreamType.PlainText);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #4
0
        public void Load(System.IO.Stream stream, RichTextAreaFormat format)
        {
            switch (format)
            {
            case RichTextAreaFormat.PlainText:
                Control.Buffer.Clear();
                using (var reader = new StreamReader(stream))
                {
                    Control.Buffer.Text = reader.ReadToEnd();
                }
                break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #5
0
        public void Load(Stream stream, RichTextAreaFormat format)
        {
            switch (format)
            {
            case RichTextAreaFormat.Rtf:
                var range = new NSRange(0, Control.TextStorage.Length);
                Control.ReplaceWithRtf(range, NSData.FromStream(stream));
                break;

            case RichTextAreaFormat.PlainText:
                Control.TextStorage.SetString(new NSAttributedString(new StreamReader(stream).ReadToEnd()));
                break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #6
0
        public void Save(Stream stream, RichTextAreaFormat format)
        {
            var range = ContentRange;

            switch (format)
            {
            case RichTextAreaFormat.Rtf:
                range.Save(stream, sw.DataFormats.Rtf);
                break;

            case RichTextAreaFormat.PlainText:
                range.Save(stream, sw.DataFormats.Rtf);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #7
0
        public void Save(Stream stream, RichTextAreaFormat format)
        {
            switch (format)
            {
            case RichTextAreaFormat.Rtf:
                var range = new NSRange(0, Control.TextStorage.Length);
                Control.RtfFromRange(range).AsStream().CopyTo(stream);
                break;

            case RichTextAreaFormat.PlainText:
                var bytes = Encoding.UTF8.GetBytes(Control.TextStorage.Value);
                stream.Write(bytes, 0, bytes.Length);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #8
0
        public void Load(System.IO.Stream stream, RichTextAreaFormat format)
        {
            SuppressSelectionChanged++;
            switch (format)
            {
            case RichTextAreaFormat.Rtf:
                Control.LoadFile(stream, swf.RichTextBoxStreamType.RichText);
                break;

            case RichTextAreaFormat.PlainText:
                Control.LoadFile(stream, swf.RichTextBoxStreamType.PlainText);
                break;

            default:
                throw new NotSupportedException();
            }
            SuppressSelectionChanged--;
            Selection = Range.FromLength(Control.TextLength, 0);
        }
Beispiel #9
0
        public void Load(Stream stream, RichTextAreaFormat format)
        {
            SuppressSelectionChanged++;
            SuppressTextChanged++;
            var range = ContentRange;

            switch (format)
            {
            case RichTextAreaFormat.Rtf:
                range.Load(stream, sw.DataFormats.Rtf);
                break;

            case RichTextAreaFormat.PlainText:
                range.Load(stream, sw.DataFormats.Text);
                break;

            default:
                throw new NotSupportedException();
            }
            SuppressTextChanged--;
            SuppressSelectionChanged--;
            Callback.OnTextChanged(Widget, EventArgs.Empty);
            Selection = Range.FromLength(ContentRange.GetLength(), 0);
        }