RecreateLoadingPage and Persistence

Topics related to the Krypton Docking.

Moderators: Phil Wright, Chris Porter

RecreateLoadingPage and Persistence

Postby random » Fri Nov 04, 2011 11:59 am

Hi,

I'm trying to get persistence (layout/config) loading to work. The saving was easy, but I'm having some issues with the configuration that gets loaded when I start the application back up.

If I call KryptonDockableWorkspace.LoadLayoutFromArray followed by KryptonDockingManager.LoadConfigFromArray, then create my windows, I get a side-by-side left to right configuration of my windows regardless which order they were when the configuration was saved. If I create the windows, then load the layout/config, my windows are disposed by the layout change.

If I load the layout/config and don't create the windows at all, none of my registered events are called, such as KryptonDockingManager.RecreateLoadingPage.

Here's some code. :)

Code: Select all
        public class MyLayout
        {
            // note that this is only part of the implementation

            public static void LoadLayout(Page page, string filename)
            {
                if (!System.IO.File.Exists(filename))
                {
                    return;
                }

                MyLayout settings = null;

                System.Xml.Serialization.XmlSerializer xml = null;
               
                try
                {
                    xml = new System.Xml.Serialization.XmlSerializer(typeof(MyLayout));
                }
                catch
                {
                    xml = null;
                }

                if (null != xml)
                {
                    try
                    {
                        using (System.IO.FileStream str = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                        {
                            settings = xml.Deserialize(str) as MyLayout;
                        }
                    }
                    catch
                    {
                    }
                }

                if (null != settings)
                {
                    page.SuspendLayout();

                    // this seems to be destroyed or overridden when we load the layout/config?
                    page.Width = settings.Width;
                    page.Height = settings.Height;
                    page.Left = settings.Left;
                    page.Top = settings.Top;

                    if (settings.WorkspaceLayout != null)
                    {
                        page.kryptonDockableWorkspace.LoadLayoutFromArray(settings.WorkspaceLayout);
                    }

                    if (settings.DockingLayout != null)
                    {
                        page.kryptonDockingManager.LoadConfigFromArray(settings.DockingLayout);
                    }

/*
                    // turned on, I get a layout that goes
                    // A B C
                    // even though I saved it as:
                    // A |CC|
                    // B |CC|
                    // turned off, I get nada, zip, zilch. :)
                    if (settings.ModuleToolbar)
                    {
                        page.show_module_toolbar();
                    }

                    if (settings.DataToolbar)
                    {
                        page.show_data_toolbar();
                    }

                    if (settings.ModuleEditor)
                    {
                        page.show_module_editor();
                    }
*/

                    page.ResumeLayout(true);
                    page.Refresh();
                }
            }

        private void Page_Load(object sender, System.EventArgs e)
        {
            ComponentFactory.Krypton.Docking.KryptonDockingWorkspace workspace = kryptonDockingManager.ManageWorkspace(kryptonDockableWorkspace);
            kryptonDockingManager.ManageControl("Control", kryptonPanel, workspace);

            kryptonDockingManager.OrphanedPages += new System.EventHandler<ComponentFactory.Krypton.Docking.PagesEventArgs>(on_orphaned_page);
            kryptonDockableWorkspace.PageLoading += new System.EventHandler<ComponentFactory.Krypton.Workspace.PageLoadingEventArgs>(on_page_load);
            kryptonDockingManager.RecreateLoadingPage += new System.EventHandler<ComponentFactory.Krypton.Workspace.RecreateLoadingPageEventArgs>(on_recreate_page);

            string path = System.IO.Path.Combine(Editor.Program.CONFIG_PATH, "layout.xml");
            MyLayout.Load(this, path);

            // this has no effect on the outcome of the events being triggered...
//            kryptonDockingManager.RecreateLoadingPage -= on_recreate_page;
//            kryptonDockableWorkspace.PageLoading -= on_page_load;
//            kryptonDockingManager.OrphanedPages -= on_orphaned_page;
        }

        // These are never called.
        // I wouldn't expect on_orphaned_page to be called... it's not orphaned, it shouldn't exist.
        // I would expect at least one of on_page_load and on_recreate_page to be called but they aren't.

        private void on_orphaned_page(object sender, ComponentFactory.Krypton.Docking.PagesEventArgs e)
        {
            foreach (ComponentFactory.Krypton.Navigator.KryptonPage page in e.Pages)
            {
            }
        }

        private void on_page_load(object sender, ComponentFactory.Krypton.Workspace.PageLoadingEventArgs e)
        {
        }

        private void on_recreate_page(object sender, ComponentFactory.Krypton.Workspace.RecreateLoadingPageEventArgs e)
        {
        }


Thanks!
random
 
Posts: 3
Joined: Fri Nov 04, 2011 5:07 am

Re: RecreateLoadingPage and Persistence

Postby random » Sat Nov 05, 2011 3:43 am

I'm still working on this, but I wanted to add a note that when I create the KryptonPages, I do call KryptonPage.SetFlags(All) so the configuration is (supposed to be?) written.
random
 
Posts: 3
Joined: Fri Nov 04, 2011 5:07 am


Return to Krypton Docking

Who is online

Users browsing this forum: No registered users and 0 guests