/// <summary>
 /// Enumerate the given folder and add all compatible files to the cache.
 /// </summary>
 /// <param name="projectFolder">Project folder to enumerate.</param>
 public void AddFolder(ProjectFolder projectFolder)
 {
   if (projectFolder.Project != null && this.AddProject(projectFolder.Project))
   {
     ProjectUtilities.Instance.EnumerateFolder(projectFolder).ForEach(file => this.AddFile(file));
   }
 }
Exemplo n.º 2
0
		void AddFile (ProjectFile file, Project project)
		{
			ITreeBuilder tb = Context.GetTreeBuilder ();
			
			if (file.DependsOnFile != null) {
				if (!tb.MoveToObject (file.DependsOnFile)) {
					// The parent is not in the tree. Add it now, and it will add this file as a child.
					AddFile (file.DependsOnFile, project);
				}
				else
					tb.AddChild (file);
				return;
			}
			
			object data;
			if (file.Subtype == Subtype.Directory)
				data = new ProjectFolder (file.Name, project);
			else
				data = file;
				
			// Already there?
			if (tb.MoveToObject (data))
				return;
			
			string filePath = file.IsLink
				? project.BaseDirectory.Combine (file.ProjectVirtualPath).ParentDirectory
				: file.FilePath.ParentDirectory;
			
			tb = GetFolder (project, filePath);
			if (tb != null)
				tb.AddChild (data);
		}
 static void DeleteFolder(ProjectFolder folder)
 {
     try {
         if (Directory.Exists (folder.Path))
             // FileService events should remove remaining files from the project
             FileService.DeleteDirectory (folder.Path);
     }
     catch (Exception ex) {
         MessageService.ShowError (GettextCatalog.GetString ("The folder {0} could not be deleted from disk: {1}", folder.Path, ex.Message));
     }
 }
		void OnAddFile (object sender, ProjectFileEventArgs args)
		{
			foreach (ProjectFileEventInfo e in args) {
				if (!e.ProjectFile.IsLink) {
					object target;
					if (e.ProjectFile.Subtype == Subtype.Directory) {
						target = new ProjectFolder (e.ProjectFile.FilePath, e.Project);
					} else {
						ITreeBuilder tb = Context.GetTreeBuilder (new SystemFile (e.ProjectFile.Name, e.Project));
						if (tb != null) tb.Remove (true);
						target = e.ProjectFile;
					}
					Context.Tree.AddNodeInsertCallback (target, new TreeNodeCallback (UpdateProjectFileParent));
				}
			}
		}
    /// <summary>
    /// Enumerate the given folder and return all files known by StyleCop.
    /// </summary>
    /// <param name="projectFolder">Project folder to enumerate.</param>
    /// <returns>A list with all known files.</returns>
    internal List<ProjectFile> EnumerateFolder(ProjectFolder projectFolder)
    {
      List<ProjectFile> results = new List<ProjectFile>();

      if (projectFolder.Project != null)
      {
        results = projectFolder.Project.Files.GetFilesInPath(projectFolder.Path).Where(value => this.HasKnownFileExtension(value)).ToList();
      }

      return results;
    }
 /// <summary>
 /// Enumerate the given folder and remove all files from cache.
 /// </summary>
 /// <param name="projectFolder">Project folder to enumerate.</param>
 public void RemoveFolder(ProjectFolder projectFolder)
 {
   if (projectFolder.Project != null && this.projectCache.ContainsKey(projectFolder.Project))
   {
     this.projectCache[projectFolder.Project].Where(
       file => file.FilePath.ParentDirectory.ToString().Contains(projectFolder.Path)).ToList().ForEach(file => this.RemoveFile(file, projectFolder.Project));
   }
 }
        public override object GetParentObject(object dataObject)
        {
            ProjectFolder folder = (ProjectFolder)dataObject;

            return(folder.Parent);
        }
    /// <summary>
    /// Enumerate the given folder and return all known files.
    /// </summary>
    /// <param name="projectFolder">Project folder to enumerate.</param>
    /// <returns>A list with all known files.</returns>
    private Dictionary<int, ProjectFile> EnumerateFolder(ProjectFolder projectFolder)
    {
      Dictionary<int, ProjectFile> results = new Dictionary<int, ProjectFile>();

      if (projectFolder.Project != null)
      {
        results = projectFolder.Project.Files.GetFilesInPath(projectFolder.Path).Where(
          value => !IsDirectory(value.FilePath) && this.IsKnownFileExtension(value.FilePath.Extension)).ToDictionary(file => file.FilePath.ToString().GetHashCode());
      }

      return results;
    }
		void OnFolderRenamed (object sender, FileCopyEventArgs e)
		{
			ProjectFolder f = (ProjectFolder) sender;
			ITreeBuilder tb = Context.GetTreeBuilder (f.Parent);
			if (tb != null) tb.UpdateAll ();
		}
Exemplo n.º 10
0
        void RemoveFile(ProjectFile file, Project project)
        {
            ITreeBuilder tb = Context.GetTreeBuilder();

            if (file.Subtype == Subtype.Directory)
            {
                if (!tb.MoveToObject(new ProjectFolder(file.Name, project)))
                {
                    return;
                }
                tb.MoveToParent();
                tb.UpdateAll();
                return;
            }
            else
            {
                if (tb.MoveToObject(file))
                {
                    tb.Remove(true);
                }
                else
                {
                    // We can't use IsExternalToProject here since the ProjectFile has
                    // already been removed from the project
                    FilePath parentPath = file.IsLink
                                                ? project.BaseDirectory.Combine(file.Link.IsNullOrEmpty? file.FilePath.FileName : file.Link.ToString()).ParentDirectory
                                                : file.FilePath.ParentDirectory;

                    if (!tb.MoveToObject(new ProjectFolder(parentPath, project)))
                    {
                        if (project.UseFileWatcher && parentPath.IsChildPathOf(project.BaseDirectory))
                        {
                            // Keep looking for folder higher up the tree so any empty folders
                            // can be removed.
                            while (parentPath != project.BaseDirectory)
                            {
                                parentPath = parentPath.ParentDirectory;
                                if (tb.MoveToObject(new ProjectFolder(parentPath, project)))
                                {
                                    tb.UpdateAll();
                                    break;
                                }
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }

            while (tb.DataItem is ProjectFolder)
            {
                ProjectFolder f = (ProjectFolder)tb.DataItem;
                if (!Directory.Exists(f.Path) && !project.Files.GetFilesInVirtualPath(f.Path.ToRelative(project.BaseDirectory)).Any())
                {
                    tb.Remove(true);
                }
                else if (project.UseFileWatcher)
                {
                    // Ensure empty folders are removed if they are not part of the project.
                    while (!tb.HasChildren() && tb.MoveToParent())
                    {
                        tb.UpdateAll();
                    }
                    break;
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 11
0
        public override bool Equals(object other)
        {
            ProjectFolder f = other as ProjectFolder;

            return(f != null && absolutePath == f.absolutePath && parentWorkspaceObject == f.parentWorkspaceObject);
        }