Esempio n. 1
0
        private void TagBlockCloned(object sender, TagBlockClonedEventArgs e)
        {
            FlattenedTagBlock flattened = _flattenInfo[e.Old];

            AttachToTagBlock(e.Clone, flattened);
            flattened.SynchronizeWith(e.Clone);
        }
Esempio n. 2
0
        private void TagBlockPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var block = (TagBlockData)sender;
            FlattenedTagBlock flattenedField = _flattenInfo[block];

            if (e.PropertyName == "IsExpanded")
            {
                if (block.IsExpanded)
                {
                    flattenedField.Expand();
                }
                else
                {
                    flattenedField.Contract();
                }
            }
            else if (!_loading &&
                     (e.PropertyName == "CurrentIndex" || e.PropertyName == "FirstElementAddress" || e.PropertyName == "ElementSize"))
            {
                _loading         = true;
                _tracker.Enabled = false;

                if (e.PropertyName == "FirstElementAddress")
                {
                    // Throw out any cached changes and reset the current index
                    RecursiveReset(flattenedField.LoadedFields);
                    if (block.Length > 0)
                    {
                        block.CurrentIndex = 0;
                    }
                    else
                    {
                        block.CurrentIndex = -1;
                    }
                }
                else
                {
                    // Cache any changes made to the current page
                    RecursiveUnload(flattenedField.LoadedFields);
                }

                // Load the new page in
                flattenedField.LoadPage(block, block.CurrentIndex);

                // Read any non-cached fields in the page
                _reader.ReadTagBlockChildren(block);
                RecursiveLoad(flattenedField.LoadedFields);

                _tracker.Enabled = true;
                _loading         = false;
            }
        }
Esempio n. 3
0
 private void RecursiveLoad(IEnumerable <MetaField> fields)
 {
     foreach (MetaField field in fields)
     {
         var block = field as TagBlockData;
         if (block != null)
         {
             FlattenedTagBlock flattened = _flattenInfo[block];
             _flattenInfo[block].LoadPage(block, block.CurrentIndex);
             RecursiveLoad(flattened.LoadedFields);
         }
     }
 }
Esempio n. 4
0
        public WrappedTagBlockEntry GetTopLevelWrapper(WrappedTagBlockEntry wrapper)
        {
            WrappedTagBlockEntry result = wrapper;
            FlattenedTagBlock    block  = _parent;

            while (block != null)
            {
                int index = block._template.Template.IndexOf(result);
                result = block._wrappers[index];
                block  = block._parent;
            }
            return(result);
        }
Esempio n. 5
0
        private void RecursiveReset(IEnumerable <MetaField> fields)
        {
            foreach (MetaField field in fields)
            {
                _tracker.MarkUnchanged(field);

                var block = field as TagBlockData;
                if (block != null)
                {
                    FlattenedTagBlock flattened = _flattenInfo[block];
                    RecursiveReset(flattened.LoadedFields);
                    block.ResetPages();
                }
            }
        }
Esempio n. 6
0
 public FlattenedTagBlock(FlattenedTagBlock parent, TagBlockData template,
                          ObservableCollection <MetaField> topLevelFields, FieldChangeTracker tracker, FieldChangeSet changes)
 {
     _parent         = parent;
     _template       = template;
     _activeTagBlock = template;
     _synchronizedTagBlocks.Add(template);
     if (template.HasChildren)
     {
         _lastPage = template.Pages[template.CurrentIndex];
     }
     _topLevelFields = topLevelFields;
     _tracker        = tracker;
     _changes        = changes;
 }
Esempio n. 7
0
        private void HideFields(FlattenedTagBlock block, int start, int end)
        {
            if (end <= start)
            {
                return;
            }

            if (block != null)
            {
                int baseIndex = block._template.Template.IndexOf(_template) + 1;
                if (block._expanded)
                {
                    block.HideFields(block._parent, baseIndex + start, baseIndex + end);
                }

                bool adjustLast = false;
                for (int i = start; i < end; i++)
                {
                    block._fieldVisibility[baseIndex + i] = false;
                    if (block._wrappers[baseIndex + i].IsLast)
                    {
                        block._wrappers[baseIndex + i].IsLast = false;
                        adjustLast = true;
                    }
                }

                if (adjustLast && start + baseIndex > 0)
                {
                    int lastVisible = block._fieldVisibility.FindLastIndex(start + baseIndex - 1, v => v);
                    if (lastVisible >= 0)
                    {
                        block._wrappers[lastVisible].IsLast = true;
                    }
                }
            }
            else
            {
                int baseIndex = _topLevelFields.IndexOf(_template) + 1 + GetVisibleFieldOffset(start);
                for (int i = start; i < end; i++)
                {
                    if (_fieldVisibility[i])
                    {
                        _topLevelFields.RemoveAt(baseIndex);
                    }
                }
            }
        }
Esempio n. 8
0
        private void ShowFields(FlattenedTagBlock block, int start, int end)
        {
            if (end <= start)
            {
                return;
            }

            if (block != null)
            {
                // Set the visibility of everything
                int baseIndex = block._template.Template.IndexOf(_template) + 1;
                for (int i = start; i < end; i++)
                {
                    block._fieldVisibility[baseIndex + i] = _fieldVisibility[i];
                }

                // Update the IsLast states in case we added wrappers after the "last" one
                if (baseIndex + start > 0 && block._wrappers[baseIndex + start - 1].IsLast)
                {
                    int lastVisible = block._fieldVisibility.FindLastIndex(v => v);
                    if (lastVisible >= 0)
                    {
                        block._wrappers[baseIndex + start - 1].IsLast = false;
                        block._wrappers[lastVisible].IsLast           = true;
                    }
                }

                // Recurse through ancestors if we're expanded
                if (block._expanded)
                {
                    block.ShowFields(block._parent, baseIndex + start, baseIndex + end);
                }
            }
            else
            {
                // Insert our fields into the top-level
                int insertIndex = _topLevelFields.IndexOf(_template) + 1 + GetVisibleFieldOffset(start);
                for (int i = start; i < end; i++)
                {
                    if (_fieldVisibility[i])
                    {
                        _topLevelFields.Insert(insertIndex, _wrappers[i]);
                        insertIndex++;
                    }
                }
            }
        }
Esempio n. 9
0
        public void VisitTagBlock(TagBlockData field)
        {
            // Create flatten information for the block and attach event handlers to it
            var flattened = new FlattenedTagBlock(_flatParent, field, _topLevelFields, _tracker, _changes);

            AttachToTagBlock(field, flattened);

            FlattenedTagBlock oldParent = _flatParent;

            _flatParent = flattened;
            Flatten(field.Template);
            field.UpdateWidth();
            _flatParent = oldParent;

            for (int i = 0; i < field.Template.Count; i++)
            {
                WrappedTagBlockEntry wrapper = flattened.WrapField(field.Template[i], field.Width, i == field.Template.Count - 1);
                _index++;
                _fields.Insert(_index, wrapper);
            }
        }
Esempio n. 10
0
 private void AttachToTagBlock(TagBlockData field, FlattenedTagBlock flattened)
 {
     field.PropertyChanged += TagBlockPropertyChanged;
     field.Cloned          += TagBlockCloned;
     _flattenInfo[field]    = flattened;
 }