Beispiel #1
0
        /// <summary>
        /// Remove pane
        /// </summary>
        public bool Remove(DockablePane pane)
        {
            if (!_isInited)
            {
                return(false);
            }

            Debug.Assert(CompositionType.Terminal != _type);

            _CalculateSpaceFactors();

            bool isRemoved = false;

            // find terminal element to deleting
            Composition terminalComposition2Delete = null;

            for (int index = 0; index < _children.Count; ++index)
            {
                Composition currentComposition = _children[index];
                if (CompositionType.Terminal == currentComposition.Type)
                {
                    if (currentComposition.AttachedPane.Equals(pane))
                    {
                        terminalComposition2Delete = currentComposition;
                        break; // NOTE: founded
                    }
                }
                else
                {   // remove from child composition
                    if (currentComposition.Remove(pane))
                    {
                        isRemoved = true;
                        break;
                    }
                }
            }

            // remove terminal element
            if (null != terminalComposition2Delete)
            {
                _children.Remove(terminalComposition2Delete);
                isRemoved = true;

                if (1 == _children.Count)
                {   // change state to terminal
                    Composition lastChield = _children[0];
                    _children.Clear();
                    if (CompositionType.Terminal == lastChield.Type)
                    {
                        _type         = CompositionType.Terminal;
                        _attachedPane = lastChield.AttachedPane;
                    }
                    else
                    {
                        _type = lastChield.Type;
                        ICollection <Composition> children = lastChield.Children;
                        foreach (Composition child in children)
                        {
                            _children.Add(child);
                        }
                    }
                }
                else
                {
                    // recalculate new space factors
                    Size   sz       = _CalculateSpaceSize();
                    double fullSize = (_type == CompositionType.Horizontal) ? sz.Height : sz.Width;
                    fullSize += SPLITTER_SIZE;

                    double splitterFree = SPLITTER_SIZE / _children.Count;

                    Size freeSize = terminalComposition2Delete._CalculateSpaceSize();
                    for (int index = 0; index < _children.Count; ++index)
                    {
                        Composition child     = _children[index];
                        Size        childSize = child._CalculateSpaceSize();
                        child.SpaceFactor = (_type == CompositionType.Horizontal) ?
                                            ((childSize.Height + freeSize.Height * child.SpaceFactor + splitterFree) / Math.Max(fullSize, 1)) :
                                            ((childSize.Width + freeSize.Width * child.SpaceFactor + splitterFree) / Math.Max(fullSize, 1));
                    }
                }
            }
            else if (isRemoved)
            {   // normalize composition - if child presented as one line
                for (int index = 0; index < _children.Count; ++index)
                {
                    Composition currentChild = _children[index];
                    if (currentChild.Type == _type)
                    {
                        ICollection <Composition> children = currentChild.Children;
                        Debug.Assert(currentChild.Type != CompositionType.Terminal);
                        Debug.Assert(1 < currentChild.Children.Count);

                        Collection <Composition> fromRemoved = new Collection <Composition> ();
                        foreach (Composition child in children)
                        {
                            fromRemoved.Add(child);
                        }

                        _children.Remove(currentChild);
                        _children.InsertRange(index, fromRemoved);
                    }
                }

                _CalculateSpaceFactors();
            }

            Debug.Assert(_IsNormalized());
            return(isRemoved);
        }