コード例 #1
0
        public DockingManager()
        {
            Layout = new LayoutRoot() { RootPanel = new LayoutPanel(new LayoutDocumentPaneGroup(new LayoutDocumentPane())) };


            this.Loaded += new RoutedEventHandler(DockingManager_Loaded);
            this.Unloaded += new RoutedEventHandler(DockingManager_Unloaded);
        }
コード例 #2
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {
            if (anchorableToShow.Content is ITool)
            {
                var preferredLocation = ((ITool)anchorableToShow.Content).PreferredLocation;
                string paneName = GetPaneName(preferredLocation);
                var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == paneName);
                if (toolsPane == null)
                {
                    switch (preferredLocation)
                    {
                        case Dock.Left:
                            {
                                var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Horizontal);
                                toolsPane = new LayoutAnchorablePane { DockWidth = new GridLength(200, GridUnitType.Pixel) };
                                parent.InsertChildAt(0, toolsPane);
                            }
                            break;
                        case Dock.Right:
                            {
                                var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Horizontal);
                                toolsPane = new LayoutAnchorablePane { DockWidth = new GridLength(200, GridUnitType.Pixel) };
                                parent.Children.Add(toolsPane);
                            }
                            break;
                        case Dock.Bottom:
                            {
                                var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Vertical);
                                toolsPane = new LayoutAnchorablePane { DockHeight = new GridLength(200, GridUnitType.Pixel) };
                                parent.Children.Add(toolsPane);
                            }
                            break;
                        case Dock.Top:
                            {
                                var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Vertical);
                                toolsPane = new LayoutAnchorablePane { DockHeight = new GridLength(200, GridUnitType.Pixel) };
                                parent.InsertChildAt(0, toolsPane);
                            }
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                toolsPane.Children.Add(anchorableToShow);
                return true;
            }

            return false;
        }
コード例 #3
0
ファイル: LayoutInitializer.cs プロジェクト: vinodj/Wide
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow,
                                           ILayoutContainer destinationContainer)
        {
            var destPane = destinationContainer as LayoutAnchorablePane;
            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
                return false;

            LayoutAnchorablePane toolsPane =
                layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(
                    d => d.GetType() == typeof (IContentView));
            if (toolsPane != null)
            {
                toolsPane.Children.Add(anchorableToShow);
                return true;
            }

            return false;
        }
コード例 #4
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {
            //AD wants to add the anchorable into destinationContainer
            //just for test provide a new anchorablepane
            //if the pane is floating let the manager go ahead
            LayoutAnchorablePane destPane = destinationContainer as LayoutAnchorablePane;
            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
                return false;

            var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "ToolsPane");
            if (toolsPane != null)
            {
                toolsPane.Children.Add(anchorableToShow);
                return true;
            }

            return false;
        }
コード例 #5
0
        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 as ILayoutContainer).RemoveChild(
                    documentToRemove);
            }

            var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
            if (documentsSourceAsNotifier != null)
                documentsSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
        }
コード例 #6
0
        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 as ILayoutContainer).RemoveChild(
                    anchorableToRemove);
            }

            var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
            if (anchorablesSourceAsNotifier != null)
                anchorablesSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
        }
コード例 #7
0
        void AttachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
        {
            if (documentsSource == null)
                return;

            if (layout == null)
                return;

            //if (layout.Descendents().OfType<LayoutDocument>().Any())
            //    throw new InvalidOperationException("Unable to set the DocumentsSource property if LayoutDocument objects are already present in the model");
            var documentsImported = layout.Descendents().OfType<LayoutDocument>().Select(d => d.Content).ToArray();
            var documents = documentsSource as IEnumerable;
            var listOfDocumentsToImport = new List<object>(documents.OfType<object>());

            foreach (var document in listOfDocumentsToImport.ToArray())
            {
                if (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();
            }

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

            _suspendLayoutItemCreation = true;
            foreach (var documentContentToImport in listOfDocumentsToImport)
            {

                //documentPane.Children.Add(new LayoutDocument() { Content = documentToImport });

                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);
                    added = true;
                }

                if (LayoutUpdateStrategy != null)
                    LayoutUpdateStrategy.AfterInsertDocument(layout, documentToImport);

                CreateDocumentLayoutItem(documentToImport);

            }
            _suspendLayoutItemCreation = true;

            var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
            if (documentsSourceAsNotifier != null)
                documentsSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
        }
コード例 #8
0
        void AttachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
        {
            if (anchorablesSource == null)
                return;

            if (layout == null)
                return;

            //if (layout.Descendents().OfType<LayoutAnchorable>().Any())
            //    throw new InvalidOperationException("Unable to set the AnchorablesSource property if LayoutAnchorable objects are already present in the model");
            var anchorablesImported = layout.Descendents().OfType<LayoutAnchorable>().Select(d => d.Content).ToArray();
            var anchorables = anchorablesSource as IEnumerable;
            var listOfAnchorablesToImport = new List<object>(anchorables.OfType<object>());

            foreach (var document in listOfAnchorablesToImport.ToArray())
            {
                if (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>().Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right).FirstOrDefault();
            }

            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);
                    added = true;
                }

                if (LayoutUpdateStrategy != null)
                    LayoutUpdateStrategy.AfterInsertAnchorable(layout, anchorableToImport);

                CreateAnchorableLayoutItem(anchorableToImport);

            }

            _suspendLayoutItemCreation = false;

            var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
            if (anchorablesSourceAsNotifier != null)
                anchorablesSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
        }
コード例 #9
0
        /// <summary>
        /// Provides derived classes an opportunity to handle changes to the <see cref="DockingManager.Layout"/> property.
        /// </summary>
        protected virtual void OnLayoutChanged(LayoutRoot oldLayout, LayoutRoot newLayout)
        {
            if (oldLayout != null)
            {
                oldLayout.PropertyChanged -= new PropertyChangedEventHandler(OnLayoutRootPropertyChanged);
                oldLayout.Updated -= new EventHandler(OnLayoutRootUpdated);
            }

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

            _fwList.Clear();

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

            if (oldLayout != null &&
                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())
                {
                    if (fw.IsValid)
                       _fwList.Add(CreateUIElementForModel(fw) as LayoutFloatingWindowControl);
                }

                foreach (var fw in _fwList)
                {
                    //fw.Owner = Window.GetWindow(this);
                    //fw.SetParentToMainWindowOf(this);
                }
            }

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

            if (LayoutChanged != null)
                LayoutChanged(this, EventArgs.Empty);

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

            CommandManager.InvalidateRequerySuggested();
        }
コード例 #10
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();
                            previousContainer.DockMinWidth = this.AutoHideMinWidth;
                            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();
                            previousContainer.DockMinWidth = this.AutoHideMinWidth;
                            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();
                            previousContainer.DockMinHeight = this.AutoHideMinHeight;
                            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();
                            previousContainer.DockMinHeight = this.AutoHideMinHeight;
                            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;
                    }
                }
                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);

                var parent = previousContainer.Parent as LayoutGroupBase;
                while ((parent != null))
                {
                    if (parent is LayoutGroup <ILayoutPanelElement> )
                    {
                        ((LayoutGroup <ILayoutPanelElement>)parent).ComputeVisibility();
                    }
                    parent = parent.Parent as LayoutGroupBase;
                }
            }
            #endregion

            #region Anchorable is docked
            else if (Parent is LayoutAnchorablePane)
            {
                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:
                    if (root.RightSide != null)
                    {
                        root.RightSide.Children.Add(newAnchorGroup);
                    }
                    break;

                case AnchorSide.Left:
                    if (root.LeftSide != null)
                    {
                        root.LeftSide.Children.Add(newAnchorGroup);
                    }
                    break;

                case AnchorSide.Top:
                    if (root.TopSide != null)
                    {
                        root.TopSide.Children.Add(newAnchorGroup);
                    }
                    break;

                case AnchorSide.Bottom:
                    if (root.BottomSide != null)
                    {
                        root.BottomSide.Children.Add(newAnchorGroup);
                    }
                    break;
                }
            }
            #endregion
        }
コード例 #11
0
        private object ReadElement(XmlReader reader)
        {
            while (reader.NodeType == XmlNodeType.Whitespace)
            {
                reader.Read();
            }

            if (reader.NodeType == XmlNodeType.EndElement)
            {
                return(null);
            }

            XmlSerializer serializer;

            switch (reader.LocalName)
            {
            case "LayoutAnchorablePaneGroup":
                serializer = new XmlSerializer(typeof(LayoutAnchorablePaneGroup));
                break;

            case "LayoutAnchorablePane":
                serializer = new XmlSerializer(typeof(LayoutAnchorablePane));
                break;

            case "LayoutAnchorable":
                serializer = new XmlSerializer(typeof(LayoutAnchorable));
                break;

            case "LayoutDocumentPaneGroup":
                serializer = new XmlSerializer(typeof(LayoutDocumentPaneGroup));
                break;

            case "LayoutDocumentPane":
                serializer = new XmlSerializer(typeof(LayoutDocumentPane));
                break;

            case "LayoutDocument":
                serializer = new XmlSerializer(typeof(LayoutDocument));
                break;

            case "LayoutAnchorGroup":
                serializer = new XmlSerializer(typeof(LayoutAnchorGroup));
                break;

            case "LayoutPanel":
                serializer = new XmlSerializer(typeof(LayoutPanel));
                break;

            case "LayoutDocumentFloatingWindow":
                serializer = new XmlSerializer(typeof(LayoutDocumentFloatingWindow));
                break;

            case "LayoutAnchorableFloatingWindow":
                serializer = new XmlSerializer(typeof(LayoutAnchorableFloatingWindow));
                break;

            case "LeftSide":
            case "RightSide":
            case "TopSide":
            case "BottomSide":
                if (reader.IsEmptyElement)
                {
                    reader.Read();
                    return(null);
                }
                return(reader.Read());

            default:
                var type = LayoutRoot.FindType(reader.LocalName);
                if (type == null)
                {
                    throw new ArgumentException("AvalonDock.LayoutRoot doesn't know how to deserialize " + reader.LocalName);
                }
                serializer = new XmlSerializer(type);
                break;
            }

            return(serializer.Deserialize(reader));
        }
コード例 #12
0
 void OnLayoutChanging(LayoutRoot newLayout)
 {
 }
コード例 #13
0
ファイル: LayoutInitializer.cs プロジェクト: vinodj/Wide
 public bool BeforeInsertDocument(LayoutRoot layout, LayoutDocument anchorableToShow,
                                  ILayoutContainer destinationContainer)
 {
     return false;
 }
コード例 #14
0
 void OnLayoutChanging(LayoutRoot newLayout)
 {
     if (LayoutChanging != null)
         LayoutChanging(this, EventArgs.Empty);
 }
コード例 #15
0
 public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
 {
 }
コード例 #16
0
 public LayoutEventArgs(LayoutRoot layoutRoot)
 {
     LayoutRoot = layoutRoot;
 }
コード例 #17
0
ファイル: LayoutInitializer.cs プロジェクト: vinodj/Wide
 public void AfterInsertDocument(LayoutRoot layout, LayoutDocument anchorableShown)
 {
 }