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

SwitchFloatingToDockedRequest() public method

Perform a switch from floating to docked for the named pages.
public SwitchFloatingToDockedRequest ( string uniqueNames ) : KryptonDockingDockspace
uniqueNames string Unique name of floating pages that need switching.
return KryptonDockingDockspace
        public virtual KryptonDockingDockspace SwitchFloatingToDockedRequest(string[] uniqueNames)
        {
            // Cannot action a null reference
            if (uniqueNames == null)
                throw new ArgumentNullException("uniqueNames");

            // Cannot action an empty array
            if (uniqueNames.Length == 0)
                throw new ArgumentOutOfRangeException("uniqueNames", "array cannot be empry");

            // Cannot action a null or zero length unique name
            foreach (string uniqueName in uniqueNames)
            {
                if (uniqueName == null)
                    throw new ArgumentNullException("uniqueNames array contains a null string reference");

                if (uniqueName.Length == 0)
                    throw new ArgumentException("uniqueNames array contains a zero length string");
            }

            // Use events to determine which pages should be switched
            List<string> switchUniqueNames = new List<string>();
            List<KryptonPage> switchPages = new List<KryptonPage>();
            string selectedPage = null;
            foreach (string uniqueName in uniqueNames)
            {
                // Does the provided unique name exist and is in the required 'floating' state
                if (FindPageLocation(uniqueName) == DockingLocation.Floating)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked));
                        OnPageDockedRequest(args);

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

                            // Navigate to the cell that holds the page
                            KryptonDockingFloatspace floatspace = FindPageElement(page) as KryptonDockingFloatspace;
                            if (floatspace != null)
                            {
                                KryptonWorkspaceCell cell = floatspace.CellForPage(uniqueName);
                                if (cell != null)
                                {
                                    // Remember the page that is active
                                    if (cell.SelectedPage == page)
                                        selectedPage = page.UniqueName;
                                }
                            }
                        }
                    }
                }
            }

            // Still any pages to be switched?
            if (switchUniqueNames.Count > 0)
            {
                using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                {
                    // Convert the pages to placeholders so they can be returned to the same location
                    PropogateAction(DockingPropogateAction.StorePages, switchUniqueNames.ToArray());

                    // Try and restore each page, but make a note of thos that failed to be restore
                    List<string> defaultUniqueNames = new List<string>();
                    List<KryptonPage> defaultPages = new List<KryptonPage>();
                    KryptonPage defaultSelectedPage = null;
                    for(int i=0; i<switchUniqueNames.Count; i++)
                    {
                        // Find any dockspace that contains a restore page for this named page
                        string switchUniqueName = switchUniqueNames[i];
                        KryptonDockingDockspace restoreElement = DockingManager.FindStorePageElement(DockingLocation.Docked, switchUniqueName) as KryptonDockingDockspace;
                        if (restoreElement != null)
                        {
                            // Find the target cell and the index of the restore page
                            KryptonWorkspaceCell cell = restoreElement.CellForPage(switchUniqueName);
                            int pageIndex = cell.Pages.IndexOf(cell.Pages[switchUniqueName]);

                            // Insert the set of pages at the same index as the restore page
                            restoreElement.CellInsert(cell, pageIndex, switchPages[i]);

                            // Make sure the same page is selected as was selected in the floating source
                            if (switchUniqueName == selectedPage)
                            {
                                restoreElement.SelectPage(selectedPage);
                                restoreElement.DockspaceControl.UpdateVisible(true);
                            }
                        }
                        else
                        {
                            defaultUniqueNames.Add(switchUniqueName);
                            defaultPages.Add(switchPages[i]);

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

                    // Any pages that need default positioning because they could not be restored?
                    if (defaultPages.Count > 0)
                    {
                        // Cannot switch to docked unless we can find a docked element as the target
                        KryptonDockingEdgeDocked edgeDocked = FindDockingEdgeDocked(defaultSelectedPage != null ? defaultSelectedPage.UniqueName : defaultPages[0].UniqueName);
                        if (edgeDocked != null)
                        {
                            KryptonDockingDockspace dockspace = edgeDocked.AppendDockspace();
                            dockspace.Append(defaultPages.ToArray());

                            // Make sure the same page is selected as was selected in the floating source
                            if (defaultSelectedPage != null)
                            {
                                dockspace.SelectPage(defaultSelectedPage.UniqueName);
                                dockspace.DockspaceControl.UpdateVisible(true);
                            }
                        }
                    }
                }
            }

            return null;
        }
KryptonDockingManager