public void RestoreDockPanelState(DockPanelState state, Func <string, DarkDockContent> getContentBySerializationKey) { foreach (var region in state.Regions) { switch (region.Area) { case DarkDockArea.Left: _regions[DarkDockArea.Left].Size = region.Size; break; case DarkDockArea.Right: _regions[DarkDockArea.Right].Size = region.Size; break; case DarkDockArea.Bottom: _regions[DarkDockArea.Bottom].Size = region.Size; break; } foreach (var group in region.Groups) { DarkDockContent previousContent = null; DarkDockContent visibleContent = null; foreach (var contentKey in group.Contents) { var content = getContentBySerializationKey(contentKey); if (content == null) { continue; } content.DockArea = region.Area; if (previousContent == null) { AddContent(content); } else { AddContent(content, previousContent.DockGroup); } previousContent = content; if (group.VisibleContent == contentKey) { visibleContent = content; } } if (visibleContent != null) { visibleContent.Select(); } } } }
public DockPanelState GetDockPanelState() { var state = new DockPanelState(); state.Regions.Add(new DockRegionState(DarkDockArea.Document)); state.Regions.Add(new DockRegionState(DarkDockArea.Left, _regions[DarkDockArea.Left].Size)); state.Regions.Add(new DockRegionState(DarkDockArea.Right, _regions[DarkDockArea.Right].Size)); state.Regions.Add(new DockRegionState(DarkDockArea.Bottom, _regions[DarkDockArea.Bottom].Size)); var _groupStates = new Dictionary <DarkDockGroup, DockGroupState>(); var orderedContent = _contents.OrderBy(c => c.Order); foreach (var content in orderedContent) { foreach (var region in state.Regions) { if (region.Area == content.DockArea) { DockGroupState groupState; if (_groupStates.ContainsKey(content.DockGroup)) { groupState = _groupStates[content.DockGroup]; } else { groupState = new DockGroupState(); region.Groups.Add(groupState); _groupStates.Add(content.DockGroup, groupState); } groupState.Contents.Add(content.SerializationKey); groupState.VisibleContent = content.DockGroup.VisibleContent.SerializationKey; } } } return(state); }