internal DockableCollection Create(Dock dock, DockableContextContentCreator contentCreator) { DockableCollection newCollection = new DockableCollection() { Description = this.Description, HorizontalContentAlignment = this.HorizontalContentAlignment, State = this.State, TabPosition = this.TabPosition, VerticalContentAlignment = this.VerticalContentAlignment, }; DockingPanel.SetDockPosition(newCollection, this.DockPosition); if (newCollection.IsCollapsed) { newCollection.CollapsedTabPosition = this.CollapsedTabPosition; } foreach (DockableContentDescriptor desc in Content) { FrameworkElement content = desc.RestoreDockedLayout(newCollection, contentCreator); if (content != null && desc.InternalId == CurrentTab) { newCollection.SetVisibleContent(content); } } dock.Items.Add(newCollection); if (!newCollection.IsCollapsed) { LayoutContext layoutContext = DockingPanel.GetLayoutContext(newCollection); layoutContext.Left = Left; layoutContext.Top = Top; if (IsHeightSplitterActive) { layoutContext.Size.Height.SetSplitter(LayoutHeight.Value); } else { layoutContext.Size.Height.SetInternalValue(LayoutHeight); } if (IsWidthSplitterActive) { layoutContext.Size.Width.SetSplitter(LayoutWidth.Value); } else { layoutContext.Size.Width.SetInternalValue(LayoutWidth); } layoutContext.Size.Height.SetUserValue(Height.Value); layoutContext.Size.Width.SetUserValue(Width.Value); } return(newCollection); }
/// <summary> /// The Restore method is invoked to populate a Dock with a previously saved configuration. /// </summary> /// <param name="layout"> Provides the object previously created by Save</param> /// <param name="dock"> Provides the Dock to receive the new DockableCollection and DockableContent objects. It must have /// no items when Restore is invoked.</param> /// <param name="contentCreator"> Provides an optional callback, invoked once for each freshly restored DockableContent object /// in the saved configuration.</param> public static void Restore(object layout, Dock dock, DockableContextContentCreator contentCreator) { if (layout is DockDescriptor dockDescriptor) { if (dock.Items.Count > 0) { throw new InvalidOperationException("Yawn.Layout.Restore requires the input Dock to be empty."); } dockDescriptor.RestoreLayout(dock, contentCreator); } else { throw new ArgumentException("Yawn.Layout.Restore expected a " + typeof(DockDescriptor).ToString() + ", but was passed a " + layout.GetType().ToString(), "layout"); } }
internal void RestoreLayout(Dock dock, DockableContextContentCreator contentCreator) { Dictionary <int, DockableCollection> dockableCollections = new Dictionary <int, DockableCollection>(); if (MajorVersion != MetadataMajorVersion || MinorVersion > MetadataMinorVersion) { throw new InvalidDataException("Saved layout version (" + MajorVersion.ToString() + "." + MinorVersion.ToString() + " is not compatible with the expected version " + MetadataMajorVersion.ToString() + "." + MetadataMinorVersion.ToString()); } // First, create the collections and associate them with the dock foreach (DockableCollectionDescriptor desc in DockedCollections) { DockableCollection newCollection = desc.Create(dock, contentCreator); dockableCollections.Add(desc.InternalId, newCollection); } // Next, resolve their peer associations foreach (DockableCollectionDescriptor desc in DockedCollections) { DockableCollection dockableCollection = dockableCollections[desc.InternalId]; desc.ResolvePeerRelationships(dockableCollections, dockableCollection); } dock.InvalidatePhysical(); if (dock.ActualWidth != DockSize.Width || dock.ActualHeight != DockSize.Height) { dock.InvalidatePositioning(LayoutContext.PositionClasses.EveryCollection | LayoutContext.PositionClasses.All | LayoutContext.PositionClasses.Resize); } foreach (DockDescriptor desc in FloatingDocks) { dock.CreateFloatingDock(desc.Position, desc.DockSize, (DockWindow dockWindow) => { desc.RestoreLayout(dockWindow.Dock, contentCreator); }); } }
internal FrameworkElement RestoreDockedLayout(DockableCollection newCollection, DockableContextContentCreator contentCreator) { FrameworkElement content = null; if (contentCreator != null) { content = contentCreator.Invoke(TypeName, Description); if (content == null) { return(null); } } SetContentColors(content, this.Background, this.Foreground); DockingPanel.SetTabText(content, TabText); DockingPanel.SetDescriptiveText(content, Description); newCollection.Items.Add(content); return(content); }