public FunctionalTreeVisualizerWindow(FunctionalTree functionalTree)
        {
            InitializeComponent();

            FunctionalTree = functionalTree;
            SetupFunctionalTree();
        }
        internal FunctionalTree GetOrCreateFunctionalTree(IFunctionalTreeElement element)
        {
            if (element == null)
                return null;

            FunctionalTree tree = GetFunctionalTree(element);
            if (tree != null)
                return tree;

            tree = new FunctionalTree(element);
            tree.FunctionalChildAttachedInternal += Tree_FunctionalChildAttached;
            tree.FunctionalChildDetachedInternal += Tree_FunctionalChildDetached;

            FunctionalTreeList.Add(tree);
            return tree;
        }
 private void DetachedFromTreeHandler(FunctionalTree functionalTree)
 {
     MainWindow.Reporter.WriteLine(string.Format("[Detached From Tree] Element: {0}", Name));
 }
Esempio n. 4
0
        private void FunctionalTree_FunctionalChildDetached(IFunctionalTreeElement child, IFunctionalTreeElement parent, FunctionalTree functionalTree)
        {
            if (child == this)
                return;

            IDockingElement dockingChild = child as IDockingElement;
            if (dockingChild != null)
                OnDockingContentDetached(dockingChild);
        }
        private void FunctionalElementDetachedFromTree(FunctionalTreeElement element, FunctionalTreeElement parent, FunctionalTree functionalTree)
        {
            foreach (FunctionalProperty property in FunctionalPropertyValuesInternal.Keys)
            {
                if (property.DefaultMetadata == null || !property.DefaultMetadata.Inherits || property.DefaultMetadata.PropertyChangedCallback == null)
                    continue;

                if (HasValue(property, element.Element))
                    continue;

                FunctionalTreeElement curParent = parent;
                while (curParent != null)
                {
                    if (HasValue(property, curParent.Element))
                    {
                        object oldValue = GetValue(property, curParent.Element);
                        object newValue = property.DefaultMetadata.DefaultValue;

                        property.DefaultMetadata.PropertyChangedCallback(element.Element,
                            new FunctionalPropertyChangedEventArgs(property, oldValue, newValue));

                        if (property.DefaultMetadata.Inherits)
                            NotifyChildrenAboutInheritedValue(FunctionalTreeHelper.GetFunctionalChildren(element.Element), property, oldValue, newValue);

                        break;
                    }

                    curParent = curParent.Parent;
                }
            }
        }
        private void Tree_FunctionalChildAttached(FunctionalTreeElement child, FunctionalTreeElement parent, FunctionalTree functionalTree)
        {
            //remove all other trees with the element or any child in it
            IEnumerable<FunctionalTreeElement> childSubElements = GetAllElements(child);
            IEnumerable<FunctionalTree> treesToRemove = FunctionalTreeList.Where(tree => childSubElements.Any(subElement => tree.IsChild(subElement.Element)));
            //Debug.Assert((treesToRemove.Count() - 1) <= 1, "There shouldn't be more than one tree to remove.");

            foreach (FunctionalTree tree in treesToRemove.ToList())
            {
                if (tree == functionalTree)
                    continue;

                tree.FunctionalChildAttachedInternal -= Tree_FunctionalChildAttached;
                tree.FunctionalChildDetachedInternal -= Tree_FunctionalChildDetached;

                FunctionalTreeList.Remove(tree);
            }

            if (FunctionalElementAttachedToTree != null)
                FunctionalElementAttachedToTree(child, parent, functionalTree);
        }
        private void Tree_FunctionalChildDetached(FunctionalTreeElement child, FunctionalTreeElement parent, FunctionalTree functionalTree)
        {
            //Make sure there are no other trees with child in it
            int removedTreeCount = RemoveTreesWithElement(child.Element);
            //TODO fix and remove unused trees effectively
            //Debug.Assert(removedTreeCount == 0, "There shouldn't have been any trees left with child in it.");

            if (child.HasData)
            {
                //save child in new functional tree to save the data
                FunctionalTree tree = new FunctionalTree(child);
                tree.FunctionalChildAttachedInternal += Tree_FunctionalChildAttached;
                tree.FunctionalChildDetachedInternal += Tree_FunctionalChildDetached;

                FunctionalTreeList.Add(tree);
            }

            if (FunctionalElementDetachedFromTree != null)
                FunctionalElementDetachedFromTree(child, parent, functionalTree);
        }