Ejemplo n.º 1
0
        public void Split(FilesystemView fsView, SplitterType type)
        {
            var        RootWidget = fsView.RootWidget;
            FSViewNode vn         = RootWidget.Components.Get <ViewNodeComponent>().ViewNode as FSViewNode;

            var newFsView = new FilesystemView();

            views.Add(newFsView);
            var newVn = new FSViewNode {
                Widget = newFsView.RootWidget,
                Path   = vn.Path,
                ShowSelectionPreview   = vn.ShowSelectionPreview,
                ShowCookingRulesEditor = vn.ShowCookingRulesEditor,
            };

            // TODO: setup internal stretches of fsView here
            newFsView.RootWidget.Components.Add(new ViewNodeComponent {
                ViewNode = newVn
            });
            newFsView.Initialize();

            if (vn.Parent == null)
            {
                // Root node, need to replace on in UserPreferences
                Splitter s  = type.MakeSplitter();
                var      up = FilesystemUserPreferences.Instance;
                var      sn = new SplitterNode {
                    Widget = s,
                    Type   = type
                };
                up.ViewRoot  = sn;
                newVn.Parent = sn;
                s.Stretches  = Splitter.GetStretchesList(sn.Stretches, 1, 1);
                sn.Children.Add(vn);
                sn.Children.Add(newVn);
                var thisParent = RootWidget.ParentWidget;
                RootWidget.Unlink();
                s.AddNode(RootWidget);
                s.AddNode(newFsView.RootWidget);
                s.Components.Add(new ViewNodeComponent {
                    ViewNode = sn
                });
                vn.Parent = sn;
                thisParent.Nodes.Add(s);

                // TODO setup stretches ^
            }
            else if (vn.Parent is SplitterNode)
            {
                if ((vn.Parent as SplitterNode).Type == type)
                {
                    var sn = vn.Parent as SplitterNode;
                    var s  = sn.Widget;
                    s.Nodes.Insert(s.Nodes.IndexOf(RootWidget), newFsView.RootWidget);
                    newVn.Parent = sn;
                    sn.Children.Insert(sn.Children.IndexOf(vn), newVn);
                }
                else
                {
                    Splitter s  = type.MakeSplitter();
                    var      sn = new SplitterNode {
                        Widget = s,
                        Type   = type
                    };
                    s.Components.Add(new ViewNodeComponent {
                        ViewNode = sn
                    });
                    s.Stretches = Splitter.GetStretchesList(sn.Stretches);

                    var psn = vn.Parent as SplitterNode;

                    // or vn.Parent.Widget
                    int thisIndex  = RootWidget.ParentWidget.Nodes.IndexOf(RootWidget);
                    var thisParent = RootWidget.ParentWidget;
                    RootWidget.Unlink();
                    s.AddNode(RootWidget);
                    s.AddNode(newFsView.RootWidget);
                    sn.Children.Add(vn);
                    sn.Children.Add(newVn);
                    vn.Parent    = sn;
                    newVn.Parent = sn;
                    thisParent.Nodes.Insert(thisIndex, s);


                    var ps = psn.Widget;
                    sn.Parent = psn;
                    psn.Children.RemoveAt(thisIndex);
                    psn.Children.Insert(thisIndex, sn);
                }
            }
            else if (vn.Parent is FSViewNode)
            {
                // wat
            }
        }