Ejemplo n.º 1
0
        private void RestoreWorkspaceLayout(WorkspaceLayout layout)
        {
            if (null == View)
            {
                return;
            }

            View.WidgetDockManager.RestoreLayoutFromStream(new MemoryStream(layout.DockingLayout));

            var instances = new List <IWidget>();

            foreach (var widget in layout.Widgets)
            {
                var widgetInstance = Dashboard.CreateWidget(Type.GetType(widget.Type), widget.ViewModelId).Result;
                if (null == widgetInstance)
                {
                    throw new MissingWidgetException(widget.Type);
                }
                widgetInstance.ParentName       = widget.ParentName;
                widgetInstance.GridsLayout      = widget.GridsLayout;
                widgetInstance.PivotGridsLayout = widget.PivotGridsLayout;
                widgetInstance.DockId           = widget.DockId;
                instances.Add(widgetInstance);
            }

            Widgets.AddRange(instances, false);

            VisualTreeWalker <LayoutPanel> .Execute(View, FillPanel, instances);

            RestoreFloatingWidgets();
        }
Ejemplo n.º 2
0
        public async Task LoadLayout(WorkspaceLayout providedLayout = null)
        {
            Widgets.Clear();

            var layout = providedLayout ?? await FindRelevantLayout();

            if (null == layout)
            {
                return;
            }

            RestoreWorkspaceLayout(layout);

            RestoreGridLayouts(layout.Widgets);
        }
Ejemplo n.º 3
0
        public WorkspaceLayout GetCurrentLayout()
        {
            var processedPanels = new List <LayoutPanel>();

            VisualTreeWalker <LayoutPanel> .Execute(View, SetNameOnPanel);

            View.WidgetDockManager.ClosedPanels.Clear();

            var layout = new WorkspaceLayout {
                Widgets = Widgets.Select(y => y.GetDescriptor()).ToList()
            };

            var layoutId = DateTime.Now.Ticks;

            VisualTreeWalker <LayoutPanel> .Execute(View, layoutPanel =>
            {
                var widget = layoutPanel.DataContext as IWidget;

                if (null == widget)
                {
                    return;
                }

                if (processedPanels.Contains(layoutPanel))
                {
                    return;
                }
                processedPanels.Add(layoutPanel);

                layoutPanel.Name = widget.ParentName;

                if (widget.AllowGridSaveLayout)
                {
                    VisualTreeWalker <GridControl> .Execute(widget.View, b =>
                    {
                        using (var ms = new MemoryStream())
                        {
                            b.SaveLayoutToStream(ms);
                            ms.Position = 0;

                            widget.GridsLayout.RemoveAll(y => y.GridLayoutId != layoutId);

                            widget.GridsLayout.Add(new GridLayoutItem()
                            {
                                GridLayoutId = layoutId,
                                Layout       = ms.ToArray(),
                                WidgetId     = widget.DockId
                            }
                                                   );
                        }
                    });

                    VisualTreeWalker <PivotGridControl> .Execute(widget.View, b =>
                    {
                        using (var ms = new MemoryStream())
                        {
                            b.SaveLayoutToStream(ms);
                            ms.Position = 0;

                            widget.PivotGridsLayout.RemoveAll(y => y.GridLayoutId != layoutId);

                            widget.PivotGridsLayout.Add(new GridLayoutItem()
                            {
                                GridLayoutId = layoutId,
                                Layout       = ms.ToArray(),
                                WidgetId     = widget.DockId
                            });
                        }
                    });
                }
            });

            SaveFloatingWidgetsGridLayouts();

            using (var ms = new MemoryStream())
            {
                View.WidgetDockManager.SaveLayoutToStream(ms);
                ms.Position          = 0;
                layout.DockingLayout = ms.ToArray();
            }

            return(layout);
        }