예제 #1
0
        private static XmlElement AddFloatingToolPaneGroupNode(XmlDocument xmlDocument, XmlNode xmlParentNode, FloatingToolPaneGroup floatingToolPaneGroup)
        {
            System.Diagnostics.Trace.Assert(xmlDocument != null);
            System.Diagnostics.Trace.Assert(xmlParentNode != null);

            XmlElement xmlFloatingToolPaneGroup = xmlDocument.CreateElement("FloatingToolPaneGroup");

            AddPositionAndSizeAttributes(xmlDocument, xmlFloatingToolPaneGroup, floatingToolPaneGroup);
            AddGuidAttribute(xmlDocument, xmlFloatingToolPaneGroup, floatingToolPaneGroup);

            xmlParentNode.AppendChild(xmlFloatingToolPaneGroup);

            int count = floatingToolPaneGroup.IViewContainer.GetUserControlCount();

            System.Diagnostics.Trace.Assert(count > 0, "Floating tool pane has no tools");

            for (int index = 0; index < count; ++index)
            {
                UserControl userControl = floatingToolPaneGroup.IViewContainer.GetUserControl(index);
                if (userControl == null)
                {
                    break;
                }
                AddToolNode(xmlDocument, xmlFloatingToolPaneGroup, userControl.DataContext as IViewModel, userControl.Name);
            }

            return(xmlFloatingToolPaneGroup);
        }
예제 #2
0
        public static void LoadNode(ILayoutFactory iLayoutFactory, Dictionary <string, UserControl> viewsMap, FrameworkElement rootFrameworkElement, FrameworkElement parentFrameworkElement, XmlNode xmlParentElement, bool isParentHorizontal)
        {
            int row             = 0;
            int rowIncrement    = isParentHorizontal ? 2 : 0;
            int column          = 0;
            int columnIncrement = isParentHorizontal ? 0 : 2;

            foreach (var xmlChildNode in xmlParentElement.ChildNodes)
            {
                if (xmlChildNode is XmlElement)
                {
                    if ((xmlChildNode as XmlElement).Name == "SplitterPane")
                    {
                        XmlElement xmlSplitterPane = xmlChildNode as XmlElement;

                        XmlAttribute xmlAttribute = xmlSplitterPane.Attributes.GetNamedItem("Orientation") as XmlAttribute;

                        System.Diagnostics.Trace.Assert(xmlAttribute != null, "SplitterPane element does not have an orientation attribute");

                        bool isChildHorizontal = xmlAttribute.Value == "Horizontal";

                        SplitterPane newGrid = iLayoutFactory.MakeSplitterPane(isChildHorizontal);
                        newGrid.Tag = GetGuid(xmlSplitterPane);

                        if (parentFrameworkElement == rootFrameworkElement)
                        {
                            iLayoutFactory.SetRootPane(newGrid, out row, out column);
                        }
                        else
                        {
                            System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                            parentElement.AddChild(newGrid);
                            Grid.SetRow(newGrid, row);
                            Grid.SetColumn(newGrid, column);
                        }
                        SetWidthOrHeight(xmlSplitterPane, parentFrameworkElement, isParentHorizontal, row, column);

                        row    += rowIncrement;
                        column += columnIncrement;

                        LoadNode(iLayoutFactory, viewsMap, rootFrameworkElement, newGrid, xmlSplitterPane, isChildHorizontal);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "DocumentPanel")
                    {
                        DocumentPanel documentPanel = iLayoutFactory.MakeDocumentPanel();

                        if (parentFrameworkElement == rootFrameworkElement)
                        {
                            iLayoutFactory.SetRootPane(documentPanel, out row, out column);
                        }
                        else
                        {
                            System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                            parentElement.AddChild(documentPanel);
                            Grid.SetRow(documentPanel, row);
                            Grid.SetColumn(documentPanel, column);
                        }

                        XmlElement xmlDocumentPanel = xmlChildNode as XmlElement;
                        SetWidthOrHeight(xmlDocumentPanel, parentFrameworkElement, isParentHorizontal, row, column);

                        row    += rowIncrement;
                        column += columnIncrement;

                        LoadNode(iLayoutFactory, viewsMap, rootFrameworkElement, documentPanel, xmlDocumentPanel, true);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "DocumentPaneGroup")
                    {
                        DocumentPaneGroup documentPaneGroup = iLayoutFactory.MakeDocumentPaneGroup();

                        System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                        parentElement.AddChild(documentPaneGroup);

                        XmlElement xmlDocumentGroup = xmlChildNode as XmlElement;

                        documentPaneGroup.Tag = GetGuid(xmlDocumentGroup);;
                        SetWidthOrHeight(xmlDocumentGroup, parentFrameworkElement, isParentHorizontal, row, column);

                        LoadDocuments(iLayoutFactory, viewsMap, xmlDocumentGroup, documentPaneGroup.IViewContainer);
                        Grid.SetRow(documentPaneGroup, row);
                        Grid.SetColumn(documentPaneGroup, column);
                        row    += rowIncrement;
                        column += columnIncrement;
                    }
                    else if ((xmlChildNode as XmlElement).Name == "ToolPaneGroup")
                    {
                        ToolPaneGroup toolPaneGroup = iLayoutFactory.MakeToolPaneGroup();

                        System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                        parentElement.AddChild(toolPaneGroup);

                        XmlElement xmlToolPaneGroup = xmlChildNode as XmlElement;

                        toolPaneGroup.Tag = GetGuid(xmlToolPaneGroup);
                        SetWidthOrHeight(xmlToolPaneGroup, parentFrameworkElement, isParentHorizontal, row, column);

                        LoadTools(viewsMap, xmlToolPaneGroup, toolPaneGroup.IViewContainer);
                        Grid.SetRow(toolPaneGroup, row);
                        Grid.SetColumn(toolPaneGroup, column);
                        row    += rowIncrement;
                        column += columnIncrement;
                    }
                    else if ((xmlChildNode as XmlElement).Name == "FloatingToolPaneGroup")
                    {
                        FloatingToolPaneGroup floatingToolPaneGroup = iLayoutFactory.MakeFloatingToolPaneGroup();
                        XmlElement            xmlfloatingTool       = xmlChildNode as XmlElement;
                        floatingToolPaneGroup.Tag = GetGuid(xmlfloatingTool);
                        SetLocationAndSize(xmlfloatingTool, floatingToolPaneGroup);
                        LoadTools(viewsMap, xmlfloatingTool, floatingToolPaneGroup.IViewContainer);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "FloatingDocumentPaneGroup")
                    {
                        FloatingDocumentPaneGroup floatingDocumentPaneGroup = iLayoutFactory.MakeFloatingDocumentPaneGroup();
                        XmlElement xmlfloatingDocument = xmlChildNode as XmlElement;
                        floatingDocumentPaneGroup.Tag = GetGuid(xmlfloatingDocument);
                        SetLocationAndSize(xmlfloatingDocument, floatingDocumentPaneGroup);
                        LoadDocuments(iLayoutFactory, viewsMap, xmlfloatingDocument, floatingDocumentPaneGroup.IViewContainer);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "LeftSide")
                    {
                        XmlElement xmlLeftSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.LeftSide, xmlLeftSide);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "TopSide")
                    {
                        XmlElement xmlTopSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.TopSide, xmlTopSide);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "RightSide")
                    {
                        XmlElement xmlRightSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.RightSide, xmlRightSide);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "BottomSide")
                    {
                        XmlElement xmlBottomSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.BottomSide, xmlBottomSide);
                    }
                }

                if (parentFrameworkElement != rootFrameworkElement)
                {
                    if ((row > 2) || (column > 2))
                    {
                        // we can only have two child elements (plus a splitter) in each grid
                        break;
                    }
                }
            }
        }