Esempio n. 1
0
        /*
         * public void RemoveSide()
         * {
         *  if (Parent is LayoutAnchorGroup)
         *  {
         *      ILayoutRoot root = Root;
         *      LayoutAnchorGroup lagroup = (LayoutAnchorGroup)(Parent);
         *      if (root.RightSide.Children.Contains(lagroup))
         *      {
         *          root.RightSide.Children.Remove(lagroup);
         *      }
         *      if (root.LeftSide.Children.Contains(lagroup))
         *      {
         *          root.LeftSide.Children.Remove(lagroup);
         *      }
         *      if (root.TopSide.Children.Contains(lagroup))
         *      {
         *          root.TopSide.Children.Remove(lagroup);
         *      }
         *      if (root.BottomSide.Children.Contains(lagroup))
         *      {
         *          root.BottomSide.Children.Remove(lagroup);
         *      }
         *      lagroup.Parent = (ILayoutContainer)(root);
         *  }
         * }
         */
        public void ReplaceSide(AnchorSide side)
        {
            if (Parent is LayoutAnchorGroup)
            {
                ILayoutRoot       root    = Root;
                LayoutAnchorGroup lagroup = (LayoutAnchorGroup)(Parent);
                if (root.RightSide.Children.Contains(lagroup))
                {
                    root.RightSide.Children.Remove(lagroup);
                }
                if (root.LeftSide.Children.Contains(lagroup))
                {
                    root.LeftSide.Children.Remove(lagroup);
                }
                if (root.TopSide.Children.Contains(lagroup))
                {
                    root.TopSide.Children.Remove(lagroup);
                }
                if (root.BottomSide.Children.Contains(lagroup))
                {
                    root.BottomSide.Children.Remove(lagroup);
                }
                switch (side)
                {
                case AnchorSide.Right:
                    root.RightSide.Children.Add(lagroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "RIGHT");
                    break;

                case AnchorSide.Left:
                    root.LeftSide.Children.Add(lagroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "LEFT");
                    break;

                case AnchorSide.Top:
                    root.TopSide.Children.Add(lagroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "TOP");
                    break;

                case AnchorSide.Bottom:
                    root.BottomSide.Children.Add(lagroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "BOTTOM");
                    break;
                }
            }
        }
Esempio n. 2
0
        public void ToggleAutoHide()
        {
            #region Anchorable is already auto hidden
            if (IsAutoHidden)
            {
                var parentGroup       = Parent as LayoutAnchorGroup;
                var parentSide        = parentGroup.Parent as LayoutAnchorSide;
                var previousContainer = ((ILayoutPreviousContainer)parentGroup).PreviousContainer as LayoutAnchorablePane;

                if (previousContainer == null)
                {
                    AnchorSide side = (parentGroup.Parent as LayoutAnchorSide).Side;
                    switch (side)
                    {
                    case AnchorSide.Right:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;

                    case AnchorSide.Left:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Top:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Bottom:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;
                    }
                    // Do something about initializing the docks of previousContainer
                    GridLength[] defaultdock = LayoutSetting.GetDefaultDockAnchorable(Title);
                    previousContainer.DockWidth  = defaultdock[0];
                    previousContainer.DockHeight = defaultdock[1];
                }
                else
                {
                    //I'm about to remove parentGroup, redirect any content (ie hidden contents) that point to it
                    //to previousContainer
                    LayoutRoot root = parentGroup.Root as LayoutRoot;
                    foreach (var cnt in root.Descendents().OfType <ILayoutPreviousContainer>().Where(c => c.PreviousContainer == parentGroup))
                    {
                        cnt.PreviousContainer = previousContainer;
                    }
                }

                foreach (var anchorableToToggle in parentGroup.Children.ToArray())
                {
                    previousContainer.Children.Add(anchorableToToggle);
                }

                parentSide.Children.Remove(parentGroup);
                IsDock = true;
            }
            #endregion
            #region Anchorable is docked
            else if (Parent is LayoutAnchorablePane)
            {
                IsActive = false;
                IsDock   = false;
                IsFloat  = false;

                var root       = Root;
                var parentPane = Parent as LayoutAnchorablePane;

                var newAnchorGroup = new LayoutAnchorGroup();

                ((ILayoutPreviousContainer)newAnchorGroup).PreviousContainer = parentPane;

                foreach (var anchorableToImport in parentPane.Children.ToArray())
                {
                    newAnchorGroup.Children.Add(anchorableToImport);
                }

                //detect anchor side for the pane
                var anchorSide = parentPane.GetSide();

                switch (anchorSide)
                {
                case AnchorSide.Right:
                    root.RightSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "RIGHT");
                    break;

                case AnchorSide.Left:
                    root.LeftSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "LEFT");
                    break;

                case AnchorSide.Top:
                    root.TopSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "TOP");
                    break;

                case AnchorSide.Bottom:
                    root.BottomSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "BOTTOM");
                    break;
                }
            }
            #endregion
        }
Esempio n. 3
0
        /// <summary>
        /// Add the anchorable to a DockingManager layout
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="strategy"></param>
        public void AddToLayout(DockingManager manager, AnchorableShowStrategy strategy)
        {
            if (IsVisible ||
                IsHidden)
            {
                throw new InvalidOperationException();
            }


            bool most   = (strategy & AnchorableShowStrategy.Most) == AnchorableShowStrategy.Most;
            bool left   = (strategy & AnchorableShowStrategy.Left) == AnchorableShowStrategy.Left;
            bool right  = (strategy & AnchorableShowStrategy.Right) == AnchorableShowStrategy.Right;
            bool top    = (strategy & AnchorableShowStrategy.Top) == AnchorableShowStrategy.Top;
            bool bottom = (strategy & AnchorableShowStrategy.Bottom) == AnchorableShowStrategy.Bottom;

            if (!most)
            {
                var side = AnchorSide.Left;
                if (left)
                {
                    side = AnchorSide.Left;
                }
                if (right)
                {
                    side = AnchorSide.Right;
                }
                if (top)
                {
                    side = AnchorSide.Top;
                }
                if (bottom)
                {
                    side = AnchorSide.Bottom;
                }

                var anchorablePane = manager.Layout.Descendents().OfType <LayoutAnchorablePane>().FirstOrDefault(p => p.GetSide() == side);
                if (anchorablePane != null)
                {
                    anchorablePane.Children.Add(this);
                }
                else
                {
                    most = true;
                }
            }


            if (most)
            {
                if (manager.Layout.RootPanel == null)
                {
                    manager.Layout.RootPanel = new LayoutPanel()
                    {
                        Orientation = (left || right ? Orientation.Horizontal : Orientation.Vertical)
                    }
                }
                ;

                if (left || right)
                {
                    if (manager.Layout.RootPanel.Orientation == Orientation.Vertical &&
                        manager.Layout.RootPanel.ChildrenCount > 1)
                    {
                        manager.Layout.RootPanel = new LayoutPanel(manager.Layout.RootPanel);
                    }

                    manager.Layout.RootPanel.Orientation = Orientation.Horizontal;

                    if (left)
                    {
                        manager.Layout.RootPanel.Children.Insert(0, new LayoutAnchorablePane(this));
                    }
                    else
                    {
                        manager.Layout.RootPanel.Children.Add(new LayoutAnchorablePane(this));
                    }
                }
                else
                {
                    if (manager.Layout.RootPanel.Orientation == Orientation.Horizontal &&
                        manager.Layout.RootPanel.ChildrenCount > 1)
                    {
                        manager.Layout.RootPanel = new LayoutPanel(manager.Layout.RootPanel);
                    }

                    manager.Layout.RootPanel.Orientation = Orientation.Vertical;

                    if (top)
                    {
                        manager.Layout.RootPanel.Children.Insert(0, new LayoutAnchorablePane(this));
                    }
                    else
                    {
                        manager.Layout.RootPanel.Children.Add(new LayoutAnchorablePane(this));
                    }
                }
            }

            if (left)
            {
                LayoutSetting.AddDefaultSideAnchorable(Title, "LEFT");
            }
            if (right)
            {
                LayoutSetting.AddDefaultSideAnchorable(Title, "RIGHT");
            }
            if (top)
            {
                LayoutSetting.AddDefaultSideAnchorable(Title, "TOP");
            }
            if (bottom)
            {
                LayoutSetting.AddDefaultSideAnchorable(Title, "BOTTOM");
            }
        }