Ejemplo n.º 1
0
        /// <summary>
        /// 从布局信息构造节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="windowList"></param>
        /// <param name="onWindowClose"></param>
        public virtual void CreateFromLayoutCfg(XmlElement node, List <SubWindow> windowList,
                                                System.Action <SubWindow> onWindowClose)
        {
            string weightStr     = node.GetAttribute("Weight");
            string depthStr      = node.GetAttribute("Depth");
            string horizontalStr = node.GetAttribute("Horizontal");

            weight       = float.Parse(weightStr);
            depth        = int.Parse(depthStr);
            isHorizontal = bool.Parse(horizontalStr);
            XmlNodeList nodes = node.ChildNodes;

            if (nodes.Count == 0)
            {
                return;
            }
            XmlElement[] sortnode = new XmlElement[nodes.Count];
            foreach (var n in nodes)
            {
                XmlElement nd       = (XmlElement)n;
                string     indexstr = nd.GetAttribute("Index");
                int        index    = int.Parse(indexstr);
                sortnode[index] = nd;
            }
            foreach (var n in sortnode)
            {
                if (n.Name == "SubWindowNode")
                {
                    SubWindowNode swnode = new SubWindowNode(true, 0);
                    swnode.CreateFromLayoutCfg(n, windowList, onWindowClose);
                    this.m_Childs.Add(swnode);
                }
                else if (n.Name == "SubWindowLeaf")
                {
                    SubWindowLeaf swleaf = new SubWindowLeaf(null, true, 0);
                    swleaf.CreateFromLayoutCfg(n, windowList, onWindowClose);
                    this.m_Childs.Add(swleaf);
                }
            }
        }
Ejemplo n.º 2
0
        private bool UseLayout(string layoutName)
        {
            if (string.IsNullOrEmpty(layoutName))
            {
                return(false);
            }
            string treeId = GetTreeIndentifier();

            if (string.IsNullOrEmpty(treeId))
            {
                return(false);
            }
            if (m_Layout == null)
            {
                return(false);
            }
            if (m_Root == null)
            {
                m_Root = new SubWindowNode(true, 0);
            }
            var element = m_Layout.UseLayout(layoutName, treeId);

            if (element == null)
            {
                return(false);
            }
            for (int i = 0; i < m_SubWindowList.Count; i++)
            {
                if (m_SubWindowList[i].IsOpen)
                {
                    m_SubWindowList[i].Close();
                }
            }

            m_Root.CreateFromLayoutCfg(element, m_SubWindowList, m_OnSubWindowClose);
            m_Root.ClearEmptyNode();
            m_Root.Recalculate(0, true);

            return(true);
        }