RenameFileNode() protected method

protected RenameFileNode ( string oldFileName, string newFileName ) : FileNode
oldFileName string
newFileName string
return FileNode
Example #1
0
        private void RenameFolder(string newName)
        {
            // Do the rename (note that we only do the physical rename if the leaf name changed)
            string newPath = Path.Combine(this.Parent.VirtualNodeName, newName);

            if (String.Compare(Path.GetFileName(VirtualNodeName), newName, StringComparison.Ordinal) != 0)
            {
                this.RenameDirectory(Path.Combine(this.ProjectMgr.ProjectFolder, newPath));
            }
            this.VirtualNodeName = newPath;

            this.ItemNode.Rename(VirtualNodeName);
            ThreadHelper.ThrowIfNotOnUIThread();

            // Let all children know of the new path
            for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
            {
                FileNode childFileNode = child as FileNode;
                if (childFileNode != null && childFileNode.IsLink)
                {
                    string linkPath = Path.Combine(newPath, child.Caption);
                    childFileNode.RenameFileNode(child.Url, child.Url, linkPath, this.ID);
                }
                else if (!(child is FolderNode))
                {
                    child.SetEditLabel(child.Caption);
                }
                else
                {
                    FolderNode childFolderNode = (FolderNode)child;
                    childFolderNode.RenameFolder(childFolderNode.Caption);
                }
            }

            // Some of the previous operation may have changed the selection so set it back to us
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            // This happens in the context of renaming a folder.
            // Since we are already in solution explorer, it is extremely unlikely that we get a null return.
            // If we do, the consequences are minimal: the parent node will be selected instead of the
            // renamed node.
            if (uiWindow != null)
            {
                ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr, this.ID, EXPANDFLAGS.EXPF_SelectItem));
            }
        }