/// <summary> /// Renames the file in the hierarchy by removing old node and adding a new node in the hierarchy. /// </summary> /// <param name="oldFileName">The old file name.</param> /// <param name="newFileName">The new file name</param> /// <param name="newParentId">The new parent id of the item.</param> /// <returns>The newly added FileNode.</returns> /// <remarks>While a new node will be used to represent the item, the underlying MSBuild item will be the same and as a result file properties saved in the project file will not be lost.</remarks> private FileNode RenameFileNode(string oldFileName, string newFileName, HierarchyNode newParent) { if (CommonUtils.IsSamePath(oldFileName, newFileName)) { // We do not want to rename the same file return(null); } if (newParent.IsNonMemberItem) { ErrorHandler.ThrowOnFailure(newParent.IncludeInProject(false)); } ProjectMgr.OnItemDeleted(this); this.Parent.RemoveChild(this); this.ID = this.ProjectMgr.ItemIdMap.Add(this); this.ItemNode.Rename(CommonUtils.GetRelativeFilePath(ProjectMgr.ProjectHome, newFileName)); this.ItemNode.RefreshProperties(); this.ProjectMgr.SetProjectFileDirty(true); newParent.AddChild(this); this.Parent = newParent; ProjectMgr.ReDrawNode(this, UIHierarchyElement.Caption); //Update the new document in the RDT. DocumentManager.RenameDocument(this.ProjectMgr.Site, oldFileName, newFileName, ID); //Select the new node in the hierarchy ExpandItem(EXPANDFLAGS.EXPF_SelectItem); RenameChildNodes(this); return(this); }
// !EFW /// <summary> /// This method converts a non-member folder node into a member node including /// all of its child nodes. /// </summary> /// <returns>Returns S_OK on success or an error code on failure</returns> protected internal int IncludeInProjectRecursive() { int result = this.IncludeInProject(); if (result == VSConstants.S_OK) { for (HierarchyNode node = this.FirstChild; node != null; node = node.NextSibling) { FolderNode fn = node as FolderNode; if (fn != null) { result = fn.IncludeInProjectRecursive(); } else { result = node.IncludeInProject(); } if (result != VSConstants.S_OK) { break; } } } return(result); }
/// <summary> /// Renames the file in the hierarchy by removing old node and adding a new node in the hierarchy. /// </summary> /// <param name="oldFileName">The old file name.</param> /// <param name="newFileName">The new file name</param> /// <param name="newParentId">The new parent id of the item.</param> /// <returns>The newly added FileNode.</returns> /// <remarks>While a new node will be used to represent the item, the underlying MSBuild item will be the same and as a result file properties saved in the project file will not be lost.</remarks> internal FileNode RenameFileNode(string oldFileName, string newFileName, HierarchyNode newParent) { if (CommonUtils.IsSamePath(oldFileName, newFileName)) { // We do not want to rename the same file return(null); } //If we are included in the project and our parent isn't then //we need to bring our parent into the project if (!this.IsNonMemberItem && newParent.IsNonMemberItem) { ErrorHandler.ThrowOnFailure(newParent.IncludeInProject(false)); } // Retrieve child nodes to add later. List <HierarchyNode> childNodes = this.GetChildNodes(); FileNode renamedNode; using (this.ProjectMgr.ExtensibilityEventsDispatcher.Suspend()) { // Remove this from its parent. ProjectMgr.OnItemDeleted(this); this.Parent.RemoveChild(this); // Update name in MSBuild this.ItemNode.Rename(CommonUtils.GetRelativeFilePath(ProjectMgr.ProjectHome, newFileName)); // Request a new file node be made. This is used to replace the old file node. This way custom // derived FileNode types will be used and correctly associated on rename. This is useful for things // like .txt -> .js where the file would now be able to be a startup project/file. renamedNode = this.ProjectMgr.CreateFileNode(this.ItemNode); renamedNode.ItemNode.RefreshProperties(); renamedNode.UpdateCaption(); newParent.AddChild(renamedNode); renamedNode.Parent = newParent; } UpdateCaption(); ProjectMgr.ReDrawNode(renamedNode, UIHierarchyElement.Caption); renamedNode.ProjectMgr.ExtensibilityEventsDispatcher.FireItemRenamed(this, oldFileName); //Update the new document in the RDT. DocumentManager.RenameDocument(renamedNode.ProjectMgr.Site, oldFileName, newFileName, renamedNode.ID); //Select the new node in the hierarchy renamedNode.ExpandItem(EXPANDFLAGS.EXPF_SelectItem); // Add children to new node and rename them appropriately. childNodes.ForEach(x => renamedNode.AddChild(x)); RenameChildNodes(renamedNode); return(renamedNode); }
/// <summary> /// Renames the file in the hierarchy by removing old node and adding a new node in the hierarchy. /// </summary> /// <param name="oldFileName">The old file name.</param> /// <param name="newFileName">The new file name</param> /// <param name="newParentId">The new parent id of the item.</param> /// <returns>The newly added FileNode.</returns> /// <remarks>While a new node will be used to represent the item, the underlying MSBuild item will be the same and as a result file properties saved in the project file will not be lost.</remarks> internal FileNode RenameFileNode(string oldFileName, string newFileName, HierarchyNode newParent) { if (CommonUtils.IsSamePath(oldFileName, newFileName)) { // We do not want to rename the same file return null; } //If we are included in the project and our parent isn't then //we need to bring our parent into the project if (!this.IsNonMemberItem && newParent.IsNonMemberItem) { ErrorHandler.ThrowOnFailure(newParent.IncludeInProject(false)); } // Retrieve child nodes to add later. List<HierarchyNode> childNodes = this.GetChildNodes(); FileNode renamedNode; using (this.ProjectMgr.ExtensibilityEventsDispatcher.Suspend()) { // Remove this from its parent. ProjectMgr.OnItemDeleted(this); this.Parent.RemoveChild(this); // Update name in MSBuild this.ItemNode.Rename(CommonUtils.GetRelativeFilePath(ProjectMgr.ProjectHome, newFileName)); // Request a new file node be made. This is used to replace the old file node. This way custom // derived FileNode types will be used and correctly associated on rename. This is useful for things // like .txt -> .js where the file would now be able to be a startup project/file. renamedNode = this.ProjectMgr.CreateFileNode(this.ItemNode); renamedNode.ItemNode.RefreshProperties(); renamedNode.UpdateCaption(); newParent.AddChild(renamedNode); renamedNode.Parent = newParent; } UpdateCaption(); ProjectMgr.ReDrawNode(renamedNode, UIHierarchyElement.Caption); renamedNode.ProjectMgr.ExtensibilityEventsDispatcher.FireItemRenamed(this, oldFileName); //Update the new document in the RDT. DocumentManager.RenameDocument(renamedNode.ProjectMgr.Site, oldFileName, newFileName, renamedNode.ID); //Select the new node in the hierarchy renamedNode.ExpandItem(EXPANDFLAGS.EXPF_SelectItem); // Add children to new node and rename them appropriately. childNodes.ForEach(x => renamedNode.AddChild(x)); RenameChildNodes(renamedNode); return renamedNode; }
/// <summary> /// Renames the file in the hierarchy by removing old node and adding a new node in the hierarchy. /// </summary> /// <param name="oldFileName">The old file name.</param> /// <param name="newFileName">The new file name</param> /// <param name="newParentId">The new parent id of the item.</param> /// <returns>The newly added FileNode.</returns> /// <remarks>While a new node will be used to represent the item, the underlying MSBuild item will be the same and as a result file properties saved in the project file will not be lost.</remarks> private FileNode RenameFileNode(string oldFileName, string newFileName, HierarchyNode newParent) { if (CommonUtils.IsSamePath(oldFileName, newFileName)) { // We do not want to rename the same file return null; } if (newParent.IsNonMemberItem) { ErrorHandler.ThrowOnFailure(newParent.IncludeInProject(false)); } ProjectMgr.OnItemDeleted(this); this.Parent.RemoveChild(this); this.ID = this.ProjectMgr.ItemIdMap.Add(this); this.ItemNode.Rename(CommonUtils.GetRelativeFilePath(ProjectMgr.ProjectHome, newFileName)); this.ItemNode.RefreshProperties(); this.ProjectMgr.SetProjectFileDirty(true); newParent.AddChild(this); this.Parent = newParent; ProjectMgr.ReDrawNode(this, UIHierarchyElement.Caption); //Update the new document in the RDT. DocumentManager.RenameDocument(this.ProjectMgr.Site, oldFileName, newFileName, ID); //Select the new node in the hierarchy ExpandItem(EXPANDFLAGS.EXPF_SelectItem); RenameChildNodes(this); return this; }