Пример #1
0
        protected override void InsertTimeStamp(Gtk.TextBuffer buffer, ref Gtk.TextIter iter,
                                                string timestamp, MessageModel msg)
        {
            if (String.IsNullOrWhiteSpace(msg.ID))
            {
                buffer.Insert(ref iter, timestamp);
            }
            else
            {
                var uri = new Uri(String.Format("https://twitter.com/{0}/status/{1}", msg.GetNick(), msg.ID));

                var tags = new List <Gtk.TextTag>();
                // link URI tag
                var linkTag = new LinkTag(uri);
                linkTag.TextEvent += OnLinkTagTextEvent;
                _MessageTextTagTable.Add(linkTag);
                tags.Add(linkTag);

                // link style tag
                tags.Add(LinkTag);

                buffer.InsertWithTags(ref iter, timestamp, tags.ToArray());
            }

            buffer.Insert(ref iter, " ");
        }
Пример #2
0
        private void InsertToBuffer(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, UrlMessagePartModel urlPart)
        {
            var linkText = urlPart.Text ?? urlPart.Url;

            Uri uri;

            try {
                uri = new Uri(urlPart.Url);
            } catch (UriFormatException ex) {
#if LOG4NET
                _Logger.Error("AddMessage(): Invalid URL: " + urlPart.Url, ex);
#endif
                buffer.Insert(ref iter, linkText);
                return;
            }

            var tags = new List <Gtk.TextTag>();
            // link URI tag
            var linkTag = new LinkTag(uri);
            linkTag.TextEvent += OnLinkTagTextEvent;
            _MessageTextTagTable.Add(linkTag);
            tags.Add(linkTag);

            // link style tag
            tags.Add(LinkTag);

            buffer.InsertWithTags(ref iter, linkText, tags.ToArray());
        }
Пример #3
0
        public override void Redo(Gtk.TextBuffer buffer)
        {
            RemoveSplitTags(buffer);

            Gtk.TextIter cursor = buffer.GetIterAtOffset(Offset);

            Gtk.TextTag[] tags = { Tag };
            buffer.InsertWithTags(ref cursor, Id, tags);

            buffer.MoveMark(buffer.SelectionBound, buffer.GetIterAtOffset(Offset));
            buffer.MoveMark(buffer.InsertMark,
                            buffer.GetIterAtOffset(Offset + chop.Length));
        }
Пример #4
0
        public static void ConvertDatabaseToEditCategorie(string raw, ref Gtk.TextBuffer buffer)
        {
            var splittedTags = Regex.Split(raw, "(<.>|</.>|<..>)");             // What a noobish Regex
            var tagList      = new List <Gtk.TextTag>();

            // Split text into HTML-tags and insert the text with them
            var endIter = buffer.EndIter;

            foreach (var textBit in splittedTags)
            {
                switch (textBit)
                {
                case "<br>":
                    buffer.Insert(ref endIter, "\n");
                    break;

                case "<b>":
                    tagList.Add(boldTag);
                    break;

                case "</b>":
                    tagList.Remove(boldTag);
                    break;

                case "<i>":
                    tagList.Add(italicTag);
                    break;

                case "</i>":
                    tagList.Remove(italicTag);
                    break;

                default:
                    if (tagList.Count != 0)
                    {
                        buffer.InsertWithTags(ref endIter, textBit, tagList.ToArray());
                    }
                    else
                    {
                        buffer.Insert(ref endIter, textBit);
                    }
                    break;
                }
            }
        }
Пример #5
0
        private void InsertToBuffer(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, TextMessagePartModel fmsgti)
        {
            var tags = new List <Gtk.TextTag>();

            if (fmsgti.Text == null)
            {
                // Gtk.TextBuffer.Insert*() asserts on text == NULL
                return;
            }
            if (fmsgti.ForegroundColor != TextColor.None)
            {
                var bg = ColorConverter.GetTextColor(BackgroundColor);
                if (fmsgti.BackgroundColor != TextColor.None)
                {
                    bg = fmsgti.BackgroundColor;
                }
                TextColor color = TextColorTools.GetBestTextColor(
                    fmsgti.ForegroundColor, bg
                    );
                string tagname = GetTextTagName(color, null);
                var    tag     = _MessageTextTagTable.Lookup(tagname);
                tags.Add(tag);
            }
            if (fmsgti.BackgroundColor != TextColor.None)
            {
                // TODO: get this from ChatView
                string tagname = GetTextTagName(null, fmsgti.BackgroundColor);
                var    tag     = _MessageTextTagTable.Lookup(tagname);
                tags.Add(tag);
            }
            if (fmsgti.Underline)
            {
#if LOG4NET && MSG_DEBUG
                _Logger.Debug("AddMessage(): fmsgti.Underline is true");
#endif
                tags.Add(UnderlineTag);
            }
            if (fmsgti.Bold)
            {
#if LOG4NET && MSG_DEBUG
                _Logger.Debug("AddMessage(): fmsgti.Bold is true");
#endif
                tags.Add(BoldTag);
            }
            if (fmsgti.Italic)
            {
#if LOG4NET && MSG_DEBUG
                _Logger.Debug("AddMessage(): fmsgti.Italic is true");
#endif
                tags.Add(ItalicTag);
            }

            if (tags.Count > 0)
            {
                buffer.InsertWithTags(ref iter, fmsgti.Text, tags.ToArray());
            }
            else
            {
                buffer.Insert(ref iter, fmsgti.Text);
            }
        }