private void ReflexiveCloned(object sender, ReflexiveClonedEventArgs e) { FlattenedReflexive flattened = _flattenInfo[e.Old]; AttachTo(e.Clone, flattened); flattened.SynchronizeWith(e.Clone); }
private void ReflexivePropertyChanged(object sender, PropertyChangedEventArgs e) { var reflexive = (ReflexiveData)sender; FlattenedReflexive flattenedField = _flattenInfo[reflexive]; if (e.PropertyName == "IsExpanded") { if (reflexive.IsExpanded) { flattenedField.Expand(); } else { flattenedField.Contract(); } } else if (!_loading && (e.PropertyName == "CurrentIndex" || e.PropertyName == "FirstEntryAddress" || e.PropertyName == "EntrySize")) { _loading = true; _tracker.Enabled = false; if (e.PropertyName == "FirstEntryAddress") { // Throw out any cached changes and reset the current index RecursiveReset(flattenedField.LoadedFields); if (reflexive.Length > 0) { reflexive.CurrentIndex = 0; } else { reflexive.CurrentIndex = -1; } } else { // Cache any changes made to the current page RecursiveUnload(flattenedField.LoadedFields); } // Load the new page in flattenedField.LoadPage(reflexive, reflexive.CurrentIndex); // Read any non-cached fields in the page _reader.ReadReflexiveChildren(reflexive); RecursiveLoad(flattenedField.LoadedFields); _tracker.Enabled = true; _loading = false; } }
private void RecursiveLoad(IEnumerable <MetaField> fields) { foreach (MetaField field in fields) { var reflexive = field as ReflexiveData; if (reflexive != null) { FlattenedReflexive flattened = _flattenInfo[reflexive]; _flattenInfo[reflexive].LoadPage(reflexive, reflexive.CurrentIndex); RecursiveLoad(flattened.LoadedFields); } } }
public WrappedReflexiveEntry GetTopLevelWrapper(WrappedReflexiveEntry wrapper) { WrappedReflexiveEntry result = wrapper; FlattenedReflexive reflexive = _parent; while (reflexive != null) { int index = reflexive._template.Template.IndexOf(result); result = reflexive._wrappers[index]; reflexive = reflexive._parent; } return(result); }
public FlattenedReflexive(FlattenedReflexive parent, ReflexiveData template, ObservableCollection<MetaField> topLevelFields, FieldChangeTracker tracker, FieldChangeSet changes) { _parent = parent; _template = template; _activeReflexive = template; _synchronizedReflexives.Add(template); if (template.HasChildren) _lastPage = template.Pages[template.CurrentIndex]; _topLevelFields = topLevelFields; _tracker = tracker; _changes = changes; }
private void RecursiveReset(IEnumerable <MetaField> fields) { foreach (MetaField field in fields) { _tracker.MarkUnchanged(field); var reflexive = field as ReflexiveData; if (reflexive != null) { FlattenedReflexive flattened = _flattenInfo[reflexive]; RecursiveReset(flattened.LoadedFields); reflexive.ResetPages(); } } }
public FlattenedReflexive(FlattenedReflexive parent, ReflexiveData template, ObservableCollection <MetaField> topLevelFields, FieldChangeTracker tracker, FieldChangeSet changes) { _parent = parent; _template = template; _activeReflexive = template; _synchronizedReflexives.Add(template); if (template.HasChildren) { _lastPage = template.Pages[template.CurrentIndex]; } _topLevelFields = topLevelFields; _tracker = tracker; _changes = changes; }
private void HideFields(FlattenedReflexive reflexive, int start, int end) { if (end <= start) { return; } if (reflexive != null) { int baseIndex = reflexive._template.Template.IndexOf(_template) + 1; if (reflexive._expanded) { reflexive.HideFields(reflexive._parent, baseIndex + start, baseIndex + end); } bool adjustLast = false; for (int i = start; i < end; i++) { reflexive._fieldVisibility[baseIndex + i] = false; if (reflexive._wrappers[baseIndex + i].IsLast) { reflexive._wrappers[baseIndex + i].IsLast = false; adjustLast = true; } } if (adjustLast && start + baseIndex > 0) { int lastVisible = reflexive._fieldVisibility.FindLastIndex(start + baseIndex - 1, v => v); if (lastVisible >= 0) { reflexive._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); } } } }
private void ShowFields(FlattenedReflexive reflexive, int start, int end) { if (end <= start) { return; } if (reflexive != null) { // Set the visibility of everything int baseIndex = reflexive._template.Template.IndexOf(_template) + 1; for (int i = start; i < end; i++) { reflexive._fieldVisibility[baseIndex + i] = _fieldVisibility[i]; } // Update the IsLast states in case we added wrappers after the "last" one if (baseIndex + start > 0 && reflexive._wrappers[baseIndex + start - 1].IsLast) { int lastVisible = reflexive._fieldVisibility.FindLastIndex(v => v); if (lastVisible >= 0) { reflexive._wrappers[baseIndex + start - 1].IsLast = false; reflexive._wrappers[lastVisible].IsLast = true; } } // Recurse through ancestors if we're expanded if (reflexive._expanded) { reflexive.ShowFields(reflexive._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++; } } } }
public void VisitReflexive(ReflexiveData field) { // Create flatten information for the reflexive and attach event handlers to it var flattened = new FlattenedReflexive(_flatParent, field, _topLevelFields, _tracker, _changes); AttachTo(field, flattened); FlattenedReflexive oldParent = _flatParent; _flatParent = flattened; Flatten(field.Template); field.UpdateWidth(); _flatParent = oldParent; for (int i = 0; i < field.Template.Count; i++) { WrappedReflexiveEntry wrapper = flattened.WrapField(field.Template[i], field.Width, i == field.Template.Count - 1); _index++; _fields.Insert(_index, wrapper); } }
private void AttachTo(ReflexiveData field, FlattenedReflexive flattened) { field.PropertyChanged += ReflexivePropertyChanged; field.Cloned += ReflexiveCloned; _flattenInfo[field] = flattened; }
private void ShowFields(FlattenedReflexive reflexive, int start, int end) { if (end <= start) return; if (reflexive != null) { // Set the visibility of everything int baseIndex = reflexive._template.Template.IndexOf(_template) + 1; for (int i = start; i < end; i++) reflexive._fieldVisibility[baseIndex + i] = _fieldVisibility[i]; // Update the IsLast states in case we added wrappers after the "last" one if (baseIndex + start > 0 && reflexive._wrappers[baseIndex + start - 1].IsLast) { int lastVisible = reflexive._fieldVisibility.FindLastIndex((v) => v); if (lastVisible >= 0) { reflexive._wrappers[baseIndex + start - 1].IsLast = false; reflexive._wrappers[lastVisible].IsLast = true; } } // Recurse through ancestors if we're expanded if (reflexive._expanded) reflexive.ShowFields(reflexive._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++; } } } }
private void HideFields(FlattenedReflexive reflexive, int start, int end) { if (end <= start) return; if (reflexive != null) { int baseIndex = reflexive._template.Template.IndexOf(_template) + 1; if (reflexive._expanded) reflexive.HideFields(reflexive._parent, baseIndex + start, baseIndex + end); bool adjustLast = false; for (int i = start; i < end; i++) { reflexive._fieldVisibility[baseIndex + i] = false; if (reflexive._wrappers[baseIndex + i].IsLast) { reflexive._wrappers[baseIndex + i].IsLast = false; adjustLast = true; } } if (adjustLast && start + baseIndex > 0) { int lastVisible = reflexive._fieldVisibility.FindLastIndex(start + baseIndex - 1, (v) => v); if (lastVisible >= 0) reflexive._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); } } }
public void VisitReflexive(ReflexiveData field) { // Create flatten information for the reflexive and attach event handlers to it FlattenedReflexive flattened = new FlattenedReflexive(_flatParent, field, _topLevelFields, _tracker, _changes); AttachTo(field, flattened); FlattenedReflexive oldParent = _flatParent; _flatParent = flattened; Flatten(field.Template); field.UpdateWidth(); _flatParent = oldParent; for (int i = 0; i < field.Template.Count; i++) { WrappedReflexiveEntry wrapper = flattened.WrapField(field.Template[i], field.Width, i == field.Template.Count - 1); _index++; _fields.Insert(_index, wrapper); } }