Example #1
0
        private void OnSpaceControlRecreateLoadingPage(object sender, RecreateLoadingPageEventArgs e)
        {
            KryptonDockingManager dockingManager = DockingManager;

            if (dockingManager != null)
            {
                dockingManager.RaiseRecreateLoadingPage(e);
            }
        }
        /// <summary>
        /// Perform docking element specific actions for loading a child xml.
        /// </summary>
        /// <param name="xmlReader">Xml reader object.</param>
        /// <param name="pages">Collection of available pages.</param>
        /// <param name="child">Optional reference to existing child docking element.</param>
        protected override void LoadChildDockingElement(XmlReader xmlReader,
                                                        KryptonPageCollection pages,
                                                        IDockingElement child)
        {
            KryptonDockingManager manager = DockingManager;

            // Is it the expected xml element name?
            if (xmlReader.Name != "KP")
            {
                throw new ArgumentException("Element name 'KP' was expected but found '" + xmlReader.Name + "' instead.");
            }

            // Get the unique name of the page
            string uniqueName = xmlReader.GetAttribute("UN");
            string boolStore = xmlReader.GetAttribute("S");
            string boolVisible = xmlReader.GetAttribute("V");

            KryptonPage page;

            // If the entry is for just a placeholder...
            if (CommonHelper.StringToBool(boolStore))
            {
                // Recreate the requested store page and append
                page = new KryptonStorePage(uniqueName, "AutoHiddenGroup");
                AutoHiddenGroupControl.Pages.Add(page);
            }
            else
            {
                // Can we find a provided page to match the incoming layout?
                page = pages[uniqueName];
                if (page == null)
                {
                    // Generate event so developer can create and supply the page now
                    RecreateLoadingPageEventArgs args = new RecreateLoadingPageEventArgs(uniqueName);
                    manager.RaiseRecreateLoadingPage(args);
                    if (!args.Cancel)
                    {
                        page = args.Page;

                        // Add recreated page to the looking dictionary
                        if ((page != null) && (pages[page.UniqueName] == null))
                        {
                            pages.Add(page);
                        }
                    }
                }

                if (page != null)
                {
                    // Use the loaded visible state
                    page.Visible = CommonHelper.StringToBool(boolVisible);

                    // Create a proxy around the page and append it
                    KryptonAutoHiddenProxyPage proxyPage = new KryptonAutoHiddenProxyPage(page);
                    AutoHiddenGroupControl.Pages.Add(proxyPage);
                }
            }

            if (!xmlReader.Read())
            {
                throw new ArgumentException("An element was expected but could not be read in.");
            }

            if (xmlReader.Name != "CPD")
            {
                throw new ArgumentException("Expected 'CPD' element was not found");
            }

            bool finished = xmlReader.IsEmptyElement;

            // Generate event so custom data can be loaded and/or the page to be added can be modified
            DockPageLoadingEventArgs pageLoading = new DockPageLoadingEventArgs(manager, xmlReader, page);
            manager.RaisePageLoading(pageLoading);

            // Read everything until we get the end of custom data marker
            while (!finished)
            {
                // Check it has the expected name
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    finished = (xmlReader.Name == "CPD");
                }

                if (!finished)
                {
                    if (!xmlReader.Read())
                    {
                        throw new ArgumentException("An element was expected but could not be read in.");
                    }
                }
            }

            if (!xmlReader.Read())
            {
                throw new ArgumentException("An element was expected but could not be read in.");
            }
        }
Example #3
0
        /// <summary>
        /// Loads docking configuration information using a provider xml reader.
        /// </summary>
        /// <param name="xmlReader">Xml reader object.</param>
        /// <param name="pages">Collection of available pages for adding.</param>
        public override void LoadElementFromXml(XmlReader xmlReader, KryptonPageCollection pages)
        {
            // Is it the expected xml element name?
            if (xmlReader.Name != XmlElementName)
            {
                throw new ArgumentException($@"Element name '{XmlElementName}' was expected but found '{xmlReader.Name}' instead.");
            }

            // Grab the element attributes
            string elementName  = xmlReader.GetAttribute(@"N");
            string elementCount = xmlReader.GetAttribute(@"C");

            // Check the name matches up
            if (elementName != Name)
            {
                throw new ArgumentException($@"Attribute 'N' value '{Name}' was expected but found '{elementName}' instead.");
            }

            // Remove any existing pages in the navigator
            DockableNavigatorControl.Pages.Clear();

            // If there are children then load them
            int count = int.Parse(elementCount);

            if (count > 0)
            {
                KryptonDockingManager manager = DockingManager;
                for (int i = 0; i < count; i++)
                {
                    // Read past this element
                    if (!xmlReader.Read())
                    {
                        throw new ArgumentException(@"An element was expected but could not be read in.");
                    }

                    // Is it the expected xml element name?
                    if (xmlReader.Name != @"KP")
                    {
                        throw new ArgumentException($@"Element name 'KP' was expected but found '{xmlReader.Name}' instead.");
                    }

                    // Get the unique name of the page
                    string uniqueName  = CommonHelper.XmlAttributeToText(xmlReader, @"UN");
                    bool   boolStore   = CommonHelper.StringToBool(CommonHelper.XmlAttributeToText(xmlReader, @"S"));
                    bool   boolVisible = CommonHelper.StringToBool(CommonHelper.XmlAttributeToText(xmlReader, @"V", @"True"));

                    // If the entry is for just a placeholder...
                    KryptonPage page;
                    if (boolStore)
                    {
                        // Recreate the requested store page and append
                        page = new KryptonStorePage(uniqueName, _storeName);
                        DockableNavigatorControl.Pages.Add(page);
                    }
                    else
                    {
                        // Can we find a provided page to match the incoming layout?
                        page = pages[uniqueName];
                        if (page == null)
                        {
                            // Generate event so developer can create and supply the page now
                            RecreateLoadingPageEventArgs args = new RecreateLoadingPageEventArgs(uniqueName);
                            manager.RaiseRecreateLoadingPage(args);

                            if (!args.Cancel && (args.Page != null))
                            {
                                page = args.Page;
                            }
                        }

                        if (page != null)
                        {
                            // Use the loaded visible state
                            page.Visible = boolVisible;

                            // Remove from provided collection as we can only add it once to the docking hierarchy
                            pages.Remove(page);

                            // Add into the navigator
                            DockableNavigatorControl.Pages.Add(page);
                        }
                    }

                    if (!xmlReader.Read())
                    {
                        throw new ArgumentException(@"An element was expected but could not be read in.");
                    }

                    if (xmlReader.Name != @"CPD")
                    {
                        throw new ArgumentException(@"Expected 'CPD' element was not found");
                    }

                    bool finished = xmlReader.IsEmptyElement;

                    // Generate event so custom data can be loaded and/or the page to be added can be modified
                    DockPageLoadingEventArgs pageLoading = new DockPageLoadingEventArgs(manager, xmlReader, page);
                    manager.RaisePageLoading(pageLoading);

                    // Read everything until we get the end of custom data marker
                    while (!finished)
                    {
                        // Check it has the expected name
                        if (xmlReader.NodeType == XmlNodeType.EndElement)
                        {
                            finished = (xmlReader.Name == @"CPD");
                        }

                        if (!finished)
                        {
                            if (!xmlReader.Read())
                            {
                                throw new ArgumentException(@"An element was expected but could not be read in.");
                            }
                        }
                    }

                    if (!xmlReader.Read())
                    {
                        throw new ArgumentException(@"An element was expected but could not be read in.");
                    }
                }
            }

            // Read past this element to the end element
            if (!xmlReader.Read())
            {
                throw new ArgumentException(@"An element was expected but could not be read in.");
            }
        }