Exemple #1
0
        /// <summary>
        /// 更新树的子节点路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parentTreeNode"></param>
        private void updateChildTreeNodePath(string path, GxTreeNode parentTreeNode)
        {
            foreach (GxTreeNode node in parentTreeNode.Nodes)
            {
                //更新树节点路径
                GxNodeData treeNodeData = (GxNodeData)node.Tag;
                if (treeNodeData != null)
                {
                    //取得文件名
                    string filename = Path.GetFileName(treeNodeData.getPath());
                    string fullPath = path + "\\" + filename;
                    treeNodeData.setPath(GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR) + "\\" + fullPath);

                    if (node.Nodes.Count > 0)
                    {
                        updateChildTreeNodePath(fullPath, node);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 创建一个新的场景文件
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="filename"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>

        /*public bool createNewScene(string sceneName, string filename, GxTreeNode parentNode = null)
         * {
         *  if (sceneName.Length == 0 || filename.Length == 0)
         *  {
         *      Logger.Warn("sceneName.Length == 0 || filename.Length == 0");
         *      return false;
         *  }
         *
         *  //如果文件已经存在则返回
         *  if (File.Exists(filename) == true)
         *  {
         *      Logger.Error("Create scene file failed, file is exists.");
         *      return false;
         *  }
         *
         *  XmlDocument newSceneXmlDoc = new XmlDocument();
         *  newSceneXmlDoc.Save(filename);
         *
         *  return true;
         * }*/

        /// <summary>
        /// 以默认目录名新建一个目录
        /// </summary>
        /// <param name="directoryName"></param>
        /// <param name="dirPath"></param>
        /// <returns></returns>
        public bool createNewDirectory(GxTreeNode parentNode)
        {
            GxTreeNode treeNode = (GxTreeNode)parentNode;

            if (treeNode == null)
            {
                return(false);
            }

            GxNodeData nodeDataBase = (GxNodeData)parentNode.Tag;

            if (nodeDataBase != null)
            {
                string parentPath = "";

                //if (treeNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_DIRECTORY)
                //{
                parentPath = nodeDataBase.getPath();
                //}
                // else if (treeNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_PROJECT)
                //{
                //   parentPath = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR);
                //}

                Logger.Debug("parent full path = " + Path.GetFullPath(parentPath));
                if (Directory.Exists(parentPath) == true)
                {
                    //循环创建文件夹并找到一个不存在的计数,作为默认文件夹
                    int          count = 1;
                    const string defaultDirectoryName = "新建场景目录";

                    string newDirectoryName     = "";
                    string newDirectoryFullPath = "";

                    while (true)
                    {
                        newDirectoryName     = defaultDirectoryName + count.ToString();
                        newDirectoryFullPath = parentPath + "\\" + newDirectoryName;

                        //目录如果存在,则计数+1
                        if (Directory.Exists(newDirectoryFullPath) == true)
                        {
                            Logger.Info("[" + newDirectoryFullPath + "] is exists.");
                            count++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    //取得父节点XML对象,创建文件夹节点到XML
                    XmlNode    parentXmlNode          = nodeDataBase.getRelatedXmlNode();
                    XmlElement newDirectoryXmlElement = null;
                    if (parentXmlNode != null)
                    {
                        //创建一个IncludeNode节点
                        newDirectoryXmlElement = _document.CreateElement("IncludeNode");
                        newDirectoryXmlElement.SetAttribute("Name", newDirectoryName);
                        newDirectoryXmlElement.SetAttribute("Type", "DirectoryType");
                        newDirectoryXmlElement.SetAttribute("Path", newDirectoryFullPath);

                        //插入到父节点
                        parentXmlNode.AppendChild(newDirectoryXmlElement);
                        parentXmlNode.OwnerDocument.Save(GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_PATH));
                    }
                    else
                    {
                        Logger.Error("parentXmlNode == null");
                        return(false);
                    }

                    //创建目录到硬盘
                    Directory.CreateDirectory(Path.GetFullPath(newDirectoryFullPath));

                    //添加TreeView节点到场景列表
                    GxSceneDirectory sceneDir         = new GxSceneDirectory(newDirectoryFullPath, newDirectoryXmlElement);
                    GxTreeNode       newDirectoryNode = new GxTreeNode(newDirectoryName, sceneDir, GXNodeType.GX_NODE_TYPE_DIRECTORY, ICON_TYPE.ICON_SCENE_DIR, ICON_TYPE.ICON_SCENE_DIR);
                    parentNode.Nodes.Add(newDirectoryNode);
                }
                else
                {
                    Logger.Error("Parent directory is not exists.");
                    return(false);
                }
            }
            else
            {
                Logger.Error("nodeDataBase == null");
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 移动一个节点
        /// </summary>
        /// <param name="srcNode">要移动的节点</param>
        /// <param name="detNode">父节点</param>
        /// <returns>返回移动成功的节点</returns>
        public GxTreeNode moveNode(GxTreeNode srcNode, GxTreeNode dstNode)
        {
            if (srcNode == null || dstNode == null)
            {
                Logger.Error("srcNode == null || dstNode == null.");
                return(null);
            }

            if (srcNode == dstNode)
            {
                Logger.Error("srcNode is equals to dstNode.");
                return(null);
            }

            if (findNode(srcNode) == false || findNode(dstNode) == false)
            {
                Logger.Error("srcNode or dstNode not in NodeCollection");
                return(null);
            }

            //目标节点不能是源节点的子节点
            if (findNode(dstNode, srcNode) == true)
            {
                Logger.Error("dstNode is the childNode of srcNode");
                return(null);
            }

            //判断目标节点是否文件夹节点或工程节点
            GXNodeType dstNodeType = dstNode.getGxNodeType();

            if (dstNodeType != GXNodeType.GX_NODE_TYPE_DIRECTORY && dstNodeType != GXNodeType.GX_NODE_TYPE_PROJECT)
            {
                Logger.Error("destination node is not directory type or not project type.");
                return(null);
            }

            //取得场景目录完整路径
            string sceneDirFullPath = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR);

            //如果原节点是目录
            if (srcNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_DIRECTORY)
            {
                //取得源目录完整路径
                GxNodeData srcNodeData    = (GxNodeData)srcNode.Tag;
                string     srcDirFullPath = srcNodeData.getPath();
                if (Directory.Exists(srcDirFullPath) == false)
                {
                    Logger.Error("srcNode dir path not exists.");
                    return(null);
                }

                //DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirFullPath);
                string srcDirName = Path.GetFileName(srcDirFullPath);

                //取得目标目录完整路径,默认为场景根目录
                GxNodeData dstNodeData    = (GxNodeData)dstNode.Tag;
                string     dstDirFullPath = dstNodeData.getPath();

                if (Directory.Exists(dstDirFullPath) == false)
                {
                    Logger.Error("dstNode dir path not exists.");
                    return(null);
                }

                //取得移动后的目录路径
                string newDirFullPath = dstDirFullPath + "\\" + srcDirName;

                //检查目标路径是否存在了
                if (Directory.Exists(newDirFullPath) == true)
                {
                    Logger.Error("Destination dir is exists!");
                    return(null);
                }

                //检查目标路径是否与自己相等
                if (srcDirFullPath == newDirFullPath)
                {
                    Logger.Error("Two path equals.");
                    return(null);
                }

                //移动目录
                Directory.Move(srcDirFullPath, newDirFullPath);
                Logger.Debug(string.Format("Direcotry [{0}] moved to [{1}] finished!", srcDirFullPath, newDirFullPath));

                //取得节点相关XML元素
                XmlNode srcRelatedXmlNode = srcNodeData.getRelatedXmlNode();
                XmlNode dstRelatedXmlNode = dstNodeData.getRelatedXmlNode();

                //复制源xml节点的副本
                XmlNode appendNode = srcRelatedXmlNode.CloneNode(true);

                //把复制的副本插入到目标节点中
                dstRelatedXmlNode.AppendChild(appendNode);

                //把源xml节点删除
                srcRelatedXmlNode.ParentNode.RemoveChild(srcRelatedXmlNode);

                //更新源节点的关联XMLNode
                srcNodeData.setRelatedXmlNode(appendNode);

                //取得父节点的基本数据
                string newPath = IOUtil.getRelPath(newDirFullPath, sceneDirFullPath);
                srcNodeData.saveRealPathToXml(newPath, srcNode, true);
            }

            //移除原节点
            srcNode.Remove();

            //加到目标节点
            dstNode.Nodes.Add(srcNode);

            return(srcNode);
        }