private void FloatingPane_EndDrag(object sender, EventArgs e)
        {
            System.Diagnostics.Trace.Assert(sender is FloatingPane, System.Reflection.MethodBase.GetCurrentMethod().Name + ": sender not a FloatingPane");
            Application.Current.Dispatcher.Invoke(delegate
            {
                FloatingPane floatingPane = sender as FloatingPane;

                if (
                    (floatingPane == null) ||
                    ((SelectedPane != null) && !(SelectedPane is FloatingPane) && !(SelectedPane.Parent is SplitterPane) && !(SelectedPane.Parent is DocumentPanel) && (SelectedPane.Parent != IFloatingPaneHost.RootGrid)) ||
                    (_insertionIndicatorManager == null) ||
                    (_insertionIndicatorManager.WindowLocation == WindowLocation.None)
                    )
                {
                    if (floatingPane != null)
                    {
                        floatingPane.Close();
                    }
                    CancelSelection();
                    return;
                }

                ISelectablePane selectedPane  = SelectedPane;
                WindowLocation windowLocation = _insertionIndicatorManager.WindowLocation;
                CancelSelection();

                if (selectedPane is FloatingPane)
                {
                    IFloatingPane selectedFloatingPane = selectedPane as IFloatingPane;
                    selectedFloatingPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer);
                    if (floatingPane is FloatingToolPaneGroup)
                    {
                        FloatingToolPaneGroups.Remove(floatingPane);
                    }
                    else
                    {
                        FloatingDocumentPaneGroups.Remove(floatingPane);
                    }
                    floatingPane.Close();
                }
                else
                {
                    IFloatingPaneHost.Unfloat(floatingPane, selectedPane as SelectablePane, windowLocation);
                }

                Application.Current.MainWindow.Activate();
            });
        }
Example #2
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();
            });
        }