Example #1
0
        internal static void Remove(IDockPane dockPane, IDockElement dockElement)
        {
            Debug.Assert(dockPane != null);
            Debug.Assert(dockElement != null);
            Debug.Assert(dockPane != dockElement);

            var parent = GetParent(dockPane, dockElement);

            if (parent is IDockAnchorPane)
            {
                Debug.Assert(dockElement is IDockPane);

                var dockAnchorPane = (IDockAnchorPane)parent;
                dockAnchorPane.ChildPane = null;
            }
            else if (parent is IDockSplitPane)
            {
                Debug.Assert(dockElement is IDockPane);

                var dockSplitPane = (IDockSplitPane)parent;
                dockSplitPane.ChildPanes.Remove((IDockPane)dockElement);
            }
            else if (parent is IDockTabPane)
            {
                Debug.Assert(dockElement is IDockTabItem);

                var dockTabPane = (IDockTabPane)parent;
                dockTabPane.Items.Remove((IDockTabItem)dockElement);
            }
        }
Example #2
0
 public override void Detach(IDockElement element)
 {
     base.Detach(element);
     if (DockManager.AutoHideElement == element)
     {
         DockManager.AutoHideElement = null;
     }
 }
Example #3
0
 public int IndexOf(IDockElement child)
 {
     if (child == null)
     {
         return(-1);
     }
     return(_children.IndexOf(child as DockElement));
 }
Example #4
0
 public override void Detach(IDockElement element)
 {
     base.Detach(element);
     if (element.IsActive)
     {
         IsActive = false;
     }
 }
Example #5
0
 public override void Attach(IDockElement element, int index = -1)
 {
     if (!element.Side.Assert())
     {
         throw new ArgumentException("Side is illegal!");
     }
     base.Attach(element, index);
 }
Example #6
0
 public int IndexOf(IDockElement child)
 {
     if (child == null)
     {
         return(-1);
     }
     return(Children_CanSelect.IndexOf(child));
     //return _children.IndexOf(child as DockElement);
 }
Example #7
0
 public virtual void Attach(IDockElement element, int index = -1)
 {
     if (element == null || element.Container != null)
     {
         throw new InvalidOperationException("Attach Failed!");
     }
     _children.Insert(Math.Max(index, 0), element);
     (element as DockElement).Mode = _mode;
 }
Example #8
0
 public virtual void Detach(IDockElement element)
 {
     if (element == null || !_children.Contains(element))
     {
         throw new InvalidOperationException("Detach Failed!");
     }
     _children.Remove(element);
     (element as DockElement).IsVisible = false;
 }
Example #9
0
 public void CloseAllExcept(IDockElement element)
 {
     foreach (var child in _children.ToList())
     {
         if (child != element)
         {
             child.Hide();
         }
     }
 }
Example #10
0
 public virtual void SetActive(IDockElement element)
 {
     if (element != null && !element.CanSelect)
     {
         (element as DockElement).CanSelect = true;
     }
     if (_view != null)
     {
         DockManager.ActiveElement = element;
     }
 }
Example #11
0
 public virtual void Dispose()
 {
     SelectedItem = null;
     BindingOperations.ClearBinding(this, ItemsSourceProperty);
     Items.Clear();
     Model     = null;
     _dragItem = null;
     _childrenBounds?.Clear();
     _childrenBounds = null;
     Disposed(this, new EventArgs());
 }
Example #12
0
 public virtual void ShowWithActive(IDockElement element, bool toActive = true)
 {
     if (element != null && !element.CanSelect)
     {
         (element as DockElement).CanSelect = true;
     }
     if (_view != null && toActive)
     {
         DockManager.ActiveElement = element;
     }
 }
Example #13
0
 public void Dispose()
 {
     if (_isDisposed)
     {
         return;
     }
     _isDisposed = true;
     DockManager.RemoveDockControl(this);
     _protoType.PropertyChanged -= OnPrototypePropertyChanged;
     _protoType.Dispose();
     _protoType = null;
 }
Example #14
0
        //--------------------------------------------------------------
        #region Layout operations
        //--------------------------------------------------------------

        /// <overloads>
        /// <summary>
        /// Determines whether the docking layout contains the specified element.
        /// </summary>
        /// </overloads>
        ///
        /// <summary>
        /// Determines whether an <see cref="IDockContainer"/> contains the specified
        /// <see cref="IDockElement"/>.
        /// </summary>
        /// <param name="dockContainer">The dock container.</param>
        /// <param name="dockElement">The dock element.</param>
        /// <returns>
        /// <see langword="true"/> if <paramref name="dockContainer"/> contains
        /// <paramref name="dockElement"/>; otherwise, <see langword="false"/>.
        /// </returns>
        internal static bool Contains(this IDockContainer dockContainer, IDockElement dockElement)
        {
            Debug.Assert(dockContainer != null);
            Debug.Assert(dockElement != null);

            if (dockContainer.RootPane == null)
            {
                return(false);
            }

            return(Contains(dockContainer.RootPane, dockElement));
        }
Example #15
0
 public override void Attach(IDockElement element, int index = -1)
 {
     if (element.Side != DockSide.None)
     {
         throw new ArgumentException("Side is illegal!");
     }
     base.Attach(element, index);
     if (element.IsActive)
     {
         IsActive = true;
     }
 }
Example #16
0
 public override void Detach(IDockElement element)
 {
     base.Detach(element);
     //保存Size信息
     if (_view != null)
     {
         (element as DockElement).DesiredHeight = (_view as BaseGroupControl).ActualHeight;
         (element as DockElement).DesiredWidth  = (_view as BaseGroupControl).ActualWidth;
         //如果Children_CanSelect数量为0,且Container不是LayoutDocumentGroup,则尝试将view从界面移除
         if (Children_CanSelect.Count() == 0) //如果Children_CanSelect数量为0
         {
             _DetachFromParent();
         }
     }
 }
Example #17
0
        /// <summary>
        /// Determines if any <see cref="IDockPane"/> in a collection of <see cref="IDockPane"/>s
        /// contains the specified <see cref="IDockElement"/>.
        /// </summary>
        /// <param name="dockPanes">The collection of <see cref="IDockPane"/>s.</param>
        /// <param name="dockElement">The element to find.</param>
        /// <returns>
        /// <see langword="true"/> if a pane in <paramref name="dockPanes"/> is/contains
        /// <paramref name="dockElement"/>; otherwise, <see langword="false"/>.
        /// </returns>
        internal static bool Contains(this IReadOnlyList <IDockPane> dockPanes, IDockElement dockElement)
        {
            Debug.Assert(dockPanes != null);
            Debug.Assert(dockElement != null);

            foreach (var dockPane in dockPanes)
            {
                if (Contains(dockPane, dockElement))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #18
0
        /// <overloads>
        /// <summary>
        /// Removes the specified element from the docking layout.
        /// </summary>
        /// </overloads>
        ///
        /// <summary>
        /// Removes the specified element from the <see cref="IDockContainer"/>.
        /// </summary>
        /// <param name="rootContainer">The <see cref="IDockContainer"/>.</param>
        /// <param name="dockElement">The element to remove.</param>
        internal static void Remove(IDockContainer rootContainer, IDockElement dockElement)
        {
            Debug.Assert(rootContainer != null);
            Debug.Assert(rootContainer.RootPane != null);
            Debug.Assert(dockElement != null);

            if (rootContainer.RootPane == dockElement)
            {
                rootContainer.RootPane = null;
            }
            else
            {
                Remove(rootContainer.RootPane, dockElement);
            }
        }
Example #19
0
        /// <summary>
        /// Gets the <see cref="IDockPane"/> which is the direct parent of the specified child
        /// element.
        /// </summary>
        /// <param name="dockPanes">The collection of <see cref="IDockPane"/>s that are searched.</param>
        /// <param name="child">The child element.</param>
        /// <returns>
        /// The <see cref="IDockPane"/> which contains <paramref name="child"/> in its immediate
        /// children.
        /// </returns>
        internal static IDockPane GetParent(IReadOnlyList <IDockPane> dockPanes, IDockElement child)
        {
            Debug.Assert(dockPanes != null);
            Debug.Assert(child != null);

            for (int i = 0; i < dockPanes.Count; i++)
            {
                var parent = GetParent(dockPanes[i], child);
                if (parent != null)
                {
                    return(parent);
                }
            }

            return(null);
        }
Example #20
0
 public virtual void Attach(IDockElement element, int index = -1)
 {
     if (element == null || element.Container != null)
     {
         throw new InvalidOperationException("Attach Failed!");
     }
     if (index < 0)
     {
         _children.Add(element);
     }
     else
     {
         _children.Insert(index, element);
     }
     (element as DockElement).Mode = _mode;
 }
Example #21
0
        public override void ShowWithActive(IDockElement element, bool toActice = true)
        {
            base.ShowWithActive(element, toActice);
            if (_view != null)
            {
                (_view as TabControl).SelectedIndex = IndexOf(element);
            }
            else//_view不存在则要创建新的_view
            {
                if (_attachObj == null || !_attachObj.AttachTo())
                {
                    if (this is LayoutDocumentGroup)
                    {
                        var _children = Children.ToList();
                        _children.Reverse();
                        var dockManager = _dockManager;
                        Dispose();
                        foreach (var child in _children)
                        {
                            dockManager.Root.DocumentModels[0].Attach(child);
                        }
                    }
                    else
                    {
                        var ctrl = new AnchorSideGroupControl(this);
                        switch (Side)
                        {
                        case DockSide.Left:
                            _dockManager.LayoutRootPanel.RootGroupPanel.AttachChild(ctrl, AttachMode.Left, 0);
                            break;

                        case DockSide.Right:
                            _dockManager.LayoutRootPanel.RootGroupPanel.AttachChild(ctrl, AttachMode.Right, _dockManager.LayoutRootPanel.RootGroupPanel.Count);
                            break;

                        case DockSide.Top:
                            _dockManager.LayoutRootPanel.RootGroupPanel.AttachChild(ctrl, AttachMode.Top, 0);
                            break;

                        case DockSide.Bottom:
                            _dockManager.LayoutRootPanel.RootGroupPanel.AttachChild(ctrl, AttachMode.Bottom, _dockManager.LayoutRootPanel.RootGroupPanel.Count);
                            break;
                        }
                    }
                }
            }
        }
Example #22
0
        internal static void Remove(DockTabPaneCollection dockTabPanes, IDockElement dockElement)
        {
            Debug.Assert(dockTabPanes != null);
            Debug.Assert(dockElement != null);

            if (dockElement is IDockTabPane)
            {
                var dockTabPane = (IDockTabPane)dockElement;
                dockTabPanes.Remove(dockTabPane);
            }
            else if (dockElement is IDockTabItem)
            {
                var dockTabItem = (IDockTabItem)dockElement;
                var dockTabPane = (IDockTabPane)GetParent(dockTabPanes, dockTabItem);
                dockTabPane?.Items.Remove(dockTabItem);
            }
        }
Example #23
0
 public override void Detach(IDockElement element)
 {
     base.Detach(element);
     //保存Size信息
     if (_view != null)
     {
         var bgc = _view as BaseGroupControl;
         if (bgc.IsInitialized && bgc.ActualHeight >= Constants.SideLength && bgc.ActualWidth >= Constants.SideLength)
         {
             (element as DockElement).DesiredHeight = bgc.ActualHeight;
             (element as DockElement).DesiredWidth  = bgc.ActualWidth;
         }
         //如果Children_CanSelect数量为0,且Container不是LayoutDocumentGroup,则尝试将view从界面移除
         if (Children_CanSelect.Count() == 0) //如果Children_CanSelect数量为0
         {
             _DetachFromParent();
         }
     }
 }
Example #24
0
        public static IDockPane GetParent(IDockPane dockPane, IDockElement child)
        {
            Debug.Assert(dockPane != null);
            Debug.Assert(child != null);

            if (dockPane is IDockAnchorPane)
            {
                var dockAnchorPane = (IDockAnchorPane)dockPane;
                if (dockAnchorPane.ChildPane == child)
                {
                    return(dockAnchorPane);
                }

                if (dockAnchorPane.ChildPane != null)
                {
                    return(GetParent(dockAnchorPane.ChildPane, child));
                }
            }
            else if (dockPane is IDockSplitPane)
            {
                var dockSplitPane = (IDockSplitPane)dockPane;
                var childPane     = child as IDockPane;
                if (childPane != null && dockSplitPane.ChildPanes.Contains(childPane))
                {
                    return(dockSplitPane);
                }

                return(GetParent(dockSplitPane.ChildPanes, child));
            }
            else if (dockPane is IDockTabPane)
            {
                var dockTabPane = (IDockTabPane)dockPane;
                var dockTabItem = child as IDockTabItem;
                if (dockTabItem != null && dockTabPane.Items.Contains(dockTabItem))
                {
                    return(dockTabPane);
                }
            }

            return(null);
        }
Example #25
0
        internal void AddSideChild(IDockElement ele, DockSide side)
        {
            switch (side)
            {
            case DockSide.Left:
                LeftSide.Attach(ele);
                break;

            case DockSide.Right:
                RightSide.Attach(ele);
                break;

            case DockSide.Top:
                TopSide.Attach(ele);
                break;

            case DockSide.Bottom:
                BottomSide.Attach(ele);
                break;
            }
        }
Example #26
0
        /// <overloads>
        /// <summary>
        /// Gets the <see cref="IDockPane"/> which is the direct parent of the specified child
        /// element.
        /// </summary>
        /// </overloads>
        ///
        /// <summary>
        /// Gets the <see cref="IDockPane"/> which is the direct parent of the specified child
        /// element.
        /// </summary>
        /// <param name="dockControl">The <see cref="IDockControl"/>.</param>
        /// <param name="child">The child element.</param>
        /// <returns>
        /// The <see cref="IDockPane"/> which contains <paramref name="child"/> in its immediate
        /// children.
        /// </returns>
        public static IDockPane GetParent(IDockControl dockControl, IDockElement child)
        {
            if (dockControl == null)
            {
                throw new ArgumentNullException(nameof(dockControl));
            }
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            Debug.Assert(child != null);
            Debug.Assert(child.DockState != DockState.Hide);

            switch (child.DockState)
            {
            case DockState.Dock:
                return(GetParent(dockControl.RootPane, child));

            case DockState.Float:
                foreach (var floatWindow in dockControl.FloatWindows)
                {
                    var dockPane = GetParent(floatWindow.RootPane, child);
                    if (dockPane != null)
                    {
                        return(dockPane);
                    }
                }
                break;

            case DockState.AutoHide:
                return(GetParent(dockControl.AutoHideLeft, child)
                       ?? GetParent(dockControl.AutoHideRight, child)
                       ?? GetParent(dockControl.AutoHideTop, child)
                       ?? GetParent(dockControl.AutoHideBottom, child));
            }

            return(null);
        }
Example #27
0
        internal static bool Contains(this IDockPane dockPane, IDockElement dockElement)
        {
            Debug.Assert(dockPane != null);
            Debug.Assert(dockElement != null);

            if (dockPane == dockElement)
            {
                return(true);
            }

            if (dockPane is IDockAnchorPane)
            {
                var dockAnchorPane = (IDockAnchorPane)dockPane;
                if (dockAnchorPane.ChildPane != null)
                {
                    return(Contains(dockAnchorPane.ChildPane, dockElement));
                }
            }
            else if (dockPane is IDockSplitPane)
            {
                var dockSplitPane = (IDockSplitPane)dockPane;
                if (Contains(dockSplitPane.ChildPanes, dockElement))
                {
                    return(true);
                }
            }
            else if (dockPane is IDockTabPane)
            {
                var dockTabPane = (IDockTabPane)dockPane;
                var dockTabItem = dockElement as IDockTabItem;
                if (dockTabItem != null)
                {
                    return(dockTabPane.Items.Contains(dockTabItem));
                }
            }

            return(false);
        }
Example #28
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured)
     {
         if ((e.GetPosition(this) - _mouseDown).Length > Math.Max(SystemParameters.MinimumHorizontalDragDistance, SystemParameters.MinimumVerticalDragDistance))
         {
             ReleaseMouseCapture();
             IDockElement ele = DataContext as IDockElement;
             if (!ele.DockManager.DragManager.IsDragging)
             {
                 if (ele.Mode == DockMode.DockBar)
                 {
                     ele.DockManager.DragManager.IntoDragAction(new DragItem(ele, ele.Mode, DragMode.Anchor, _mouseDown, Rect.Empty, new Size(ele.DesiredWidth, ele.DesiredHeight)));
                 }
                 else
                 {
                     ele.DockManager.DragManager.IntoDragAction(new DragItem(ele.Container, ele.Mode, DragMode.Anchor, _mouseDown, Rect.Empty, new Size(ele.DesiredWidth, ele.DesiredHeight)));
                 }
             }
         }
     }
 }
        /// <inheritdoc/>
        protected override IDockPane OnGetDefaultDockTarget(IDockElement element)
        {
            // If a document has the focus, we dock new into its pane.
            if (DockControl.ActiveDockTabItem is DocumentViewModel)
            {
                return(DockControl.ActiveDockTabPane);
            }

            var dockAnchorPane = First <IDockAnchorPane>(DockControl.RootPane);

            if (dockAnchorPane != null)
            {
                // Search anchor pane first.
                // Use the tab pane that contains the first found document.
                var document = First <DocumentViewModel>(dockAnchorPane);
                if (document != null)
                {
                    return(DockHelper.GetParent(dockAnchorPane, document));
                }

                // No document found. Use the anchor pane.
                return(dockAnchorPane);
            }
            else
            {
                // No anchor pane found.
                // Use the tab pane that contains the first found document.
                var document = First <DocumentViewModel>(DockControl.RootPane);
                if (document != null)
                {
                    return(DockHelper.GetParent(DockControl.RootPane, document));
                }
            }

            // No anchor pane and no document found. Fall back to default behavior.
            return(base.OnGetDefaultDockTarget(element));
        }
        private static XElement Save(SerializationContext context, IDockElement dockElement)
        {
            if (dockElement == null)
            {
                return(null);
            }

            if (dockElement is IDockAnchorPane)
            {
                var pane        = (IDockAnchorPane)dockElement;
                var defaultPane = context.DefaultDockAnchorPane;

                var xElement = new XElement("DockAnchorPane");

                if (!pane.DockWidth.Equals(defaultPane.DockWidth))
                {
                    xElement.Add(new XAttribute("DockWidth", ConvertToString(pane.DockWidth)));
                }
                if (!pane.DockHeight.Equals(defaultPane.DockHeight))
                {
                    xElement.Add(new XAttribute("DockHeight", ConvertToString(pane.DockHeight)));
                }

                xElement.Add(Save(context, pane.ChildPane));

                return(xElement);
            }

            if (dockElement is IDockSplitPane)
            {
                var pane = (IDockSplitPane)dockElement;

                if (!ContainsItemsToSave(context, pane))
                {
                    return(null);
                }

                var defaultPane = context.DefaultDockSplitPane;

                XElement xElement = new XElement("DockSplitPane");

                if (!pane.DockWidth.Equals(defaultPane.DockWidth))
                {
                    xElement.Add(new XAttribute("DockWidth", ConvertToString(pane.DockWidth)));
                }
                if (!pane.DockHeight.Equals(defaultPane.DockHeight))
                {
                    xElement.Add(new XAttribute("DockHeight", ConvertToString(pane.DockHeight)));
                }
                if (pane.Orientation != defaultPane.Orientation)
                {
                    xElement.Add(new XAttribute("Orientation", pane.Orientation));
                }

                if (pane.ChildPanes != null)
                {
                    foreach (var childPane in pane.ChildPanes)
                    {
                        xElement.Add(Save(context, childPane));
                    }
                }

                return(xElement);
            }

            if (dockElement is IDockTabPane)
            {
                var pane = (IDockTabPane)dockElement;

                if (!ContainsItemsToSave(context, pane))
                {
                    return(null);
                }

                var defaultPane = context.DefaultDockTabPane;

                XElement xElement = new XElement("DockTabPane");

                if (!pane.DockWidth.Equals(defaultPane.DockWidth))
                {
                    xElement.Add(new XAttribute("DockWidth", ConvertToString(pane.DockWidth)));
                }
                if (!pane.DockHeight.Equals(defaultPane.DockHeight))
                {
                    xElement.Add(new XAttribute("DockHeight", ConvertToString(pane.DockHeight)));
                }

                if (pane.Items != null)
                {
                    if (pane.SelectedItem != null)
                    {
                        xElement.Add(new XAttribute("SelectedIndex", pane.Items.IndexOf(pane.SelectedItem)));
                    }

                    foreach (var item in pane.Items)
                    {
                        xElement.Add(Save(context, item, onlyReference: true));
                    }
                }

                return(xElement);
            }

            if (dockElement is IDockTabItem)
            {
                return(Save(context, (IDockTabItem)dockElement, onlyReference: true));
            }

            return(null);
        }
Example #31
0
        private static XElement Save(SerializationContext context, IDockElement dockElement)
        {
            if (dockElement == null)
                return null;

            if (dockElement is IDockAnchorPane)
            {
                var pane = (IDockAnchorPane)dockElement;
                var defaultPane = context.DefaultDockAnchorPane;

                var xElement = new XElement("DockAnchorPane");

                if (!pane.DockWidth.Equals(defaultPane.DockWidth))
                    xElement.Add(new XAttribute("DockWidth", ConvertToString(pane.DockWidth)));
                if (!pane.DockHeight.Equals(defaultPane.DockHeight))
                    xElement.Add(new XAttribute("DockHeight", ConvertToString(pane.DockHeight)));

                xElement.Add(Save(context, pane.ChildPane));

                return xElement;
            }

            if (dockElement is IDockSplitPane)
            {
                var pane = (IDockSplitPane)dockElement;

                if (!ContainsItemsToSave(context, pane))
                    return null;

                var defaultPane = context.DefaultDockSplitPane;

                XElement xElement = new XElement("DockSplitPane");

                if (!pane.DockWidth.Equals(defaultPane.DockWidth))
                    xElement.Add(new XAttribute("DockWidth", ConvertToString(pane.DockWidth)));
                if (!pane.DockHeight.Equals(defaultPane.DockHeight))
                    xElement.Add(new XAttribute("DockHeight", ConvertToString(pane.DockHeight)));
                if (pane.Orientation != defaultPane.Orientation)
                    xElement.Add(new XAttribute("Orientation", pane.Orientation));

                if (pane.ChildPanes != null)
                    foreach (var childPane in pane.ChildPanes)
                        xElement.Add(Save(context, childPane));

                return xElement;
            }

            if (dockElement is IDockTabPane)
            {
                var pane = (IDockTabPane)dockElement;

                if (!ContainsItemsToSave(context, pane))
                    return null;

                var defaultPane = context.DefaultDockTabPane;

                XElement xElement = new XElement("DockTabPane");

                if (!pane.DockWidth.Equals(defaultPane.DockWidth))
                    xElement.Add(new XAttribute("DockWidth", ConvertToString(pane.DockWidth)));
                if (!pane.DockHeight.Equals(defaultPane.DockHeight))
                    xElement.Add(new XAttribute("DockHeight", ConvertToString(pane.DockHeight)));

                if (pane.Items != null)
                {
                    if (pane.SelectedItem != null)
                        xElement.Add(new XAttribute("SelectedIndex", pane.Items.IndexOf(pane.SelectedItem)));

                    foreach (var item in pane.Items)
                        xElement.Add(Save(context, item, onlyReference: true));
                }

                return xElement;
            }

            if (dockElement is IDockTabItem)
            {
                return Save(context, (IDockTabItem)dockElement, onlyReference: true);
            }

            return null;
        }