Beispiel #1
0
    void initBrowser()
    {
        dirRoot.RemoveAllChildren();
        DirStatus d = new DirStatus {
            depth    = 0,
            expanded = true,
            dirInfo  = new DirectoryInfo(projectPath)
        };

        d.treeNode = dirRoot.AddChild(d);

        foreach (DirectoryInfo subDir in d.dirInfo.GetDirectories())
        {
            var ds = new DirStatus {
                depth    = d.depth + 1,
                expanded = false,
                dirInfo  = subDir
            };
            ds.treeNode = d.treeNode.AddChild(ds);
        }

        fileList        = d.dirInfo.GetFiles();
        resultPath.text = "";
        drawBrowser();
    }
Beispiel #2
0
    void initBrowserUntilRoot(DirectoryInfo dir)
    {
        dirRoot.RemoveAllChildren();
        List <DirectoryInfo> parents = new List <DirectoryInfo>();

        while (dir != null)
        {
            parents.Add(dir);
            dir = dir.Parent;
        }
        parents.Reverse();

        TreeNode <DirStatus> d = null;

        foreach (string drive in Directory.GetLogicalDrives())
        {
            var child = new DirStatus {
                depth    = 0,
                expanded = false,
                dirInfo  = new DirectoryInfo(drive)
            };
            var childNode = dirRoot.AddChild(child);
            child.treeNode = childNode;
            if (drive == parents[0].Name)
            {
                d = childNode;
            }
        }

        foreach (DirectoryInfo p in parents.Skip(1))
        {
            var ds = new DirStatus {
                depth    = d.Value.depth + 1,
                expanded = false,
                dirInfo  = p
            };
            d           = d.AddChild(ds);
            ds.treeNode = d;
        }
        d.Value.expanded = true;

        foreach (DirectoryInfo subDir in d.Value.dirInfo.GetDirectories())
        {
            var ds = new DirStatus {
                depth    = d.Value.depth + 1,
                expanded = false,
                dirInfo  = subDir
            };
            ds.treeNode = d.AddChild(ds);
        }

        fileList        = null;
        resultPath.text = projectPath;
        drawBrowser();
    }
Beispiel #3
0
    public void OnDirItemClick(GameObject item)
    {
        DirStatus selectedDir;

        if (item == null || !dirDictionary.TryGetValue(item, out selectedDir))
        {
            return;
        }

        if (selectedDir.expanded)
        {
            selectedDir.treeNode.RemoveAllChildren();
            selectedDir.expanded = false;
        }
        else
        {
            foreach (DirectoryInfo subDir in selectedDir.dirInfo.GetDirectories())
            {
                if (selectedDir.treeNode.Children.Count == 0 || selectedDir.treeNode.Children.First().Value.dirInfo.Name != subDir.Name)
                {
                    var newChild = new DirStatus()
                    {
                        depth    = selectedDir.depth + 1,
                        expanded = false,
                        dirInfo  = subDir
                    };
                    newChild.treeNode = selectedDir.treeNode.AddChild(newChild);
                }
            }
            selectedDir.expanded = true;
            fileList             = fileBrowserStatus == FileBrowserStatus.File ? selectedDir.dirInfo.GetFiles() : null;
        }

        drawBrowser();
        changeBtnColor(selectedDir.gameObject.GetComponent <Button>(), BtnState.Highlighted);
        resultPath.text = fileBrowserStatus == FileBrowserStatus.File ? selectedDir.dirInfo.FullName.Substring(projectPath.Length).TrimStart(@"/\".ToCharArray()) : selectedDir.dirInfo.FullName;
    }