ComponentFactory.Krypton.Docking.KryptonDockingManager.SwitchAutoHiddenGroupToDockedCellRequest C# (CSharp) Method

SwitchAutoHiddenGroupToDockedCellRequest() public method

Perform a switch from auto hidden group to docked cell for the visible pages inside the group.
public SwitchAutoHiddenGroupToDockedCellRequest ( string uniqueName ) : KryptonDockingDockspace
uniqueName string Unique name of page inside auto hidden group that needs switching.
return KryptonDockingDockspace
        public virtual KryptonDockingDockspace SwitchAutoHiddenGroupToDockedCellRequest(string uniqueName)
        {
            // Cannot switch a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // Does the provided unique name exist and is in the required 'autohidden' state
            if (FindPageLocation(uniqueName) == DockingLocation.AutoHidden)
            {
                // Grab the auto hidden group docking element that we expect to contain the target unique name
                KryptonDockingAutoHiddenGroup autoHiddenGroup = (KryptonDockingAutoHiddenGroup)ExpectPageElement(uniqueName, typeof(KryptonDockingAutoHiddenGroup));
                if (autoHiddenGroup != null)
                {
                    // Find the sibling docked edge so we can add/restore pages
                    KryptonDockingEdgeDocked edgeDocked = autoHiddenGroup.EdgeDockedElement;
                    if (edgeDocked != null)
                    {
                        // Grab the set of visible pages in the auto hidden group
                        KryptonPage[] visiblePages = autoHiddenGroup.VisiblePages();
                        if (visiblePages.Length > 0)
                        {
                            // Use events to determine which pages in the cell should be switched
                            List<string> switchUniqueNames = new List<string>();
                            List<KryptonPage> switchPages = new List<KryptonPage>();
                            foreach (KryptonPage page in visiblePages)
                            {
                                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked));
                                OnPageDockedRequest(args);

                                if (!args.Cancel)
                                {
                                    switchUniqueNames.Add(page.UniqueName);
                                    switchPages.Add(page);
                                }
                            }

                            // Any pages that actually need to be switched?
                            if (switchPages.Count > 0)
                            {
                                using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                                {
                                    // Remove the pages from the auto hidden group
                                    string[] uniqueNames = switchUniqueNames.ToArray();
                                    PropogateAction(DockingPropogateAction.RemovePages, uniqueNames);

                                    // Attempt to restore each page back to original location on the same edge
                                    List<KryptonPage> defaultPages = new List<KryptonPage>();
                                    KryptonPage defaultSelectedPage = null;
                                    for(int i=0; i<switchPages.Count; i++)
                                    {
                                        // If we find a store page then we can simply restore straight back to that position
                                        bool? canRestore = edgeDocked.PropogateBoolState(DockingPropogateBoolState.ContainsStorePage, uniqueNames[i]);
                                        if (canRestore.HasValue && canRestore.Value)
                                        {
                                            // Restore page back into a dockspace
                                            edgeDocked.PropogateAction(DockingPropogateAction.RestorePages, new KryptonPage[] { switchPages[i] });

                                            // Should this page become the selected and focused page?
                                            if (uniqueName == uniqueNames[i])
                                            {
                                                // If this restored page was the selected page in the auto hidden group, make it selected in the dockspace
                                                KryptonDockingDockspace restoreElement = edgeDocked.FindPageElement(uniqueNames[i]) as KryptonDockingDockspace;
                                                if (restoreElement != null)
                                                {
                                                    restoreElement.SelectPage(uniqueNames[i]);
                                                    restoreElement.DockspaceControl.UpdateVisible(true);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            defaultPages.Add(switchPages[i]);

                                            // Note the default page that should become selected
                                            if (uniqueName == uniqueNames[i])
                                                defaultSelectedPage = switchPages[i];
                                        }
                                    }

                                    // Remove any existing placeholders in all the docked edges
                                    RemoveControlStorePages(edgeDocked, uniqueNames, false, true);

                                    // Do we have some pages that still need adding?
                                    if (defaultPages.Count > 0)
                                    {
                                        // Place them all inside a new dockspace
                                        KryptonDockingDockspace newDockspace = edgeDocked.AppendDockspace();
                                        newDockspace.Append(defaultPages.ToArray());

                                        // Make sure the same page is selected as was selected in the auto hidden group
                                        if (defaultSelectedPage != null)
                                        {
                                            newDockspace.SelectPage(defaultSelectedPage.UniqueName);
                                            newDockspace.DockspaceControl.UpdateVisible(true);
                                        }

                                        return newDockspace;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
KryptonDockingManager