/// <summary> /// Read page details from xml during load process. /// </summary> /// <param name="xmlReader">XmlReader to use for loading.</param> /// <param name="uniqueName">Unique name of page being loaded.</param> /// <param name="existingPages">Set of existing pages.</param> /// <returns>Reference to page to be added into the workspace cell.</returns> public override KryptonPage ReadPageElement(XmlReader xmlReader, string uniqueName, UniqueNameToPage existingPages) { // If a matching page with the unique name already exists then use it, // otherwise we need to create an entirely new page instance. KryptonPage page; if (existingPages.TryGetValue(uniqueName, out page)) { existingPages.Remove(uniqueName); } else { // Use event to try and get a newly created page for use RecreateLoadingPageEventArgs args = new RecreateLoadingPageEventArgs(uniqueName); OnRecreateLoadingPage(args); if (!args.Cancel) { page = args.Page; // Add recreated page to the looking dictionary if ((page != null) && !existingPages.ContainsKey(page.UniqueName)) { existingPages.Add(page.UniqueName, page); } } } if (page != null) { // If this is a store page then recreate as a store page type if (CommonHelper.StringToBool(CommonHelper.XmlAttributeToText(xmlReader, "S"))) { page = new KryptonStorePage(page.UniqueName, _storeName); } else { // Only some values if the actual page and not if it is a store page page.UniqueName = CommonHelper.XmlAttributeToText(xmlReader, "UN"); page.Visible = CommonHelper.StringToBool(CommonHelper.XmlAttributeToText(xmlReader, "V", "True")); } } // Read past the page start element if (!xmlReader.Read()) { throw new ArgumentException("An element was expected but could not be read in."); } return(page); }
/// <summary> /// Convert the named pages into store placeholders. /// </summary> /// <param name="uniqueNames">Array of page names.</param> public void StorePages(string[] uniqueNames) { foreach (string uniqueName in uniqueNames) { // If a matching page exists and it is not a store placeholder already KryptonPage page = Pages[uniqueName]; if ((page != null) && !(page is KryptonStorePage)) { // Notify that we are storing a page, so handlers can ensure it will be unique to the auto hidden location OnStoringPage(new UniqueNameEventArgs(page.UniqueName)); // Replace the existing page with a placeholder that has the same unique name KryptonStorePage placeholder = new KryptonStorePage(uniqueName, "AutoHiddenGroup"); Pages.Insert(Pages.IndexOf(page), placeholder); Pages.Remove(page); } } }
/// <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."); } }
/// <summary> /// Initialize a new instance of the StorePageEventArgs class. /// </summary> /// <param name="storePage">Reference to store page that is associated with the event.</param> public StorePageEventArgs(KryptonStorePage storePage) { _storePage = storePage; }
/// <summary> /// Propagates an action request down the hierarchy of docking elements. /// </summary> /// <param name="action">Action that is requested to be performed.</param> /// <param name="uniqueNames">Array of unique names of the pages the action relates to.</param> public override void PropogateAction(DockingPropogateAction action, string[] uniqueNames) { KryptonPageCollection pageCollection = DockableNavigatorControl.Pages; switch (action) { case DockingPropogateAction.Loading: // Remove all pages including store pages pageCollection.Clear(); return; case DockingPropogateAction.ShowAllPages: case DockingPropogateAction.HideAllPages: case DockingPropogateAction.RemoveAllPages: case DockingPropogateAction.RemoveAndDisposeAllPages: // Ignore some global actions return; case DockingPropogateAction.StorePages: foreach (string uniqueName in uniqueNames) { // Swap pages that are not placeholders to become placeholders KryptonPage page = pageCollection[uniqueName]; if ((page != null) && !(page is KryptonStorePage)) { // Replace the existing page with a placeholder that has the same unique name KryptonStorePage placeholder = new KryptonStorePage(uniqueName, _storeName); pageCollection.Insert(pageCollection.IndexOf(page), placeholder); pageCollection.Remove(page); } } break; case DockingPropogateAction.StoreAllPages: // Process each page inside the cell for (int i = pageCollection.Count - 1; i >= 0; i--) { // Swap pages that are not placeholders to become placeholders KryptonPage page = pageCollection[i]; if ((page != null) && !(page is KryptonStorePage)) { // Replace the existing page with a placeholder that has the same unique name KryptonStorePage placeholder = new KryptonStorePage(page.UniqueName, _storeName); pageCollection.Insert(pageCollection.IndexOf(page), placeholder); pageCollection.Remove(page); } } break; case DockingPropogateAction.ClearFillerStoredPages: case DockingPropogateAction.ClearStoredPages: foreach (string uniqueName in uniqueNames) { // Only remove a matching unique name if it is a placeholder page KryptonPage removePage = pageCollection[uniqueName]; if (removePage is KryptonStorePage) { pageCollection.Remove(removePage); } } break; case DockingPropogateAction.ClearAllStoredPages: { // Process each page inside the cell for (int i = pageCollection.Count - 1; i >= 0; i--) { // Remove all placeholders KryptonPage page = pageCollection[i]; if (page is KryptonStorePage) { pageCollection.Remove(page); } } } break; case DockingPropogateAction.DebugOutput: Console.WriteLine(GetType().ToString()); DockableNavigatorControl.DebugOutput(); break; } // Let base class perform standard processing base.PropogateAction(action, uniqueNames); }
/// <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."); } }
/// <summary> /// Propogates an action request down the hierarchy of docking elements. /// </summary> /// <param name="action">Action that is requested to be performed.</param> /// <param name="uniqueNames">Array of unique names of the pages the action relates to.</param> public override void PropogateAction(DockingPropogateAction action, string[] uniqueNames) { switch (action) { case DockingPropogateAction.Loading: // Force layout so that the correct number of pages is recognized SpaceControl.PerformLayout(); // Remove all the pages including store pages SpaceControl.ClearAllPages(); // Force layout so that the control will kill itself SpaceControl.PerformLayout(); break; case DockingPropogateAction.ShowPages: case DockingPropogateAction.HidePages: { bool newVisible = (action == DockingPropogateAction.ShowPages); foreach (string uniqueName in uniqueNames) { // Update visible state of pages that are not placeholders KryptonPage page = SpaceControl.PageForUniqueName(uniqueName); if ((page != null) && !(page is KryptonStorePage)) { page.Visible = newVisible; } } } break; case DockingPropogateAction.ShowAllPages: SpaceControl.ShowAllPages(typeof(KryptonStorePage)); break; case DockingPropogateAction.HideAllPages: SpaceControl.HideAllPages(typeof(KryptonStorePage)); break; case DockingPropogateAction.RemovePages: case DockingPropogateAction.RemoveAndDisposePages: foreach (string uniqueName in uniqueNames) { // If the named page exists and is not placeholder then remove it KryptonPage removePage = SpaceControl.PageForUniqueName(uniqueName); if ((removePage != null) && !(removePage is KryptonStorePage)) { // Find the cell that contains the target so we can remove the page KryptonWorkspaceCell cell = SpaceControl.CellForPage(removePage); if (cell != null) { cell.Pages.Remove(removePage); if (action == DockingPropogateAction.RemoveAndDisposePages) { removePage.Dispose(); } } } } break; case DockingPropogateAction.RemoveAllPages: case DockingPropogateAction.RemoveAndDisposeAllPages: { // Process each cell in turn KryptonWorkspaceCell cell = SpaceControl.FirstCell(); while (cell != null) { // Process each page inside the cell for (int i = cell.Pages.Count - 1; i >= 0; i--) { // Only remove the actual page and not placeholders KryptonPage page = cell.Pages[i]; if ((page != null) && !(page is KryptonStorePage)) { cell.Pages.RemoveAt(i); if (action == DockingPropogateAction.RemoveAndDisposeAllPages) { page.Dispose(); } } } cell = SpaceControl.NextCell(cell); } // Force layout so that the control will kill itself SpaceControl.PerformLayout(); } break; case DockingPropogateAction.StorePages: foreach (string uniqueName in uniqueNames) { // Swap pages that are not placeholders to become placeholders KryptonPage page = SpaceControl.PageForUniqueName(uniqueName); if ((page != null) && !(page is KryptonStorePage)) { // Replace the existing page with a placeholder that has the same unique name KryptonWorkspaceCell cell = SpaceControl.CellForPage(page); KryptonStorePage placeholder = new KryptonStorePage(uniqueName, _storeName); cell.Pages.Insert(cell.Pages.IndexOf(page), placeholder); cell.Pages.Remove(page); } } break; case DockingPropogateAction.StoreAllPages: { // Process each cell in turn KryptonWorkspaceCell cell = SpaceControl.FirstCell(); while (cell != null) { // Process each page inside the cell for (int i = cell.Pages.Count - 1; i >= 0; i--) { // Swap pages that are not placeholders to become placeholders KryptonPage page = cell.Pages[i]; if ((page != null) && !(page is KryptonStorePage)) { // Replace the existing page with a placeholder that has the same unique name KryptonStorePage placeholder = new KryptonStorePage(page.UniqueName, _storeName); cell.Pages.Insert(cell.Pages.IndexOf(page), placeholder); cell.Pages.Remove(page); } } cell = SpaceControl.NextCell(cell); } } break; case DockingPropogateAction.ClearFillerStoredPages: case DockingPropogateAction.ClearFloatingStoredPages: case DockingPropogateAction.ClearDockedStoredPages: case DockingPropogateAction.ClearStoredPages: // Only process an attempt to clear all pages or those related to this docking location if ((action == DockingPropogateAction.ClearStoredPages) || (action == ClearStoreAction)) { foreach (string uniqueName in uniqueNames) { // Only remove a matching unique name if it is a placeholder page KryptonPage removePage = SpaceControl.PageForUniqueName(uniqueName); if (removePage is KryptonStorePage) { // Check if the page is one marked to be ignored in this operation if (removePage != IgnoreStorePage) { // Find the cell that contains the target so we can remove the page KryptonWorkspaceCell cell = SpaceControl.CellForPage(removePage); cell?.Pages.Remove(removePage); } } } } break; case DockingPropogateAction.ClearAllStoredPages: { // Process each cell in turn KryptonWorkspaceCell cell = SpaceControl.FirstCell(); while (cell != null) { // Process each page inside the cell for (int i = cell.Pages.Count - 1; i >= 0; i--) { // Remove all placeholders KryptonPage page = cell.Pages[i]; if (page is KryptonStorePage) { cell.Pages.Remove(page); } } cell = SpaceControl.NextCell(cell); } } break; case DockingPropogateAction.StringChanged: UpdateStrings(); break; case DockingPropogateAction.DebugOutput: Console.WriteLine(SpaceControl.ToString()); SpaceControl.DebugOutput(); break; } // Let base class perform standard processing base.PropogateAction(action, uniqueNames); }
/// <summary> /// Propogates an action request down the hierarchy of docking elements. /// </summary> /// <param name="action">Action that is requested to be performed.</param> /// <param name="uniqueNames">Array of unique names of the pages the action relates to.</param> public override void PropogateAction(DockingPropogateAction action, string[] uniqueNames) { switch (action) { case DockingPropogateAction.Loading: // Force layout so that the correct number of pages is recognized SpaceControl.PerformLayout(); // Remove all the pages including store pages SpaceControl.ClearAllPages(); // Force layout so that the control will kill itself SpaceControl.PerformLayout(); break; case DockingPropogateAction.ShowPages: case DockingPropogateAction.HidePages: { bool newVisible = (action == DockingPropogateAction.ShowPages); foreach (string uniqueName in uniqueNames) { // Update visible state of pages that are not placeholders KryptonPage page = SpaceControl.PageForUniqueName(uniqueName); if ((page != null) && !(page is KryptonStorePage)) page.Visible = newVisible; } } break; case DockingPropogateAction.ShowAllPages: SpaceControl.ShowAllPages(typeof(KryptonStorePage)); break; case DockingPropogateAction.HideAllPages: SpaceControl.HideAllPages(typeof(KryptonStorePage)); break; case DockingPropogateAction.RemovePages: case DockingPropogateAction.RemoveAndDisposePages: foreach (string uniqueName in uniqueNames) { // If the named page exists and is not placeholder then remove it KryptonPage removePage = SpaceControl.PageForUniqueName(uniqueName); if ((removePage != null) && !(removePage is KryptonStorePage)) { // Find the cell that contains the target so we can remove the page KryptonWorkspaceCell cell = SpaceControl.CellForPage(removePage); if (cell != null) { cell.Pages.Remove(removePage); if (action == DockingPropogateAction.RemoveAndDisposePages) removePage.Dispose(); } } } break; case DockingPropogateAction.RemoveAllPages: case DockingPropogateAction.RemoveAndDisposeAllPages: { // Process each cell in turn KryptonWorkspaceCell cell = SpaceControl.FirstCell(); while (cell != null) { // Process each page inside the cell for (int i = cell.Pages.Count - 1; i >= 0; i--) { // Only remove the actual page and not placeholders KryptonPage page = cell.Pages[i]; if ((page != null) && !(page is KryptonStorePage)) { cell.Pages.RemoveAt(i); if (action == DockingPropogateAction.RemoveAndDisposeAllPages) page.Dispose(); } } cell = SpaceControl.NextCell(cell); } // Force layout so that the control will kill itself SpaceControl.PerformLayout(); } break; case DockingPropogateAction.StorePages: foreach (string uniqueName in uniqueNames) { // Swap pages that are not placeholders to become placeholders KryptonPage page = SpaceControl.PageForUniqueName(uniqueName); if ((page != null) && !(page is KryptonStorePage)) { // Replace the existing page with a placeholder that has the same unique name KryptonWorkspaceCell cell = SpaceControl.CellForPage(page); KryptonStorePage placeholder = new KryptonStorePage(uniqueName, _storeName); cell.Pages.Insert(cell.Pages.IndexOf(page), placeholder); cell.Pages.Remove(page); } } break; case DockingPropogateAction.StoreAllPages: { // Process each cell in turn KryptonWorkspaceCell cell = SpaceControl.FirstCell(); while (cell != null) { // Process each page inside the cell for (int i = cell.Pages.Count - 1; i >= 0; i--) { // Swap pages that are not placeholders to become placeholders KryptonPage page = cell.Pages[i]; if ((page != null) && !(page is KryptonStorePage)) { // Replace the existing page with a placeholder that has the same unique name KryptonStorePage placeholder = new KryptonStorePage(page.UniqueName, _storeName); cell.Pages.Insert(cell.Pages.IndexOf(page), placeholder); cell.Pages.Remove(page); } } cell = SpaceControl.NextCell(cell); } } break; case DockingPropogateAction.ClearFillerStoredPages: case DockingPropogateAction.ClearFloatingStoredPages: case DockingPropogateAction.ClearDockedStoredPages: case DockingPropogateAction.ClearStoredPages: // Only process an attempt to clear all pages or those related to this docking location if ((action == DockingPropogateAction.ClearStoredPages) || (action == ClearStoreAction)) { foreach (string uniqueName in uniqueNames) { // Only remove a matching unique name if it is a placeholder page KryptonPage removePage = SpaceControl.PageForUniqueName(uniqueName); if ((removePage != null) && (removePage is KryptonStorePage)) { // Check if the page is one marked to be ignored in this operation if (removePage != IgnoreStorePage) { // Find the cell that contains the target so we can remove the page KryptonWorkspaceCell cell = SpaceControl.CellForPage(removePage); if (cell != null) cell.Pages.Remove(removePage); } } } } break; case DockingPropogateAction.ClearAllStoredPages: { // Process each cell in turn KryptonWorkspaceCell cell = SpaceControl.FirstCell(); while (cell != null) { // Process each page inside the cell for (int i = cell.Pages.Count - 1; i >= 0; i--) { // Remove all placeholders KryptonPage page = cell.Pages[i]; if ((page != null) && (page is KryptonStorePage)) cell.Pages.Remove(page); } cell = SpaceControl.NextCell(cell); } } break; case DockingPropogateAction.StringChanged: UpdateStrings(); break; case DockingPropogateAction.DebugOutput: Console.WriteLine(SpaceControl.ToString()); SpaceControl.DebugOutput(); break; } // Let base class perform standard processing base.PropogateAction(action, uniqueNames); }
/// <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 = null; // 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."); }