/* * 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); } } } }
public void CreateDefaultLayout(List <UserControl> documentViews, List <UserControl> toolViews) { IDockPaneHost.Clear(); /* * We descend the tree level by level, adding a new level when the current one is full. * We continue adding nodes until we have exhausted the items in views (created above). * * Parent Level Index * G 1 * / \ * G DP 2 * / \ / \ * T T D D 3 * * Key: * * G = Grid * T = Tool * DP = Document Panel: the root ancestor of all documents. * D = Documents * * Assume we are building level N where there are potentially 2 ^ (N-1) nodes (denoted by a star). * Maintain two node lists. One for level N and one for level N + 1. * List for level N is denoted list(N). * Assume level N nodes are complete. * Then for each item in list(N) we add two child nodes, and then add these child nodes to list (N+1). * * First level: * * D1 * * Add a node -> replace D1 with a grid containing two documents and a splitter: * * G * / \ * D1 D2 * * Add a node -> replace D1 with a grid containing two documents and a splitter: * * G * / \ * G D2 * / \ * D1 D3 * * Add a node -> replace D2 with a grid containing two documents and a splitter: * * G * / \ * G G * / \ / \ * D1 D3 D2 D4 * * and so on ... * * Document panes are children of a dock panel. At first this is a child of the top level * splitter pane, or the layout manager if there are no tool panes * */ IDockPaneHost.RootPane = ILayoutFactory.MakeSplitterPane(true); DocumentPanel documentPanel = ILayoutFactory.MakeDocumentPanel(); (IDockPaneHost.RootPane as SplitterPane).AddChild(documentPanel, true); if ((documentViews != null) && (documentViews.Count > 0)) { List <FrameworkElement> list_N = new List <FrameworkElement>(); DockPane documentPane = ILayoutFactory.MakeDocumentPaneGroup(); documentPane.IViewContainer.AddUserControl(documentViews[0]); documentPanel.Children.Add(documentPane); list_N.Add(documentPane); AddViews(documentViews, list_N, delegate { return(ILayoutFactory.MakeDocumentPaneGroup()); }); } if ((toolViews != null) && (toolViews.Count > 0)) { List <FrameworkElement> list_N = new List <FrameworkElement>(); DockPane toolPaneGroup = ILayoutFactory.MakeToolPaneGroup(); toolPaneGroup.IViewContainer.AddUserControl(toolViews[0]); (IDockPaneHost.RootPane as SplitterPane).AddChild(toolPaneGroup, false); list_N.Add(toolPaneGroup); AddViews(toolViews, list_N, delegate { return(ILayoutFactory.MakeToolPaneGroup()); }); } }
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); } }
public void UnpinToolPane(ToolPaneGroup toolPaneGroup, out UnpinnedToolData unpinnedToolData, out WindowLocation toolListBoxLocation) { System.Diagnostics.Trace.Assert(toolPaneGroup != null); DocumentPanel documentPanel = FindElementOfType(typeof(DocumentPanel), IDockPaneHost.RootPane) as DocumentPanel; System.Diagnostics.Trace.Assert(documentPanel != null); List <Grid> documentPanelAncestors = new List <Grid>(); Grid grid = documentPanel; while (grid.Parent != IDockPaneHost) { grid = grid.Parent as SplitterPane; documentPanelAncestors.Add(grid); } /* * Find the first common ancestor for the document panel and the tool pane group */ FrameworkElement frameworkElement = toolPaneGroup; while (true) { if (documentPanelAncestors.Contains(frameworkElement.Parent as Grid)) { break; } frameworkElement = frameworkElement.Parent as FrameworkElement; } toolListBoxLocation = WindowLocation.None; bool isFirst = (Grid.GetRow(frameworkElement) == 0) && (Grid.GetColumn(frameworkElement) == 0); bool isHorizontal = (frameworkElement.Parent as SplitterPane).IsHorizontal; if (isHorizontal) { if (isFirst) { toolListBoxLocation = WindowLocation.TopSide; } else { toolListBoxLocation = WindowLocation.BottomSide; } } else { if (isFirst) { toolListBoxLocation = WindowLocation.LeftSide; } else { toolListBoxLocation = WindowLocation.RightSide; } } unpinnedToolData = new UnpinnedToolData(); unpinnedToolData.ToolPaneGroup = toolPaneGroup; Grid parentGrid = toolPaneGroup.Parent as Grid; unpinnedToolData.IsFirst = (Grid.GetRow(toolPaneGroup) == 0) && (Grid.GetColumn(toolPaneGroup) == 0); unpinnedToolData.IsHorizontal = (parentGrid as SplitterPane).IsHorizontal; ExtractDockPane(toolPaneGroup, out frameworkElement); System.Diagnostics.Trace.Assert(frameworkElement != null); unpinnedToolData.SiblingGuid = (Guid)((frameworkElement as Grid).Tag); }
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(); }); }