Пример #1
0
        /// <summary>
        /// Show a dockable content in its container with a desidered state
        /// </summary>
        /// <param name="content">Content to show</param>
        /// <param name="desideredState">State desidered</param>
        /// <param name="desideredAnchor">Border to which anchor the newly created container pane</param>
        /// <remarks></remarks>
        internal void Show(DockableContent content, DockableContentState desideredState, AnchorStyle desideredAnchor)
        {
            Debug.WriteLine(string.Format("Show Content={0}, desideredState={1}, desideredAnchor={2}", content.Name, desideredState, desideredAnchor));

            #region Dockable content

            if (desideredState == DockableContentState.Hidden)//??!!show hidden?
                Hide(content);

            if (content.State == DockableContentState.AutoHide)
            {
                //first redock the content
                (content.ContainerPane as DockablePane).ToggleAutoHide();
                //then show it as desidered
                Show(content, desideredState, desideredAnchor);
            }
            else if (content.State == DockableContentState.Docked ||
                content.State == DockableContentState.Document ||
                content.State == DockableContentState.None)
            {
                if (content.ContainerPane == null ||
                    content.State == DockableContentState.None)
                {
                    //Problem!? try to rescue
                    if (content.State == DockableContentState.Docked ||
                        content.State == DockableContentState.None)
                    {
                        //find the the pane which the desidered anchor style
                        //DockablePane foundPane = this.FindChildDockablePane(desideredAnchor != AnchorStyle.None ? desideredAnchor : AnchorStyle.Right);
                        //first search for a pane with other contents (avoiding empty panes which are containers for hidden contents)
                        ILinqToTree<DependencyObject> itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).IsDocked);

                        if (itemFound == null)//search for all panes (even empty)
                            itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).Items.Count == 0);

                        DockablePane foundPane = itemFound != null ? itemFound.Item as DockablePane : null;

                        if (foundPane != null)
                        {
                            content.SetStateToDock();
                            foundPane.Items.Add(content);
                            var containerPanel = foundPane.Parent as ResizingPanel;
                            if (containerPanel != null)
                                containerPanel.InvalidateMeasure();
                        }
                        else
                        {
                            //if no suitable pane was found create e new one on the fly
                            if (content.ContainerPane != null)
                            {
                                content.ContainerPane.RemoveContent(content);
                            }

                            DockablePane pane = new DockablePane();
                            pane.Items.Add(content);
                            Anchor(pane, desideredAnchor);
                        }
                    }
                    else
                    {
                        //add to main document pane
                        MainDocumentPane.Items.Add(content);
                    }

                }

                if (content.ContainerPane.GetManager() == null)
                {
                    //disconnect the parent pane from previous panel
                    //((Panel)content.ContainerPane.Parent).Children.Remove(content.ContainerPane);
                    if (content.ContainerPane.Parent != null)
                    {
                        ((Panel)content.ContainerPane.Parent).Children.Remove(content.ContainerPane);
                    }

                    Anchor(content.ContainerPane as DockablePane, desideredAnchor);
                }

                if (desideredState == DockableContentState.DockableWindow ||
                     desideredState == DockableContentState.FloatingWindow)
                {
                    var floatingWindow = new DockableFloatingWindow(this);
                    floatingWindow.Content = content;

                    var mainWindow = Window.GetWindow(this);
                    if (mainWindow.IsVisible)
                        floatingWindow.Owner = mainWindow;

                    //floatingWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    //if (content.Content != null)
                    //{
                    //    floatingWindow.Width = Math.Min(((FrameworkElement)content.Content).ActualWidth, ResizingPanel.GetResizeWidth(content.ContainerPane));
                    //    floatingWindow.Height = Math.Min(((FrameworkElement)content.Content).ActualHeight, ResizingPanel.GetResizeHeight(content.ContainerPane));
                    //}
                    //else
                    ////{
                    //    floatingWindow.Width = 400;
                    //    floatingWindow.Height = 400;
                    //}

                    floatingWindow.Show();

                }
                else if (desideredState == DockableContentState.AutoHide)
                {
                    var paneContainer = content.ContainerPane as DockablePane;
                    Debug.Assert(paneContainer != null);

                    if (paneContainer != null)
                        paneContainer.ToggleAutoHide();

                    content.Activate();
                }
                else if (desideredState == DockableContentState.Document)
                {
                    DocumentPane docPane = MainDocumentPane;
                    if (docPane != null)
                    {
                        docPane.Items.Add(content.DetachFromContainerPane());
                        docPane.SelectedItem = content;
                        content.SetStateToDocument();
                    }
                }
                else
                {
                    content.ContainerPane.SelectedItem = content;
                    content.Activate();

                    DockablePane dockParent = content.ContainerPane as DockablePane;
                    if (content.ActualWidth == 0.0 && (
                        dockParent.Anchor == AnchorStyle.Left || dockParent.Anchor == AnchorStyle.Right))
                    {
                        ResizingPanel.SetResizeWidth(dockParent, new GridLength(200));
                        ResizingPanel.SetEffectiveSize(dockParent, new Size(200, 0.0));
                    }
                    else if (content.ActualWidth == 0.0 && (
                        dockParent.Anchor == AnchorStyle.Top || dockParent.Anchor == AnchorStyle.Bottom))
                    {
                        ResizingPanel.SetResizeHeight(dockParent, new GridLength(200));
                        ResizingPanel.SetEffectiveSize(dockParent, new Size(200, 0.0));
                    }

                }
            }
            else if (content.State == DockableContentState.Document)
            {
                if (content.ContainerPane != null)
                    content.ContainerPane.SelectedItem = this;
                content.Activate();
            }
            else if (content.State == DockableContentState.Hidden ||
                content.State == DockableContentState.DockableWindow ||
                content.State == DockableContentState.FloatingWindow)
            {
                if (content.State == DockableContentState.Hidden)
                {
                    //Debug.Assert(HiddenContents.Contains(content));
                    //HiddenContents.Remove(content);
                }
                else
                {
                    FloatingWindow floatingWindow = null;
                    floatingWindow = (content.ContainerPane as FloatingDockablePane).FloatingWindow;
                    content.DetachFromContainerPane();

                    if (floatingWindow.HostedPane.Items.Count == 0)
                        floatingWindow.Close();
                }

                if (desideredState == DockableContentState.Docked ||
                    desideredState == DockableContentState.AutoHide)
                {

                    if (content.SavedStateAndPosition != null &&
                        content.SavedStateAndPosition.ContainerPane != null &&
                        content.SavedStateAndPosition.ChildIndex >= 0 &&
                        content.SavedStateAndPosition.ContainerPane.GetManager() == this &&
                        desideredState == DockableContentState.Docked)
                    {
                        //ok previous container pane is here..
                        Pane prevPane = content.SavedStateAndPosition.ContainerPane;

                        if (content.SavedStateAndPosition.ChildIndex < prevPane.Items.Count)
                        {
                            prevPane.Items.Insert(content.SavedStateAndPosition.ChildIndex, content);
                        }
                        else
                        {
                            prevPane.Items.Add(content);
                        }

                        if (prevPane.Items.Count == 1)
                        {
                            if (!double.IsNaN(content.SavedStateAndPosition.Width) ||
                                !double.IsInfinity(content.SavedStateAndPosition.Width))
                            {
                                ResizingPanel.SetResizeWidth(content,
                                    new GridLength(content.SavedStateAndPosition.Width));
                            }
                        }

                        DockablePane prevDockablePane = prevPane as DockablePane;
                        if (prevDockablePane != null && prevDockablePane.IsAutoHidden)
                        {
                            prevDockablePane.ToggleAutoHide();
                        }

                        content.SetStateToDock();
                        content.Activate();

                        (prevPane.Parent as UIElement).InvalidateMeasure();
                    }
                    else
                    {
                        if (desideredAnchor == AnchorStyle.None &&
                            content.SavedStateAndPosition != null &&
                            content.SavedStateAndPosition.Anchor != AnchorStyle.None)
                            desideredAnchor = content.SavedStateAndPosition.Anchor;

                        if (desideredAnchor == AnchorStyle.None)
                            desideredAnchor = AnchorStyle.Right;

                        DockablePane foundPane = null;

                        if (desideredState == DockableContentState.Docked)
                        {
                            //first not empty panes
                            ILinqToTree<DependencyObject> itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).IsDocked);

                            if (itemFound == null)//look for all panes even empty
                                itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).Items.Count == 0);

                            foundPane = itemFound != null ? itemFound.Item as DockablePane : null;
                        }

                        if (foundPane != null)
                        {
                            content.SetStateToDock();
                            foundPane.Items.Add(content);

                            if ((foundPane.IsAutoHidden && desideredState == DockableContentState.Docked) ||
                                 (!foundPane.IsAutoHidden && desideredState == DockableContentState.AutoHide))
                                foundPane.ToggleAutoHide();
                        }
                        else
                        {
                            DockablePane newHostpane = new DockablePane();
                            newHostpane.Items.Add(content);

                            if (desideredAnchor == AnchorStyle.Left ||
                                desideredAnchor == AnchorStyle.Right)
                            {
                                double w = 200;
                                if (content.SavedStateAndPosition != null &&
                                    !double.IsInfinity(content.SavedStateAndPosition.Width) &&
                                    !double.IsNaN(content.SavedStateAndPosition.Width))
                                    w = content.SavedStateAndPosition.Width;

                                ResizingPanel.SetResizeWidth(newHostpane, new GridLength(w));
                                ResizingPanel.SetEffectiveSize(newHostpane, new Size(w, 0.0));
                            }
                            else
                            {
                                double h = 200;
                                if (content.SavedStateAndPosition != null &&
                                    !double.IsInfinity(content.SavedStateAndPosition.Height) &&
                                    !double.IsNaN(content.SavedStateAndPosition.Height))
                                    h = content.SavedStateAndPosition.Height;

                                ResizingPanel.SetResizeHeight(newHostpane, new GridLength(h));
                                ResizingPanel.SetEffectiveSize(newHostpane, new Size(0.0, h));
                            }

                            Anchor(newHostpane, desideredAnchor);

                            if (desideredState == DockableContentState.AutoHide)
                            {
                                ToggleAutoHide(newHostpane);
                            }
                        }
                    }

                    ActiveContent = content;
                }
                else if (desideredState == DockableContentState.DockableWindow ||
                    desideredState == DockableContentState.FloatingWindow)
                {
                    DockablePane newHostpane = null;
                    FloatingDockablePane prevHostpane = null;
                    if (content.SavedStateAndPosition != null && content.SavedStateAndPosition.ContainerPane != null && content.SavedStateAndPosition.ContainerPane is FloatingDockablePane)
                    {
                        prevHostpane = content.SavedStateAndPosition.ContainerPane as FloatingDockablePane;
                        if (!prevHostpane.Items.Contains(content))
                            prevHostpane.Items.Add(content);
                    }
                    else
                    {
                        newHostpane = new DockablePane();
                        newHostpane.Items.Add(content);

                    }

                    if (desideredState == DockableContentState.DockableWindow)
                        content.SetStateToDockableWindow();
                    else if (desideredState == DockableContentState.FloatingWindow)
                        content.SetStateToFloatingWindow();

                    if (prevHostpane != null)
                    {
                        //check to see if floating window that host prevHostPane is already loaded (hosting other contents)
                        var floatingWindow = prevHostpane.Parent as DockableFloatingWindow;
                        if (floatingWindow != null && floatingWindow.IsLoaded)
                        {
                            floatingWindow.Activate();
                        }
                        else
                        {
                            floatingWindow = new DockableFloatingWindow(this);
                            floatingWindow.Content = content;
                            floatingWindow.WindowStartupLocation = WindowStartupLocation.Manual;
                            floatingWindow.Top = prevHostpane.FloatingWindow.Top;
                            floatingWindow.Left = prevHostpane.FloatingWindow.Left;
                            floatingWindow.Width = prevHostpane.FloatingWindow.Width;
                            floatingWindow.Height = prevHostpane.FloatingWindow.Height;
                            //floatingWindow.Owner = Window.GetWindow(this);
                            var mainWindow = Window.GetWindow(this);
                            if (mainWindow.IsVisible)
                                floatingWindow.Owner = mainWindow;

                            //now I've created a new pane to host the hidden content
                            //if a an hidden content is shown that has prevHostpane as saved pane
                            //I want that it is relocated in this new pane that I've created right now
                            var hiddenContents = DockableContents.Where(c => c.State == DockableContentState.Hidden).ToArray();
                            foreach (var hiddenContent in hiddenContents)
                            {
                                if (hiddenContent.SavedStateAndPosition.ContainerPane == prevHostpane)
                                {
                                    hiddenContent.SavedStateAndPosition = new DockableContentStateAndPosition(
                                        (floatingWindow.Content as Pane),
                                        hiddenContent.SavedStateAndPosition.ChildIndex,
                                        hiddenContent.SavedStateAndPosition.Width,
                                        hiddenContent.SavedStateAndPosition.Height,
                                        hiddenContent.SavedStateAndPosition.Anchor,
                                        hiddenContent.SavedStateAndPosition.State);
                                }
                            }

                            floatingWindow.Show();
                        }
                    }
                    else if (newHostpane != null)
                    {
                        var floatingWindow = new DockableFloatingWindow(this);
                        floatingWindow.Content = newHostpane;
                        floatingWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        floatingWindow.Width = 200;
                        floatingWindow.Height = 500;
                        //floatingWindow.Owner = Window.GetWindow(this);
                        var mainWindow = Window.GetWindow(this);
                        if (mainWindow.IsVisible)
                            floatingWindow.Owner = mainWindow;

                        floatingWindow.Show();
                    }

                }
                else if (desideredState == DockableContentState.Document)
                {
                    DocumentPane docPane = MainDocumentPane;
                    if (docPane != null)
                    {
                        docPane.Items.Add(content);
                        docPane.SelectedItem = content;
                        content.SetStateToDocument();
                    }
                }
            }

               #endregion
        }
Пример #2
0
        internal void ClearEmptyPanes()
        {
            if (RestoringLayout)
                return;

            while (true)
            {
                bool foundEmptyPaneToRemove = false;
                var emptyDockablePanes = new LogicalTreeAdapter(this).Descendants<DependencyObject>().Where(i => (i.Item is DockablePane) && (i.Item as DockablePane).Items.Count == 0).Select(i => i.Item).Cast<DockablePane>().ToArray();

                emptyDockablePanes.ForEach(dp =>
                {
                    if (!DockableContents.Any(dc =>
                        {
                            if (dc.SavedStateAndPosition != null &&
                                (dc.SavedStateAndPosition.ContainerPane == dp || dc.SavedStateAndPosition.ContainerPaneID == dp.ID))
                                return true;

                            if (dc.State == DockableContentState.AutoHide)
                            {
                                var flyoutDocPane = dc.ContainerPane as FlyoutDockablePane;
                                if (flyoutDocPane != null && flyoutDocPane.ReferencedPane == dp)
                                    return true;
                            }

                            return false;
                        }))
                    {
                        var containerPanel = dp.Parent as ResizingPanel;
                        if (containerPanel != null)
                        {
                            containerPanel.RemoveChild(dp);
                            foundEmptyPaneToRemove = true;
                        }
                    }
                });

                if (!foundEmptyPaneToRemove)
                    break;
            }
        }
Пример #3
0
        internal void RefreshContents()
        {
            if (!_allowRefreshContents)
                return;

            var contentsFoundUnderMe = new LogicalTreeAdapter(this).Descendants<DependencyObject>().Where(d => d.Item is ManagedContent).Select(d => d.Item).Cast<ManagedContent>();
            var contentsFoundInFloatingMode = _floatingWindows.SelectMany(d => d.HostedPane.Items.Cast<ManagedContent>());
            DockableContent contentFoundInFlyoutMode = null;

            if (_flyoutWindow != null &&
                _flyoutWindow.ReferencedPane != null &&
                _flyoutWindow.ReferencedPane.Items.Count > 0)
            {
                contentFoundInFlyoutMode =  _flyoutWindow.ReferencedPane.Items[0] as DockableContent;
            }

            var contentsFound = new List<ManagedContent>();
            contentsFound.AddRange(contentsFoundUnderMe);
            contentsFound.AddRange(contentsFoundInFloatingMode);
            if (contentFoundInFlyoutMode !=  null)
                contentsFound.Add(contentFoundInFlyoutMode);

            var dockableContensToRemove = DockableContents.Except(contentsFound.OfType<DockableContent>());
            var dockableContensToAdd = contentsFound.OfType<DockableContent>().Except(DockableContents);

            dockableContensToAdd.ToArray().ForEach(d =>
            {
                if (d.State != DockableContentState.Hidden)
                    DockableContents.Add(d);
            });
            dockableContensToRemove.ToArray().ForEach(d =>
            {
                if (d.State != DockableContentState.Hidden)
                    DockableContents.Remove(d);
            });

            var documentsToRemove = Documents.Except(contentsFound.OfType<DocumentContent>());
            var documentsToAdd = contentsFound.OfType<DocumentContent>().Except(Documents);

            documentsToAdd.ToArray().ForEach(d => Documents.Add(d));
            documentsToRemove.ToArray().ForEach(d => Documents.Remove(d));

            //refresh MainDocumentPane
            if (MainDocumentPane == null ||
                MainDocumentPane.GetManager() != this)
            {
                ILinqToTree<DependencyObject> itemFound = new LogicalTreeAdapter(this).Descendants<DependencyObject>().FirstOrDefault(d => d.Item is DocumentPane);

                MainDocumentPane = itemFound != null ? itemFound.Item as DocumentPane : null;
            }

            //_floatingWindows.ForEach(fl => fl.CheckContents());
            CheckValidPanesFromTabGroups();
        }
Пример #4
0
        /// <summary>
        /// Restore content specific layout settings
        /// </summary>
        /// <param name="storeReader">Saved xml element containg content layout settings</param>
        /// <remarks>Custom derived class must overload this method to restore custom layout settings previously saved trought <see cref="SaveLayout"/>.</remarks>
        public override void RestoreLayout(XmlElement contentElement)
        {
            if (contentElement.HasAttribute("FloatingWindowSize"))
                FloatingWindowSize = (Size)(new SizeConverter()).ConvertFromInvariantString(contentElement.GetAttribute("FloatingWindowSize"));
            if (contentElement.HasAttribute("FlyoutWindowSize"))
                FlyoutWindowSize = (Size)(new SizeConverter()).ConvertFromInvariantString(contentElement.GetAttribute("FlyoutWindowSize"));

            Size effectiveSize = new Size(0d, 0d);
            if (contentElement.HasAttribute("EffectiveSize"))
            {
                // Store
                effectiveSize = (Size)(new SizeConverter()).ConvertFromInvariantString(contentElement.GetAttribute("EffectiveSize"));
            }

            ResizingPanel.SetEffectiveSize(this, effectiveSize);

            if (contentElement.HasAttribute("ChildIndex"))
            {
                Pane paneRef = null;
                Guid containerPaneGuid = Guid.Empty;
                if (contentElement.HasAttribute("ContainerPaneID"))
                {
                    containerPaneGuid = new Guid(contentElement.GetAttribute("ContainerPaneID"));

                    if (Manager != null)
                    { 
                        ILinqToTree<DependencyObject> itemFound = new LogicalTreeAdapter(Manager).Descendants().FirstOrDefault(el => el.Item is DockablePane && ((el.Item as DockablePane).ID == containerPaneGuid));
                        paneRef = itemFound != null ? itemFound.Item as DockablePane : null;
                    }
                }

                if (paneRef != null)
                {
                    _savedStateAndPosition = new DockableContentStateAndPosition(
                        paneRef,
                        int.Parse(contentElement.GetAttribute("ChildIndex")),
                        double.Parse(contentElement.GetAttribute("Width")),
                        double.Parse(contentElement.GetAttribute("Height")),
                        (AnchorStyle)Enum.Parse(typeof(AnchorStyle), contentElement.GetAttribute("Anchor")),
                        (DockableContentState)Enum.Parse(typeof(DockableContentState), contentElement.GetAttribute("State")));
                }
                else
                {
                    _savedStateAndPosition = new DockableContentStateAndPosition(
                       containerPaneGuid,
                       int.Parse(contentElement.GetAttribute("ChildIndex")),
                       double.Parse(contentElement.GetAttribute("Width")),
                       double.Parse(contentElement.GetAttribute("Height")),
                       (AnchorStyle)Enum.Parse(typeof(AnchorStyle), contentElement.GetAttribute("Anchor")),
                       (DockableContentState)Enum.Parse(typeof(DockableContentState), contentElement.GetAttribute("State")));
                }
            }
        }