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

SwitchDockedToFloatingWindowRequest() public method

Perform a switch from docked pages to floating window for the named pages.
public SwitchDockedToFloatingWindowRequest ( string uniqueNames ) : KryptonDockingFloatingWindow
uniqueNames string Unique name of pages inside a docked cell that needs switching.
return KryptonDockingFloatingWindow
        public virtual KryptonDockingFloatingWindow SwitchDockedToFloatingWindowRequest(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 'docked' state
                if (FindPageLocation(uniqueName) == DockingLocation.Docked)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating));
                        OnPageFloatingRequest(args);

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

                            // Navigate to the cell that holds the page
                            KryptonDockingDockspace dockspace = FindPageElement(page) as KryptonDockingDockspace;
                            if (dockspace != null)
                            {
                                KryptonWorkspaceCell cell = dockspace.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)
            {
                // Find a floating element that is the target for the switching
                KryptonDockingFloating floating = FindDockingFloating(selectedPage != null ? selectedPage : switchUniqueNames[0]);
                if (floating != null)
                {
                    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());

                        KryptonWorkspaceCell cell = null;
                        foreach (string switchUniqueName in switchUniqueNames)
                        {
                            // Is there a floating window with a restore page for this unique name?
                            KryptonDockingFloatingWindow restoreElement = floating.FloatingWindowForStorePage(switchUniqueName);
                            if (restoreElement != null)
                            {
                                // Find the target cell and the index of the restore page
                                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.FloatspaceElement.CellInsert(cell, pageIndex, switchPages.ToArray());

                                // Make sure the same page is selected as was selected in the docked source
                                if (selectedPage != null)
                                    restoreElement.SelectPage(selectedPage);

                                return restoreElement;
                            }
                        }

                        // No floating window found to restore into, so create a new window
                        KryptonDockingFloatingWindow floatingElement = floating.AddFloatingWindow();
                        floatingElement.FloatspaceElement.Append(switchPages.ToArray());

                        // Make sure the same page is selected as was selected in the docked source
                        if (selectedPage != null)
                            floatingElement.SelectPage(selectedPage);

                        floatingElement.FloatingWindow.Show();
                        return floatingElement;
                    }
                }
            }

            return null;
        }
KryptonDockingManager