public DockingManager()
 {
     Layout = new LayoutRoot
     {
         RootPanel = new LayoutPanel(new LayoutDocumentPaneGroup(new LayoutDocumentPane()))
     };
     Loaded += DockingManager_Loaded;
     Unloaded += DockingManager_Unloaded;
 }
Beispiel #2
0
        public void ToggleAutoHide()
        {
            #region Anchorable is already auto hidden
            if (IsAutoHidden)
            {
                var parentGroup = Parent as LayoutAnchorGroup;
                if (parentGroup != null)
                {
                    var parentSide        = parentGroup.Parent as LayoutAnchorSide;
                    var previousContainer = ((ILayoutPreviousContainer)parentGroup).PreviousContainer as LayoutAnchorablePane;

                    if (previousContainer == null)
                    {
                        var layoutAnchorSide = parentGroup.Parent as LayoutAnchorSide;
                        if (layoutAnchorSide != null)
                        {
                            AnchorSide side = 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;
                                    if (root != null)
                                    {
                                        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;
                                    if (root != null)
                                    {
                                        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;
                                    if (root != null)
                                    {
                                        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;
                                    if (root != null)
                                    {
                                        root.RootPanel = panel;
                                    }
                                    panel.Children.Add(oldRootPanel);
                                    panel.Children.Add(previousContainer);
                                }
                                break;
                            }
                        }
                    }
                    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 => Equals(c.PreviousContainer, parentGroup)))
                        {
                            cnt.PreviousContainer = previousContainer;
                        }
                    }


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

                    parentSide?.Children.Remove(parentGroup);
                }
            }
            #endregion
            #region Anchorable is docked
            else
            {
                var pane = Parent as LayoutAnchorablePane;
                if (pane == null)
                {
                    return;
                }
                var root       = Root;
                var parentPane = pane;

                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);
                    break;

                case AnchorSide.Left:
                    root.LeftSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Top:
                    root.TopSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Bottom:
                    root.BottomSide.Children.Add(newAnchorGroup);
                    break;
                }
            }

            #endregion
        }
        private void DetachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
        {
            if (documentsSource == null)
                return;

            if (layout == null)
                return;

            var documentsToRemove = layout.Descendents().OfType<LayoutDocument>()
                .Where(d => documentsSource.Contains(d.Content)).ToArray();

            foreach (var documentToRemove in documentsToRemove)
            {
                documentToRemove.Parent.RemoveChild(
                    documentToRemove);
            }

            var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
            if (documentsSourceAsNotifier != null)
                documentsSourceAsNotifier.CollectionChanged -= DocumentsSourceElementsChanged;
        }
 // ReSharper disable once UnusedParameter.Local
 private void OnLayoutChanging(LayoutRoot newLayout)
 {
     LayoutChanging?.Invoke(this, EventArgs.Empty);
 }
        private void DetachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
        {
            if (anchorablesSource == null)
                return;

            if (layout == null)
                return;

            var anchorablesToRemove = layout.Descendents().OfType<LayoutAnchorable>()
                .Where(d => anchorablesSource.Contains(d.Content)).ToArray();

            foreach (var anchorableToRemove in anchorablesToRemove)
            {
                anchorableToRemove.Parent.RemoveChild(
                    anchorableToRemove);
            }

            var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
            if (anchorablesSourceAsNotifier != null)
                anchorablesSourceAsNotifier.CollectionChanged -= AnchorablesSourceElementsChanged;
        }
        private void AttachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
        {
            if (documentsSource == null)
                return;

            if (layout == null)
                return;

            var documentsImported = layout.Descendents().OfType<LayoutDocument>().Select(d => d.Content).ToArray();
            var documents = documentsSource;
            var listOfDocumentsToImport = new List<object>(documents.OfType<object>());

            foreach (var document in listOfDocumentsToImport.ToArray().Where(document => documentsImported.Contains(document)))
            {
                listOfDocumentsToImport.Remove(document);
            }

            LayoutDocumentPane documentPane = null;
            if (layout.LastFocusedDocument != null)
            {
                documentPane = layout.LastFocusedDocument.Parent as LayoutDocumentPane;
            }

            if (documentPane == null)
            {
                documentPane = layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
            }

            _suspendLayoutItemCreation = true;
            foreach (var documentContentToImport in listOfDocumentsToImport)
            {
                var documentToImport = new LayoutDocument()
                {
                    Content = documentContentToImport
                };

                bool added = false;
                if (LayoutUpdateStrategy != null)
                {
                    added = LayoutUpdateStrategy.BeforeInsertDocument(layout, documentToImport, documentPane);
                }

                if (!added)
                {
                    if (documentPane == null)
                        throw new InvalidOperationException(
                            "Layout must contains at least one LayoutDocumentPane in order to host documents");

                    documentPane.Children.Add(documentToImport);
                }

                LayoutUpdateStrategy?.AfterInsertDocument(layout, documentToImport);

                CreateDocumentLayoutItem(documentToImport);
            }
            _suspendLayoutItemCreation = true;

            var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
            if (documentsSourceAsNotifier != null)
                documentsSourceAsNotifier.CollectionChanged += DocumentsSourceElementsChanged;
        }
        private void AttachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
        {
            if (anchorablesSource == null)
                return;

            if (layout == null)
                return;

            var anchorablesImported = layout.Descendents().OfType<LayoutAnchorable>().Select(d => d.Content).ToArray();
            var anchorables = anchorablesSource;
            var listOfAnchorablesToImport = new List<object>(anchorables.OfType<object>());

            foreach (
                var document in listOfAnchorablesToImport.ToArray().Where(document => anchorablesImported.Contains(document)))
            {
                listOfAnchorablesToImport.Remove(document);
            }

            LayoutAnchorablePane anchorablePane = null;
            if (layout.ActiveContent != null)
            {
                //look for active content parent pane
                anchorablePane = layout.ActiveContent.Parent as LayoutAnchorablePane;
            }

            if (anchorablePane == null)
            {
                //look for a pane on the right side
                anchorablePane =
                    layout.Descendents()
                        .OfType<LayoutAnchorablePane>()
                        .FirstOrDefault(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right);
            }

            if (anchorablePane == null)
            {
                //look for an available pane
                anchorablePane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault();
            }

            _suspendLayoutItemCreation = true;
            foreach (var anchorableContentToImport in listOfAnchorablesToImport)
            {
                var anchorableToImport = new LayoutAnchorable()
                {
                    Content = anchorableContentToImport
                };

                bool added = false;
                if (LayoutUpdateStrategy != null)
                {
                    added = LayoutUpdateStrategy.BeforeInsertAnchorable(layout, anchorableToImport, anchorablePane);
                }

                if (!added)
                {
                    if (anchorablePane == null)
                    {
                        var mainLayoutPanel = new LayoutPanel { Orientation = Orientation.Horizontal };
                        if (layout.RootPanel != null)
                        {
                            mainLayoutPanel.Children.Add(layout.RootPanel);
                        }

                        layout.RootPanel = mainLayoutPanel;
                        anchorablePane = new LayoutAnchorablePane
                        {
                            DockWidth = new GridLength(200.0, GridUnitType.Pixel)
                        };
                        mainLayoutPanel.Children.Add(anchorablePane);
                    }

                    anchorablePane.Children.Add(anchorableToImport);
                }
                LayoutUpdateStrategy?.AfterInsertAnchorable(layout, anchorableToImport);
                CreateAnchorableLayoutItem(anchorableToImport);
            }

            _suspendLayoutItemCreation = false;

            var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
            if (anchorablesSourceAsNotifier != null)
                anchorablesSourceAsNotifier.CollectionChanged += AnchorablesSourceElementsChanged;
        }
        protected virtual void OnLayoutChanged(LayoutRoot oldLayout, LayoutRoot newLayout)
        {
            if (oldLayout != null)
            {
                oldLayout.PropertyChanged -= OnLayoutRootPropertyChanged;
                oldLayout.Updated -= OnLayoutRootUpdated;
            }

            foreach (var fwc in _fwList.ToArray())
            {
                fwc.KeepContentVisibleOnClose = true;
                fwc.InternalClose();
            }

            _fwList.Clear();

            DetachDocumentsSource(oldLayout, DocumentsSource);
            DetachAnchorablesSource(oldLayout, AnchorablesSource);

            if (oldLayout != null &&
                Equals(oldLayout.Manager, this))
                oldLayout.Manager = null;

            ClearLogicalChildrenList();
            DetachLayoutItems();

            Layout.Manager = this;

            AttachLayoutItems();
            AttachDocumentsSource(newLayout, DocumentsSource);
            AttachAnchorablesSource(newLayout, AnchorablesSource);

            if (IsLoaded)
            {
                LayoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
                LeftSidePanel = CreateUIElementForModel(Layout.LeftSide) as LayoutAnchorSideControl;
                TopSidePanel = CreateUIElementForModel(Layout.TopSide) as LayoutAnchorSideControl;
                RightSidePanel = CreateUIElementForModel(Layout.RightSide) as LayoutAnchorSideControl;
                BottomSidePanel = CreateUIElementForModel(Layout.BottomSide) as LayoutAnchorSideControl;

                foreach (var fw in Layout.FloatingWindows.ToArray().Where(fw => fw.IsValid))
                {
                    _fwList.Add(CreateUIElementForModel(fw) as LayoutFloatingWindowControl);
                }
            }

            if (newLayout != null)
            {
                newLayout.PropertyChanged += OnLayoutRootPropertyChanged;
                newLayout.Updated += OnLayoutRootUpdated;
            }

            LayoutChanged?.Invoke(this, EventArgs.Empty);

            //if (Layout != null)
            //    Layout.CollectGarbage();

            CommandManager.InvalidateRequerySuggested();
        }
 public LayoutEventArgs(LayoutRoot layoutRoot)
 {
     LayoutRoot = layoutRoot;
 }