/// <summary> /// Raises the OrphanedPages event. /// </summary> /// <param name="e">An PagesEventArgs containing event data.</param> protected virtual void OnOrphanedPages(PagesEventArgs e) { if (OrphanedPages != null) OrphanedPages(this, e); }
/// <summary> /// Loads docking configuration information using the provided xml reader. /// </summary> /// <param name="xmlReader">Xml reader object.</param> public void LoadConfigFromXml(XmlReader xmlReader) { // Remember the current culture setting CultureInfo culture = Thread.CurrentThread.CurrentCulture; try { // Double check this has the correct element name if (xmlReader.Name != "KD") throw new ArgumentException("Root element must be named 'KD'"); // Load the format version number string version = xmlReader.GetAttribute("V"); // Convert format version from string to double int formatVersion = (int)Convert.ToDouble(version); // We can only load 1 upward version formats if (formatVersion < 1) throw new ArgumentException("Can only load Version 1 and upwards of KryptonDockingManager persisted data."); using (DockingMultiUpdate update = new DockingMultiUpdate(this)) { // Create a list of all the existing pages KryptonPageCollection currentPages = new KryptonPageCollection(); PropogatePageList(DockingPropogatePageList.All, currentPages); // Reset docking hierarchy ready for the reload PropogateAction(DockingPropogateAction.Loading, (string[])null); try { // Read to custom data element if (!xmlReader.Read()) throw new ArgumentException("An element was expected but could not be read in."); if (xmlReader.Name != "DGD") throw new ArgumentException("Expected 'DGD' element was not found."); bool finished = xmlReader.IsEmptyElement; // Give handlers chance to reload custom saved data OnGlobalLoading(new DockGlobalLoadingEventArgs(this, xmlReader)); // 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 == "DGD"); if (!finished) { if (!xmlReader.Read()) throw new ArgumentException("An element was expected but could not be read in."); } } // Read the next well known element if (!xmlReader.Read()) throw new ArgumentException("An element was expected but could not be read in."); // Is it the expected element? if (xmlReader.Name != "DM") throw new ArgumentException("Element 'DM' was expected but not found."); // Reload the root sequence LoadElementFromXml(xmlReader, currentPages); // Move past the end element if (!xmlReader.Read()) throw new ArgumentException("Could not read in next expected node."); // Check it has the expected name if (xmlReader.NodeType != XmlNodeType.EndElement) throw new ArgumentException("EndElement expected but not found."); // Did we have any starting pages? if (currentPages.Count > 0) { // Create a list of all the pages present after loading KryptonPageCollection loadedPages = new KryptonPageCollection(); PropogatePageList(DockingPropogatePageList.All, loadedPages); // Remove the loaded pages from the current page list foreach (KryptonPage loadedPage in loadedPages) currentPages.Remove(loadedPage); // Did we any orphan pages? Those that existed at start of loading but // are not present in the docking hierarchy after loading. So they are // orphaned and we allow developers a chance to do something with them. if (currentPages.Count > 0) { // Generate event so the pages can be processed manually PagesEventArgs args = new PagesEventArgs(currentPages); OnOrphanedPages(args); // If there are pages not processed by the event if (args.Pages.Count > 0) { // Cleanup the no longer needed pages by disposing them foreach (KryptonPage page in args.Pages) page.Dispose(); } } } } finally { } } } finally { // Put back the old culture before exiting routine Thread.CurrentThread.CurrentCulture = culture; } }