Example #1
0
 private GenericNode ReuseNode(string absolute, GenericNodeList nodesToDie)
 {
     foreach (GenericNode node in nodesToDie)
         if (node.BackingPath == absolute)
         {
             nodesToDie.Remove(node);
             Nodes.Remove(node);
             return node;
         }
     return null;
 }
Example #2
0
        public override void Refresh(bool recursive)
        {
            ArrayList projectClasspaths = new ArrayList();
            ArrayList globalClasspaths = new ArrayList();

            GenericNodeList nodesToDie = new GenericNodeList();
            foreach (GenericNode oldRef in Nodes) nodesToDie.Add(oldRef);
            //if (Nodes.Count == 0) recursive = true;

            // explore classpaths
            if (PluginMain.Settings.ShowProjectClasspaths)
            {
                projectClasspaths.AddRange(project.Classpaths);
                if (project.AdditionalPaths != null) projectClasspaths.AddRange(project.AdditionalPaths);
            }

            if (PluginMain.Settings.ShowGlobalClasspaths)
                globalClasspaths.AddRange(PluginMain.Settings.GlobalClasspaths);

            // create references nodes
            ClasspathNode cpNode;
            foreach (string projectClasspath in projectClasspaths)
            {
                string absolute = projectClasspath;
                if (!Path.IsPathRooted(absolute))
                    absolute = project.GetAbsolutePath(projectClasspath);
                if ((absolute + "\\").StartsWith(project.Directory + "\\"))
                    continue;
                if (!project.ShowHiddenPaths && project.IsPathHidden(absolute))
                    continue;

                cpNode = ReuseNode(absolute, nodesToDie) as ProjectClasspathNode ?? new ProjectClasspathNode(project, absolute, projectClasspath);
                Nodes.Add(cpNode);
                cpNode.Refresh(recursive);
            }

            foreach (string globalClasspath in globalClasspaths)
            {
                string absolute = globalClasspath;
                if (!Path.IsPathRooted(absolute))
                    absolute = project.GetAbsolutePath(globalClasspath);
                if (absolute.StartsWith(project.Directory + Path.DirectorySeparatorChar.ToString()))
                    continue;

                cpNode = ReuseNode(absolute, nodesToDie) as ProjectClasspathNode ?? new ClasspathNode(project, absolute, globalClasspath);
                Nodes.Add(cpNode);
                cpNode.Refresh(recursive);
            }

            // add external libraries at the top level also
            if (project is AS3Project)
                foreach (LibraryAsset asset in (project as AS3Project).SwcLibraries)
                {
                    if (!asset.IsSwc) continue;
                    // check if SWC is inside the project or inside a classpath
                    string absolute = asset.Path;
                    if (!Path.IsPathRooted(absolute))
                        absolute = project.GetAbsolutePath(asset.Path);

                    bool showNode = true;
                    if (absolute.StartsWith(project.Directory))
                        showNode = false;
                    foreach (string path in project.AbsoluteClasspaths)
                        if (absolute.StartsWith(path))
                        {
                            showNode = false;
                            break;
                        }
                    foreach (string path in PluginMain.Settings.GlobalClasspaths)
                        if (absolute.StartsWith(path))
                        {
                            showNode = false;
                            break;
                        }

                    if (showNode && !project.ShowHiddenPaths && project.IsPathHidden(absolute))
                        continue;

                    if (showNode && File.Exists(absolute))
                    {
                        SwfFileNode swcNode = ReuseNode(absolute, nodesToDie) as SwfFileNode ?? new SwfFileNode(absolute);
                        Nodes.Add(swcNode);
                        swcNode.Refresh(recursive);
                    }
                }

            foreach (GenericNode node in nodesToDie)
            {
                node.Dispose();
                Nodes.Remove(node);
            }
        }
        private void PopulateDirectories(GenericNodeList nodesToDie, bool recursive)
        {
            foreach (string directory in Directory.GetDirectories(BackingPath))
            {
                if (IsDirectoryExcluded(directory))
                    continue;

                DirectoryNode node;
                if (Tree.NodeMap.ContainsKey(directory))
                {
                    node = Tree.NodeMap[directory] as DirectoryNode;
                    if (node != null) // ASClassWizard injects SimpleDirectoryNode != DirectoryNode
                    {
                        if (recursive) node.Refresh(recursive);
                        nodesToDie.Remove(node);
                        continue;
                    }
                    else 
                    {
                        TreeNode fake = Tree.NodeMap[directory];
                        if (fake.Parent != null) fake.Parent.Nodes.Remove(fake);
                    }
                }

                node = new DirectoryNode(directory);
                InsertNode(Nodes, node);
                node.Refresh(recursive);
                nodesToDie.Remove(node);
            }
        }
        private void PopulateFiles(GenericNodeList nodesToDie, bool recursive)
        {
            string[] files = Directory.GetFiles(BackingPath);

            foreach (string file in files)
            {
                if (IsFileExcluded(file))
                    continue;

                if (Tree.NodeMap.ContainsKey(file))
                {
                    GenericNode node = Tree.NodeMap[file];
                    node.Refresh(recursive);
                    nodesToDie.Remove(node);
                }
                else
                {
                    FileNode node = FileNode.Create(file, project);
                    InsertNode(Nodes, node);
                    node.Refresh(recursive);
                    nodesToDie.Remove(node);
                }
            }

            FileMapping mapping = GetFileMapping(files);
            if (mapping == null) return;

            foreach (string file in files)
            {
                if (IsFileExcluded(file))
                    continue;

                GenericNode node = Tree.NodeMap[file];

                // ensure this file is in the right spot
                if (mapping != null && mapping.ContainsKey(file) && Tree.NodeMap.ContainsKey(mapping[file]))
                    EnsureParentedBy(node, Tree.NodeMap[mapping[file]]);
                else
                    EnsureParentedBy(node, this);
            }
        }
        private void PopulateChildNodes(bool recursive)
        {
            dirty = false;

            // nuke the placeholder
            if (Nodes.Count == 1 && Nodes[0] is PlaceholderNode)
                Nodes.RemoveAt(0);

            // do a nice stateful update against the filesystem
            GenericNodeList nodesToDie = new GenericNodeList();
            
            // don't remove project output node if it exists - it's annoying when it
            // disappears during a build
            foreach (GenericNode node in Nodes)
            {
                if (node is ProjectOutputNode)
                {
                    var output = node as ProjectOutputNode;
                    if (project != null && !project.IsPathHidden(output.BackingPath)) output.Refresh(recursive);
                    else nodesToDie.Add(output);
                }
                else if (node is ReferencesNode) node.Refresh(recursive);
                else nodesToDie.Add(node);

                // add any mapped nodes
                if (node is FileNode && !(node is SwfFileNode))
                    nodesToDie.AddRange(node.Nodes);
            }

            if (Directory.Exists(BackingPath))
            {
                PopulateDirectories(nodesToDie, recursive);
                PopulateFiles(nodesToDie, recursive);
            }

            foreach (GenericNode node in nodesToDie)
            {
                node.Dispose();
                Nodes.Remove(node);
            }
        }