Exemple #1
0
        public void UpdateProjectFolder(ProjectFolder projectFolder, TreeNode folderNode)
        {
            if (projectFolder.Folders != null)
            {
                foreach (ProjectFolder pf in projectFolder.Folders)
                {
                    TreeNode pfNode = new TreeNode(pf.FolderName);
                    folderNode.Nodes.Add(pfNode);
                    pfNode.ImageIndex = pfNode.SelectedImageIndex = 7;
                    folderNodes.Add(pfNode, pf);

                    if (!pf.IsCollapsed)
                    {
                        pfNode.Expand();
                    }
                    else
                    {
                        pfNode.Collapse();
                    }

                    UpdateProjectFolder(pf, pfNode);
                }
            }

            if (projectFolder.Files != null)
            {
                foreach (ProjectFile pf in projectFolder.Files)
                {
                    TreeNode currentNode = new TreeNode(pf.FileName);
                    folderNode.Nodes.Add(currentNode);
                    currentNode.ImageIndex = currentNode.SelectedImageIndex = 3;
                    fileNodes.Add(currentNode, pf);

                    // types expected:
                    //  .xml (MODX)
                    //  .mod (Text Template)
                    //  .txt (Text Template)
                    //  .php (PHP)
                    //  .php (language file

                    /*if (pf.IsOpen)
                     * {
                     *  // TODO:
                     *  //
                     *  // query parent for the window owning the current node that is open
                     *  // query the mod for a list of files edited
                     *  // add the list of mods to the tree
                     *  //
                     *  // query window for icon type
                     * }
                     * else
                     * {*/
                    // query for the file type so we can change it's icon
                    try
                    {
                        string fileFullPath = "";
                        if (projectFolder.FolderName == "")
                        {
                            fileFullPath = Path.Combine(projectPath, pf.FileName);
                        }
                        else
                        {
                            fileFullPath = Path.Combine(Path.Combine(projectPath, projectFolder.GetFolderPath()), pf.FileName);
                        }
                        FileInfo        projectFileInfo = new FileInfo(fileFullPath);
                        ProjectFileType pft             = ReadFirstBytesInFile(fileFullPath);

                        switch (projectFileInfo.Extension.ToLower())
                        {
                        case ".mod":
                            if (pft == ProjectFileType.TextFile)
                            {
                                currentNode.ImageIndex = currentNode.SelectedImageIndex = 0;
                                openModFiles.Add(pf.FileName, currentNode);
                            }
                            break;

                        case ".txt":
                            switch (pft)
                            {
                            case ProjectFileType.Gpl:
                                currentNode.ImageIndex = currentNode.SelectedImageIndex = 4;
                                break;

                            case ProjectFileType.TextMod:
                                currentNode.ImageIndex = currentNode.SelectedImageIndex = 0;
                                break;
                            }
                            openModFiles.Add(pf.FileName, currentNode);
                            break;

                        case ".xml":
                            if (pft == ProjectFileType.ModxMox)
                            {
                                currentNode.ImageIndex = currentNode.SelectedImageIndex = 1;
                                openModFiles.Add(pf.FileName, currentNode);
                            }
                            break;

                        case ".php":
                            Console.WriteLine(">>> " + pft.ToString());
                            switch (pft)
                            {
                            case ProjectFileType.PhpFile:
                                currentNode.ImageIndex = currentNode.SelectedImageIndex = 6;
                                Console.WriteLine("*** PHP file ***");
                                break;

                            case ProjectFileType.LanguageFile:
                                currentNode.ImageIndex = currentNode.SelectedImageIndex = 5;
                                Console.WriteLine("*** Language file ***");
                                break;
                            }
                            openModFiles.Add(pf.FileName, currentNode);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }