Exemplo n.º 1
0
        private void RestoreGridLayoutInternal(UserControl control, WidgetDescriptor descriptor)
        {
            this.ExecuteOnCurrentDispatcher(() =>
            {
                var i = -1;

                VisualTreeWalker <GridControl> .Execute(control, grid =>
                {
                    if (descriptor.GridsLayout.Count > ++i)
                    {
                        grid.RestoreLayoutFromStream(new MemoryStream(descriptor.GridsLayout[i].Layout));
                    }
                });

                i = -1;

                VisualTreeWalker <PivotGridControl> .Execute(control, grid =>
                {
                    if (descriptor.PivotGridsLayout.Count > ++i)
                    {
                        grid.RestoreLayoutFromStream(new MemoryStream(descriptor.PivotGridsLayout[i].Layout));
                    }
                });
            });
        }
Exemplo n.º 2
0
        private void RestoreGridLayouts(IEnumerable <WidgetDescriptor> descriptors)
        {
            var processedPanels = new List <LayoutPanel>();

            foreach (var widget in Widgets)
            {
                VisualTreeWalker <LayoutPanel> .Execute(View, layoutPanel =>
                {
                    if (layoutPanel.Name != widget.ParentName)
                    {
                        return;
                    }

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

                    processedPanels.Add(layoutPanel);

                    var descriptor = descriptors.FirstOrDefault(des => des.ParentName == widget.ParentName);

                    RestoreGridLayoutInternal(layoutPanel.Content as UserControl, descriptor);
                });
            }

            RestoreFloatingWidgetsGridLayouts(descriptors);
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        private void RestoreFloatingWidgets()
        {
            var panels = new List <LayoutPanel>();

            foreach (var floatGroup in View.WidgetDockManager.FloatGroups.Cast <FloatGroup>())
            {
                panels.AddRange(floatGroup.Items.Select(x => FindEmptyPanels(x)).Aggregate((x, y) => x.Concat(y)));
            }

            if (panels.Count() == 0)
            {
                return;
            }

            foreach (var panel in panels)
            {
                var canditate = Widgets.FirstOrDefault(widget => widget.ParentName == panel.Name);

                VisualTreeWalker <LayoutPanel> .Execute(panel, FillPanel, Widgets.Select(w => w));
            }
        }
Exemplo n.º 5
0
        private void SaveFloatingWidgetsGridLayouts()
        {
            var panels = new List <LayoutPanel>();

            foreach (var floatGroup in View.WidgetDockManager.FloatGroups.Cast <FloatGroup>())
            {
                panels.AddRange(floatGroup.Items.Select(x => FindWidgetPanels(x))
                                .Aggregate((x, y) => x.Concat(y)));
            }

            panels.ForEach(panel => SetNameOnPanel(panel));

            foreach (var panel in panels)
            {
                var widget = (panel.Content as IWidget);

                if (widget == null)
                {
                    continue;
                }

                VisualTreeWalker <LayoutPanel> .Execute(panel, layoutPanel =>
                {
                    if (layoutPanel.Name != widget.ParentName)
                    {
                        return;
                    }

                    var layoutId = DateTime.Now.Ticks;

                    if (widget.AllowGridSaveLayout)
                    {
                        VisualTreeWalker <GridControl> .Execute(widget.View, grid =>
                        {
                            using (var ms = new MemoryStream())
                            {
                                grid.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, grid =>
                        {
                            using (var ms = new MemoryStream())
                            {
                                grid.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
                                }
                                                            );
                            }
                        });
                    }
                });
            }
        }
Exemplo n.º 6
0
        public BaseWorkspace(bool loadLayout = true)
        {
            _id = Guid.NewGuid();

            //This whole code is ugly... but mandatory... Binding With DockManager ItemsSource is lost when restoring the widgets.
            {
                this.ExecuteOnCurrentDispatcher(() =>
                {
                    if (null == View)
                    {
                        return;
                    }

                    View.WidgetDockManager.DockItemClosed += (sender, e) =>
                    {
                        var widget = e.Item.DataContext as IWidget;

                        if (null == widget)
                        {
                            return;
                        }

                        this.ExecuteOnCurrentDispatcher(() =>
                        {
                            widget.Dispose();
                            Widgets.Remove(widget);
                        });
                    };
                });

                Widgets = new SmartReactiveList <IWidget>();
                var itemAddedObservable = Observable
                                          .FromEventPattern <NotifyCollectionChangedEventArgs>(Widgets, "CollectionChanged")
                                          .Where(change => change.EventArgs.Action == NotifyCollectionChangedAction.Reset || change.EventArgs.Action == NotifyCollectionChangedAction.Remove)
                                          .Select(change => change.EventArgs)
                                          .Where(change => change != null)
                                          .Subscribe(change =>
                {
                    if (change.OldItems == null)
                    {
                        var panels = new List <LayoutPanel>();

                        VisualTreeWalker <LayoutPanel> .Execute(View, panel =>
                        {
                            panels.Add(panel);
                        });

                        foreach (var panel in panels)
                        {
                            View.WidgetDockManager.DockController.Close(panel);
                        }
                    }
                    else
                    {
                        foreach (var item in change.OldItems)
                        {
                            VisualTreeWalker <LayoutPanel> .Execute(View, panel =>
                            {
                                if (panel.DataContext != item)
                                {
                                    return;
                                }
                                View.WidgetDockManager.DockController.Close(panel);
                            });
                        }
                        ;
                    }
                });
            }

            var notIsLoading = this.WhenAny(z => z.IsLoading, z => !IsLoading);

            ClearCurrentLayout = ReactiveCommand.Create(() => Widgets.Clear(), this.WhenAny(z => z.IsLoading, (x) => !IsLoading));

            SaveLayoutAsFile = ReactiveCommand.Create(() =>
            {
                var layout = GetCurrentLayout();

                var dialog = new SaveFileDialog()
                {
                    FileName   = String.Format("LAYOUT_FOR_{0}", State.Name.Replace(" ", "_")),
                    DefaultExt = layoutDefaultExt,
                    Filter     = layoutDefaultFilter
                };

                if (dialog.ShowDialog() == true)
                {
                    var formatter = new BinaryFormatter();
                    var stream    = new FileStream(dialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None);
                    formatter.Serialize(stream, layout);
                    stream.Close();
                }
            });

            SaveLayout = ReactiveCommand.CreateFromTask(() => SaveCurrentLayoutAsDefault(), notIsLoading);

            LoadLayoutFromFile = ReactiveCommand.Create(async() =>
            {
                var dialog = new OpenFileDialog()
                {
                    Multiselect = false,
                    Filter      = layoutDefaultFilter
                };

                if (dialog.ShowDialog() == true)
                {
                    var stream    = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    var formatter = new BinaryFormatter();
                    var layout    = (WorkspaceLayout)formatter.Deserialize(stream);
                    await LoadLayout(layout);
                }
            }, notIsLoading);

            SaveTaggedLayout   = ReactiveCommand.Create(SaveCurrentLayoutAsTagged, this.WhenAny(vm => vm.IsLoading, vm => vm.TaggedLayoutLabel, (isloading, taggedLayoutName) => !isloading.Value && !String.IsNullOrEmpty(taggedLayoutName.Value)));
            DeleteTaggedLayout = ReactiveCommand.Create <WorkspaceLayout>((workspaceLayout) =>
            {
            }, notIsLoading);

            LoadTaggedLayout = ReactiveCommand.Create <WorkspaceLayout>(async(workspaceLayout) =>
            {
                await LoadLayout(workspaceLayout);
            }, notIsLoading);

            SaveTemplateLayout = ReactiveCommand.CreateFromTask(SaveCurrentLayoutAsTemplate, this.WhenAny(z => z.IsLoading, (x) => !IsLoading));

            OpenNewWorkspace = ReactiveCommand.Create(() =>
            {
                Dashboard.CreateWorkspace(State, false);
            });

            if (loadLayout)
            {
                this.ExecuteOnCurrentDispatcher(async() =>
                {
                    var layout = await FindRelevantLayout();

                    if (null == layout)
                    {
                        return;
                    }

                    await LoadLayout(layout);
                });
            }
        }
Exemplo n.º 7
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);
        }