Пример #1
0
        public object GetAttributeValue(int attribute)
        {
            // Lazy load mappings
            if (attr_to_val_handler == null)
            {
                PopulateAttributeDictionary();
            }

            if (!attr_to_val_handler.ContainsKey(attribute))
            {
                throw new ArgumentException();
            }

            TagDataValueHandler val_handler = attr_to_val_handler[attribute];

            Line    line;
            LineTag tag;
            int     pos;

            List <TagData> tags = new List <TagData> ();
            Document       d    = textboxbase.document;

            int point = normalizer.StartPoint;

            while (point < normalizer.EndPoint)
            {
                d.CharIndexToLineTag(point, out line,
                                     out tag, out pos);
                tags.Add(new TagData(tag, line));
                point += tag.Length;
            }

            IEnumerable <TagData> results
                = tags.Distinct(new LineTagComparer(val_handler));
            int count = results.Count();

            if (count == 1)
            {
                return(val_handler(results.First()));
            }
            else if (count > 1)
            {
                return(TextPattern.MixedAttributeValue);
            }

            return(null);
        }
Пример #2
0
 public LineTagComparer(TagDataValueHandler h)
 {
     this.val_handler = h;
 }
Пример #3
0
        public ITextRangeProvider FindAttribute(int attribute, object @value,
                                                bool backward)
        {
            // Lazy load mappings
            if (attr_to_val_handler == null)
            {
                PopulateAttributeDictionary();
            }

            if (!attr_to_val_handler.ContainsKey(attribute))
            {
                return(null);
            }

            Line    line;
            LineTag tag;
            int     pos;

            TagDataValueHandler val_handler = attr_to_val_handler[attribute];
            Document            d           = textboxbase.document;
            TextRangeProvider   range       = null;

            if (!backward)
            {
                for (int i = StartPoint; i < EndPoint; i += tag.Length)
                {
                    d.CharIndexToLineTag(i, out line, out tag, out pos);
                    if (val_handler(new TagData(tag, line)).Equals(@value))
                    {
                        if (range == null)
                        {
                            range = new TextRangeProvider(provider, textboxbase,
                                                          i, i + tag.Length);
                        }
                        else
                        {
                            range.EndPoint += tag.Length;
                        }
                    }
                    else if (range != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int i = EndPoint - 1; i >= StartPoint; i -= tag.Length)
                {
                    d.CharIndexToLineTag(i, out line, out tag, out pos);
                    if (val_handler(new TagData(tag, line)).Equals(@value))
                    {
                        if (range == null)
                        {
                            int start = i - tag.Length + 1;
                            range = new TextRangeProvider(provider, textboxbase,
                                                          start, start + tag.Length);
                        }
                        else
                        {
                            range.StartPoint -= tag.Length;
                        }
                    }
                    else if (range != null)
                    {
                        break;
                    }
                }
            }

            return(range);
        }