/// <summary> /// Renames the folder to the new name. /// </summary> public virtual void RenameFolder(string newName) { // Do the rename (note that we only do the physical rename if the leaf name changed) Debug.Assert(Path.IsPathRooted(Parent.FullPathToChildren), "Invalid full path: " + Parent.FullPathToChildren); string newPath = CommonUtils.GetAbsoluteDirectoryPath(Parent.FullPathToChildren, newName); string oldPath = Url; if (!CommonUtils.IsSameDirectory(oldPath, newPath)) { RenameDirectory(newPath); } bool wasExpanded = GetIsExpanded(); var parentPath = CommonUtils.GetParent(newPath); var newParent = ProjectMgr.CreateFolderNodes(parentPath); if (newParent == null) { Debug.Fail("Failed to create folder nodes"); throw new DirectoryNotFoundException(newPath); } var oldTriggerFlag = ProjectMgr.EventTriggeringFlag; ProjectMgr.EventTriggeringFlag |= ProjectNode.EventTriggering.DoNotTriggerTrackerEvents; try { ProjectMgr.OnItemDeleted(this); var relativePath = CommonUtils.GetRelativeDirectoryPath( ProjectMgr.ProjectHome, newPath ); ItemNode.Rename(relativePath); ProjectMgr.OnItemAdded(newParent, this); Reparent(newParent); } finally { ProjectMgr.EventTriggeringFlag = oldTriggerFlag; } ProjectMgr.Tracker.OnItemRenamed(oldPath, Url, VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_Directory); // Some of the previous operation may have changed the selection so set it back to us ExpandItem(wasExpanded ? EXPANDFLAGS.EXPF_ExpandFolder : EXPANDFLAGS.EXPF_CollapseFolder); ExpandItem(EXPANDFLAGS.EXPF_SelectItem); }