/// <include file='doc\Project.uex' path='docs/doc[@for="Project.VerifySubFolderExists"]/*' /> /// <summary> /// takes a path and verifies that we have a node with that name, if not, add it to this node. /// </summary> public HierarchyNode VerifySubFolderExists(HierarchyNode parent, string strPath) { HierarchyNode folderNode = null; uint uiItemId; Url url = new Url(this.BaseURI, strPath); string strFullPath = url.AbsoluteUrl; // folders end in our storage with a backslash, so add one... NativeMethods.ThrowOnFailure(this.ParseCanonicalName(strFullPath, out uiItemId)); if (uiItemId == 0) { // folder does not exist yet... folderNode = CreateNode(this, HierarchyNodeType.Folder, strPath); parent.AddChild(folderNode); } else { folderNode = this.NodeFromItemId(uiItemId); } return folderNode; }
/// <summary> /// Add a file node to the hierarchy /// </summary> /// <param name="item">msbuild item to add</param> /// <param name="parentNode">Parent Node</param> /// <returns>Added node</returns> private HierarchyNode AddFileNodeToNode(Microsoft.Build.Evaluation.ProjectItem item, HierarchyNode parentNode) { FileNode node = this.CreateFileNode(new ProjectElement(this, item, false)); parentNode.AddChild(node); return node; }
/// <include file='doc\Project.uex' path='docs/doc[@for="Project.Reload"]/*' /> public virtual void Reload() { if (this.myEngine == null || this.myEngine.BinPath == null) { this.myEngine = new MSBuild.Engine(); // We must set the MSBuild path prior to calling CreateNewProject or we it will fail this.myEngine.BinPath = GetMsBuildPath(); } this.projFile = myEngine.CreateNewProject(); this.projFile.LoadFromFile(this.filename); MSBuild.PropertyGroup projectProperties = projFile.EvaluatedProperties; // load the guid if (projectProperties != null) { try { this.projectGuid = new Guid(this.GetProjectProperty("ProjectGuid")); } catch { this.projectGuid = Guid.NewGuid(); } } // Process References MSBuild.ItemGroup references = this.projFile.GetEvaluatedItemsByType("Reference"); referencesFolder = CreateNode(this, HierarchyNodeType.RefFolder, "References"); AddChild(referencesFolder); foreach (MSBuild.Item reference in references) { HierarchyNode node = CreateNode(this, HierarchyNodeType.Reference, new ProjectElement(this, reference, false)); referencesFolder.AddChild(node); } // Process Files MSBuild.ItemGroup projectFiles = this.projFile.EvaluatedItems; foreach (MSBuild.Item item in projectFiles) { // Ignore the item if it is a reference or folder if (String.Compare(item.Type, "Reference", true, CultureInfo.InvariantCulture) == 0 || String.Compare(item.Type, "Folder", true, CultureInfo.InvariantCulture) == 0 || String.Compare(item.Type, "ProjectReference", true, CultureInfo.InvariantCulture) == 0 || String.Compare(item.Type, "WebReference", true, CultureInfo.InvariantCulture) == 0 || String.Compare(item.Type, "WebReferenceFolder", true, CultureInfo.InvariantCulture) == 0) continue; // MSBuilds tasks/targets can create items (such as object files), // such items are not part of the project per say, and should not be displayed. // so ignore those items. if (!this.IsItemTypeFileType(item.Type)) continue; string strPath = item.FinalItemSpec; HierarchyNode currentParent = this; strPath = Path.GetDirectoryName(strPath); if (strPath.Length > 0) { // use the relative to verify the folders... currentParent = CreateFolderNodes(strPath); } currentParent.AddChild(this.CreateNode(this, HierarchyNodeType.File, new ProjectElement(this, item, false))); } // Process Folders (useful to persist empty folder) MSBuild.ItemGroup folders = this.projFile.GetEvaluatedItemsByType("Folder"); foreach (MSBuild.Item folder in folders) { string strPath = folder.FinalItemSpec; CreateFolderNodes(strPath); } SetProjectFileDirty(false); }
private HierarchyNode AddNewFileNodeToHierarchyCore(HierarchyNode parentNode, string fileName, string linkPath) { HierarchyNode child; // In the case of subitem, we want to create dependent file node // and set the DependentUpon property if (this.canFileNodesHaveChilds && (parentNode is FileNode || parentNode is DependentFileNode)) { child = this.CreateDependentFileNode(fileName); child.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, parentNode.ItemNode.GetMetadata(ProjectFileConstants.Include)); // Make sure to set the HasNameRelation flag on the dependent node if it is related to the parent by name if (!child.HasParentNodeNameRelation && String.Compare(child.GetRelationalName(), parentNode.GetRelationalName(), StringComparison.OrdinalIgnoreCase) == 0) { child.HasParentNodeNameRelation = true; } } else { //Create and add new filenode to the project child = this.CreateFileNode(fileName); child.ItemNode.SetMetadata(ProjectFileConstants.Link, linkPath); if (!String.IsNullOrEmpty(linkPath)) { child.ExcludeNodeFromScc = true; } } parentNode.AddChild(child); return child; }
/// <summary> /// Add a dependent file node to the hierarchy /// </summary> /// <param name="item">msbuild item to add</param> /// <param name="parentNode">Parent Node</param> /// <returns>Added node</returns> private HierarchyNode AddDependentFileNodeToNode(Microsoft.Build.Evaluation.ProjectItem item, HierarchyNode parentNode) { FileNode node = this.CreateDependentFileNode(new ProjectElement(this, item, false)); parentNode.AddChild(node); // Make sure to set the HasNameRelation flag on the dependent node if it is related to the parent by name if (!node.HasParentNodeNameRelation && String.Compare(node.GetRelationalName(), parentNode.GetRelationalName(), StringComparison.OrdinalIgnoreCase) == 0) { node.HasParentNodeNameRelation = true; } return node; }
/// <summary> /// Adds a new file node to the hierarchy. /// </summary> /// <param name="parentNode">The parent of the new fileNode</param> /// <param name="fileName">The file name</param> protected virtual void AddNewFileNodeToHierarchy(HierarchyNode parentNode, string fileName) { HierarchyNode child; // In the case of subitem, we want to create dependent file node // and set the DependentUpon property if (this.canFileNodesHaveChilds && (parentNode is FileNode || parentNode is DependentFileNode)) { child = this.CreateDependentFileNode(fileName); child.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, parentNode.ItemNode.GetMetadata(ProjectFileConstants.Include)); // Make sure to set the HasNameRelation flag on the dependent node if it is related to the parent by name if (!child.HasParentNodeNameRelation && string.Compare(child.GetRelationalName(), parentNode.GetRelationalName(), StringComparison.OrdinalIgnoreCase) == 0) { child.HasParentNodeNameRelation = true; } } else { //Create and add new filenode to the project child = this.CreateFileNode(fileName); } parentNode.AddChild(child); // TODO : Revisit the VSADDFILEFLAGS here. Can it be a nested project? this.tracker.OnItemAdded(fileName, VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags); }
protected virtual FolderNode VerifySubFolderExists(string path, HierarchyNode parent) { FolderNode folderNode = null; uint uiItemId; Url url = new Url(this.BaseURI, path); string strFullPath = url.AbsoluteUrl; // Folders end in our storage with a backslash, so add one... this.ParseCanonicalName(strFullPath, out uiItemId); if ((uint)VSConstants.VSITEMID.Nil != uiItemId) { Debug.Assert(this.NodeFromItemId(uiItemId) is FolderNode, "Not a FolderNode"); folderNode = (FolderNode)this.NodeFromItemId(uiItemId); } if (folderNode == null) { // folder does not exist yet... // We could be in the process of loading so see if msbuild knows about it ProjectElement item = null; foreach (Microsoft.Build.Evaluation.ProjectItem folder in MSBuildProject.GetItems(buildProject, ProjectFileConstants.Folder)) { if (String.Compare(folder.EvaluatedInclude.TrimEnd('\\'), path.TrimEnd('\\'), StringComparison.OrdinalIgnoreCase) == 0) { item = new ProjectElement(this, folder, false); break; } } // If MSBuild did not know about it, create a new one if (item == null) item = this.AddFolderToMsBuild(path); folderNode = this.CreateFolderNode(path, item); parent.AddChild(folderNode); } return folderNode; }
/// <include file='doc\Project.uex' path='docs/doc[@for="Project.VerifySubFolderExists"]/*' /> /// <summary> /// takes a path and verifies that we have a node with that name, if not, add it to this node. /// </summary> public HierarchyNode VerifySubFolderExists(HierarchyNode parent, string strPath){ HierarchyNode folderNode = null; uint uiItemId; #if WHIDBEY Uri uri = new Uri(new Uri(this.projFile.BaseURI), strPath); #else Uri uri = new Uri(new Uri(this.projFile.BaseURI), strPath, true); #endif strPath = uri.LocalPath; //??? // folders end in our storage with a backslash, so add one... strPath += "\\"; this.ParseCanonicalName(strPath, out uiItemId); if (uiItemId == 0){ // folder does not exist yet... folderNode = CreateNode(this, HierarchyNodeType.Folder, strPath); parent.AddChild(folderNode); } else{ folderNode = this.NodeFromItemId(uiItemId); } return folderNode; }
/// <include file='doc\Project.uex' path='docs/doc[@for="Project.Reload"]/*' /> public virtual void Reload(){ this.projFile = new XmlDocument(); this.projFile.Load(this.filename); this.xmlNode = this.projFile.DocumentElement; // load the guid XmlElement state = this.StateElement = (XmlElement)this.GetProjectStateElement(this.xmlNode); if (state != null){ string projectGuid = state.GetAttribute("ProjectGuid"); this.projectGuid = projectGuid == string.Empty ? new Guid() : new Guid(projectGuid); } XmlElement refNode = (XmlElement)projFile.SelectSingleNode("//References"); if (refNode != null){ referencesFolder = CreateNode(this, HierarchyNodeType.RefFolder, refNode); AddChild(referencesFolder); foreach (XmlElement e in refNode.SelectNodes("Reference")){ HierarchyNode node = CreateNode(this, HierarchyNodeType.Reference, e); referencesFolder.AddChild(node); } } foreach (XmlElement e in this.projFile.SelectNodes("//Files/Include/File")){ string strPath = e.GetAttribute("RelPath"); uint itemId; HierarchyNode currentParent = this; strPath = Path.GetDirectoryName(strPath); if (strPath.Length > 0){ // use the relative to verify the folders... CreateFolderNodes(strPath); // now create an absolute ouf of it #if WHIDBEY Uri uri = new Uri(new Uri(this.projFile.BaseURI), strPath); #else Uri uri = new Uri(new Uri(this.projFile.BaseURI), strPath, true); #endif strPath = uri.LocalPath; //??? strPath += "\\"; this.ParseCanonicalName(strPath, out itemId); currentParent = this.NodeFromItemId(itemId); } currentParent.AddChild(this.CreateNode(this, HierarchyNodeType.File, e)); } foreach (XmlElement e in this.projFile.SelectNodes("//Files/Include/Folder")){ // so we do have some empty folders.... string strPath = e.GetAttribute("RelPath"); CreateFolderNodes(strPath); } SetProjectFileDirty(false); this.projFile.NodeChanged += new XmlNodeChangedEventHandler(OnNodeChanged); this.projFile.NodeInserted += new XmlNodeChangedEventHandler(OnNodeChanged); this.projFile.NodeRemoved += new XmlNodeChangedEventHandler(OnNodeChanged); RegisterSccProject(); }
/// <summary> /// Add a dependent file node to the hierarchy /// </summary> /// <param name="item">msbuild item to add</param> /// <param name="parentNode">Parent Node</param> /// <returns>Added node</returns> private HierarchyNode AddDependentFileNodeToNode(MSBuild.BuildItem item, HierarchyNode parentNode) { FileNode node = this.CreateDependentFileNode(new ProjectElement(this, item, false)); parentNode.AddChild(node); return node; }
/// <summary> /// Takes a path and verifies that we have a node with that name. /// It is meant to be a helper method for CreateFolderNodes(). /// For some scenario it may be useful to override. /// </summary> protected virtual FolderNode VerifySubFolderExists(string strPath, HierarchyNode parent) { FolderNode folderNode = null; uint uiItemId; Url url = new Url(this.BaseURI, strPath); string strFullPath = url.AbsoluteUrl; // Folders end in our storage with a backslash, so add one... ErrorHandler.ThrowOnFailure(this.ParseCanonicalName(strFullPath, out uiItemId)); if (uiItemId != 0) { Debug.Assert(this.NodeFromItemId(uiItemId) is FolderNode, "Not a FolderNode"); folderNode = (FolderNode)this.NodeFromItemId(uiItemId); } if (folderNode == null) { // folder does not exist yet... // We could be in the process of loading so see if msbuild knows about it MSBuild.BuildItemGroup folders = buildProject.GetEvaluatedItemsByName(ProjectFileConstants.Folder); ProjectElement item = null; foreach (MSBuild.BuildItem folder in folders) { if (String.Compare(folder.FinalItemSpec.TrimEnd('\\'), strPath.TrimEnd('\\'), StringComparison.OrdinalIgnoreCase) == 0) { item = new ProjectElement(this, folder, false); break; } } // If MSBuild did not know about it, create a new one if (item == null) item = this.AddFolderToMsBuild(strPath); folderNode = this.CreateFolderNode(strPath, item); parent.AddChild(folderNode); } return folderNode; }
/// <summary> /// Adds the new file node to hierarchy. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="fileName">Name of the file.</param> protected override void AddNewFileNodeToHierarchy(HierarchyNode parentNode, string path) { // If a lua file is being added, try to find a related FrameXML node if (MultiverseInterfaceProjectNode.IsPythonFile(path)) { // Try to find a FrameXML node with a matching relational name string fileName = Path.GetFileNameWithoutExtension(path); HierarchyNode childNode = this.FirstChild; // Iterate through the children while (childNode != null) { // If this child is an XML node and its relational name matches, break out of the loop if (childNode is MultiverseInterfaceXmlFileNode && String.Compare(childNode.GetRelationalName(), fileName, StringComparison.OrdinalIgnoreCase) == 0) { parentNode = childNode; break; } // Move over to the next sibling childNode = childNode.NextSibling; } } HierarchyNode child; if (this.CanFileNodesHaveChilds && (parentNode is FileNode || parentNode is DependentFileNode)) { child = this.CreateDependentFileNode(path); child.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, parentNode.ItemNode.GetMetadata(ProjectFileConstants.Include)); // Make sure to set the HasNameRelation flag on the dependent node if it is related to the parent by name if (String.Compare(child.GetRelationalName(), parentNode.GetRelationalName(), StringComparison.OrdinalIgnoreCase) == 0) { child.HasParentNodeNameRelation = true; } } else { //Create and add new filenode to the project child = this.CreateFileNode(path); } parentNode.AddChild(child); this.Tracker.OnItemAdded(path, VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags); }