Example #1
0
        protected DirectoryNode ScanDirectory(string dirPath)
        {
            if (!PathHelper.IsPathVisible(dirPath)) return null;
            DirectoryNode thisNode = new DirectoryNode(dirPath);

            foreach (string dir in Directory.EnumerateDirectories(dirPath))
            {
                DirectoryNode dirNode = this.ScanDirectory(dir);
                if (dirNode != null) this.InsertNodeSorted(dirNode, thisNode);
            }

            foreach (string file in Directory.EnumerateFiles(dirPath))
            {
                NodeBase fileNode = this.ScanFile(file);
                if (fileNode != null) this.InsertNodeSorted(fileNode, thisNode);
            }

            return thisNode;
        }
Example #2
0
        private void FileEventManager_ResourceCreated(object sender, ResourceEventArgs e)
        {
            bool alreadyAdded = this.NodeFromPath(e.Path) != null; // Don't add Resources that are already present.

            if (!alreadyAdded)
            {
                // Register newly detected Resource file
                if (File.Exists(e.Path) && Resource.IsResourceFile(e.Path))
                {
                    NodeBase newNode = this.ScanFile(e.Path);

                    Node parentNode = this.NodeFromPath(Path.GetDirectoryName(e.Path));
                    if (parentNode == null) parentNode = this.folderModel.Root;

                    this.InsertNodeSorted(newNode, parentNode);
                    this.RegisterNodeTree(newNode);
                    newNode.NotifyVisible();
                }
                // Add new directory tree
                else if (e.IsDirectory)
                {
                    // Actually, only add the directory itsself. Each file will trigger its own ResourceCreated event
                    DirectoryNode newNode = new DirectoryNode(e.Path);
                    //NodeBase newNode = this.ScanDirectory(e.Path);

                    Node parentNode = this.NodeFromPath(Path.GetDirectoryName(e.Path));
                    if (parentNode == null) parentNode = this.folderModel.Root;

                    this.InsertNodeSorted(newNode, parentNode);
                    this.RegisterNodeTree(newNode);
                    newNode.NotifyVisible();
                }
            }

            // Perform previously scheduled selection
            this.PerformScheduleSelect(Path.GetFullPath(e.Path));
        }
Example #3
0
        protected DirectoryNode ScanDefaultContent()
        {
            DirectoryNode thisNode = new DirectoryNode(ContentProvider.VirtualContentPath, true);

            List<ContentRef<Resource>> defaultContent = ContentProvider.GetDefaultContent<Resource>();
            foreach (ContentRef<Resource> resRef in defaultContent)
            {
                string[] pathSplit = resRef.Path.Split(':');
                DirectoryNode curDirNode = thisNode;

                // Generate virtual subdirectory nodes
                string curDirPath = pathSplit[0];
                for (int i = 1; i < pathSplit.Length - 1; i++)
                {
                    curDirPath += ":" + pathSplit[i];
                    DirectoryNode subNode = curDirNode.Nodes.FirstOrDefault(delegate(Node n)
                        {
                            return n is DirectoryNode && n.Text == pathSplit[i];
                        }) as DirectoryNode;

                    if (subNode == null)
                    {
                        subNode = new DirectoryNode(curDirPath + ":", true);
                        this.InsertNodeSorted(subNode, curDirNode);
                        curDirNode.Nodes.Add(subNode);
                    }
                    curDirNode = subNode;
                }

                // Generate virtual Resource node
                NodeBase res = this.ScanDefaultResource(resRef);
                if (res != null) this.InsertNodeSorted(res, curDirNode);
            }

            return thisNode;
        }