Пример #1
0
        private void InsertDockPane(Grid parentSplitterPane, SelectablePane selectablePane, DockPane dockPaneToInsert, bool isHorizontalSplit)
        {
            parentSplitterPane.Children.Remove(selectablePane);

            SplitterPane newGrid = ILayoutFactory.MakeSplitterPane(isHorizontalSplit);

            parentSplitterPane.Children.Add(newGrid);
            Grid.SetRow(newGrid, Grid.GetRow(selectablePane));
            Grid.SetColumn(newGrid, Grid.GetColumn(selectablePane));

            newGrid.AddChild(selectablePane, true);
            newGrid.AddChild(dockPaneToInsert, false);
        }
Пример #2
0
        private void AddViews(List <UserControl> views, List <FrameworkElement> list_N, DelegateCreateDockPane createDockPane)
        {
            List <FrameworkElement> list_N_plus_1 = new List <FrameworkElement>();
            bool isHorizontal = false;
            int  viewIndex    = 1;

            while (viewIndex < views.Count)
            {
                for (int i = 0; (i < list_N.Count) && (viewIndex < views.Count); ++i)
                {
                    SplitterPane splitterPane = ILayoutFactory.MakeSplitterPane(isHorizontal);

                    var node = list_N[i];
                    System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)node.Parent;
                    (node.Parent as Grid).Children.Remove(node);

                    parentElement.AddChild(splitterPane);
                    Grid.SetRow(splitterPane, Grid.GetRow(node));
                    Grid.SetColumn(splitterPane, Grid.GetColumn(node));

                    splitterPane.AddChild(node, true);

                    list_N_plus_1.Add(node);

                    node = views[viewIndex];
                    DockPane dockPane = createDockPane();
                    dockPane.IViewContainer.AddUserControl(node as UserControl);

                    list_N_plus_1.Add(dockPane);

                    splitterPane.AddChild(dockPane, false);

                    ++viewIndex;
                }

                isHorizontal  = !isHorizontal;
                list_N        = list_N_plus_1;
                list_N_plus_1 = new List <FrameworkElement>();
            }
        }
Пример #3
0
        /*
         * Remove tool panes with no corresponding IViewModel
         * Ensure there is a tool pane for each IViewModel
         */
        public void ValidateDockPanes(Grid grid, Dictionary <IViewModel, List <string> > viewModelUrlDictionary, Type paneType)
        {
            List <DockPane> emptyDockPanes = new List <DockPane>();

            ValidateDockPanes(IDockPaneHost.RootPane, viewModelUrlDictionary, emptyDockPanes, paneType);

            /*
             * Remove dock panes with no matching view model
             */

            foreach (var dockPane in emptyDockPanes)
            {
                ExtractDockPane(dockPane, out FrameworkElement frameworkElement);
            }

            if (viewModelUrlDictionary.Count > 0)
            {
                if (paneType == typeof(DocumentPaneGroup))
                {
                    DockPane siblingDockPane = FindElementOfType(typeof(DocumentPaneGroup), IDockPaneHost.RootPane) as DockPane;
                    if (siblingDockPane == null)
                    {
                        siblingDockPane = ILayoutFactory.MakeDocumentPaneGroup();

                        // There is always a document panel
                        DocumentPanel documentPanel = FindElementOfType(typeof(DocumentPanel), IDockPaneHost.RootPane) as DocumentPanel;
                        documentPanel.Children.Add(siblingDockPane);
                    }
                    System.Diagnostics.Trace.Assert(siblingDockPane != null);

                    List <UserControl> userControls = IDockPaneHost.LoadDocumentViews(new ObservableCollection <IViewModel>(viewModelUrlDictionary.Keys));
                    foreach (UserControl userControl in userControls)
                    {
                        siblingDockPane.IViewContainer.AddUserControl(userControl);
                    }
                }
                else if (paneType == typeof(ToolPaneGroup))
                {
                    DockPane siblingDockPane = FindElementOfType(typeof(ToolPaneGroup), IDockPaneHost.RootPane) as DockPane;
                    if (siblingDockPane == null)
                    {
                        siblingDockPane = ILayoutFactory.MakeToolPaneGroup();

                        if (IDockPaneHost.RootPane is DocumentPanel)
                        {
                            DocumentPanel documentPanel = IDockPaneHost.RootPane as DocumentPanel;

                            SplitterPane splitterPane = ILayoutFactory.MakeSplitterPane(true);
                            IDockPaneHost.RootPane = splitterPane;
                            splitterPane.AddChild(documentPanel, true);
                            splitterPane.AddChild(siblingDockPane, false);
                        }
                        else
                        {
                            // There is always a document panel
                            DocumentPanel documentPanel = FindElementOfType(typeof(DocumentPanel), IDockPaneHost.RootPane) as DocumentPanel;

                            InsertDockPane(IDockPaneHost.RootPane, documentPanel, siblingDockPane, false);
                        }
                    }
                    System.Diagnostics.Trace.Assert(siblingDockPane != null);

                    List <UserControl> userControls = IDockPaneHost.LoadToolViews(new ObservableCollection <IViewModel>(viewModelUrlDictionary.Keys));
                    foreach (UserControl userControl in userControls)
                    {
                        siblingDockPane.IViewContainer.AddUserControl(userControl);
                    }
                }
            }
        }
Пример #4
0
        public void PinToolPane(UnpinnedToolData unpinnedToolData, WindowLocation defaultWindowLocation)
        {
            Grid sibling = null;

            if (unpinnedToolData.SiblingGuid == (Guid)IDockPaneHost.RootGrid.Tag)
            {
                sibling = IDockPaneHost.RootGrid;
            }
            else
            {
                sibling = FindElement(unpinnedToolData.SiblingGuid, IDockPaneHost.RootGrid);
            }

            // This can happen when loading a layout
            bool isHorizontal = unpinnedToolData.IsHorizontal;
            bool isFirst      = unpinnedToolData.IsFirst;

            if (sibling == null)
            {
                sibling      = IDockPaneHost as Grid;
                isHorizontal = (defaultWindowLocation == WindowLocation.TopSide) || (defaultWindowLocation == WindowLocation.BottomSide);
                isFirst      = (defaultWindowLocation == WindowLocation.TopSide) || (defaultWindowLocation == WindowLocation.LeftSide);
            }

            SplitterPane newSplitterPane = ILayoutFactory.MakeSplitterPane(isHorizontal);

            if (sibling == IDockPaneHost)
            {
                IEnumerable <SplitterPane> enumerableSplitterPanes = IDockPaneHost.Children.OfType <SplitterPane>();
                if (enumerableSplitterPanes.Count() == 1)
                {
                    SplitterPane splitterPane = enumerableSplitterPanes.First();

                    IDockPaneHost.RootPane = newSplitterPane;
                    newSplitterPane.AddChild(splitterPane, !isFirst);
                    newSplitterPane.AddChild(unpinnedToolData.ToolPaneGroup, isFirst);
                }
                else
                {
                    IEnumerable <DocumentPanel> enumerableDocumentPanels = IDockPaneHost.Children.OfType <DocumentPanel>();
                    System.Diagnostics.Trace.Assert(enumerableDocumentPanels.Count() == 1);

                    DocumentPanel documentPanel = enumerableDocumentPanels.First();

                    IDockPaneHost.RootPane = newSplitterPane;
                    newSplitterPane.AddChild(documentPanel, !isFirst);
                    newSplitterPane.AddChild(unpinnedToolData.ToolPaneGroup, isFirst);
                }
            }
            else if (sibling.Parent == IDockPaneHost)
            {
                IDockPaneHost.RootPane = newSplitterPane;
                newSplitterPane.AddChild(sibling, !isFirst);
                newSplitterPane.AddChild(unpinnedToolData.ToolPaneGroup, isFirst);
            }
            else
            {
                SplitterPane parentSplitterPane = sibling.Parent as SplitterPane;
                int          row    = Grid.GetRow(sibling);
                int          column = Grid.GetColumn(sibling);
                isFirst = (parentSplitterPane.IsHorizontal && (row == 0)) || (!parentSplitterPane.IsHorizontal && (column == 0));
                parentSplitterPane.Children.Remove(sibling);

                parentSplitterPane.AddChild(newSplitterPane, isFirst);

                newSplitterPane.AddChild(sibling, !unpinnedToolData.IsFirst);
                newSplitterPane.AddChild(unpinnedToolData.ToolPaneGroup, unpinnedToolData.IsFirst);
            }
        }
Пример #5
0
        public void Unfloat(FloatingPane floatingPane, SelectablePane selectedPane, WindowLocation windowLocation)
        {
            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                if (
                    (floatingPane == null) ||
                    ((selectedPane != null) && !(selectedPane.Parent is SplitterPane) && !(selectedPane.Parent is DocumentPanel) && (selectedPane.Parent != IDockPaneHost))
                    )
                {
                    return;
                }

                SplitterPane parentSplitterPane = null;
                DockPane dockPane = null;

                switch (windowLocation)
                {
                case WindowLocation.BottomSide:
                case WindowLocation.TopSide:
                case WindowLocation.LeftSide:
                case WindowLocation.RightSide:

                    if (floatingPane is FloatingToolPaneGroup)
                    {
                        dockPane = ILayoutFactory.MakeToolPaneGroup();
                    }
                    else
                    {
                        dockPane = ILayoutFactory.MakeDocumentPaneGroup();
                    }
                    dockPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer);
                    floatingPane.Close();

                    parentSplitterPane = ILayoutFactory.MakeSplitterPane((windowLocation == WindowLocation.TopSide) || (windowLocation == WindowLocation.BottomSide));
                    bool isFirst       = (windowLocation == WindowLocation.TopSide) || (windowLocation == WindowLocation.LeftSide);
                    parentSplitterPane.AddChild(dockPane, isFirst);

                    if (IDockPaneHost.Children.Count == 0)
                    {
                        IDockPaneHost.Children.Add(parentSplitterPane);
                    }
                    else
                    {
                        Grid rootPane          = IDockPaneHost.RootPane;
                        IDockPaneHost.RootPane = parentSplitterPane;
                        parentSplitterPane.AddChild(rootPane, !isFirst);
                    }
                    break;

                case WindowLocation.Right:
                case WindowLocation.Left:
                case WindowLocation.Top:
                case WindowLocation.Bottom:

                    if (floatingPane is FloatingToolPaneGroup)
                    {
                        dockPane = ILayoutFactory.MakeToolPaneGroup();
                    }
                    else
                    {
                        dockPane = ILayoutFactory.MakeDocumentPaneGroup();
                    }
                    dockPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer);
                    floatingPane.Close();

                    SplitterPane newGrid = ILayoutFactory.MakeSplitterPane((windowLocation == WindowLocation.Top) || (windowLocation == WindowLocation.Bottom));

                    if (selectedPane.Parent is DocumentPanel)
                    {
                        DocumentPanel documentPanel = selectedPane.Parent as DocumentPanel;
                        documentPanel.Children.Remove(selectedPane);
                        documentPanel.Children.Add(newGrid);
                    }
                    else
                    {
                        parentSplitterPane = (selectedPane.Parent as SplitterPane);
                        parentSplitterPane.Children.Remove(selectedPane);
                        parentSplitterPane.Children.Add(newGrid);
                        Grid.SetRow(newGrid, Grid.GetRow(selectedPane));
                        Grid.SetColumn(newGrid, Grid.GetColumn(selectedPane));
                    }

                    bool isTargetFirst = (windowLocation == WindowLocation.Right) || (windowLocation == WindowLocation.Bottom);
                    newGrid.AddChild(selectedPane, isTargetFirst);
                    newGrid.AddChild(dockPane, !isTargetFirst);
                    break;

                case WindowLocation.Middle:

                    if (selectedPane is DockPane)
                    {
                        (selectedPane as DockPane).IViewContainer.ExtractDocuments(floatingPane.IViewContainer);
                        floatingPane.Close();
                    }
                    else if (selectedPane is DocumentPanel)
                    {
                        DocumentPaneGroup documentPaneGroup = ILayoutFactory.MakeDocumentPaneGroup();
                        selectedPane.Children.Add(documentPaneGroup);
                        documentPaneGroup.IViewContainer.ExtractDocuments(floatingPane.IViewContainer);
                        floatingPane.Close();
                    }
                    break;
                }

                Application.Current.MainWindow.Activate();
            });
        }