Exemple #1
0
        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;
                        groupState.Order          = content.DockGroup.Order;
                        groupState.Size           = content.DockGroup.Size;
                    }
                }
            }

            return(state);
        }
Exemple #2
0
        public void RestoreDockPanelState(DockPanelState state, Func <string, DarkDockContent> getContentBySerializationKey)
        {
            SuspendLayout();

            foreach (var region in state.Regions.OrderByDescending(r => r.Area))
            {
                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;
                }

                region.Groups.Sort(delegate(DockGroupState a, DockGroupState b) { return(a.Order.CompareTo(b.Order)); });

                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();
                        visibleContent.DockGroup.Size = group.Size;
                    }
                }
            }

            ResumeLayout();
        }