Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Moves the HierarchyNode from the old path to be a child of the
        /// newly specified node.
        ///
        /// This is a low-level operation that only updates the hierarchy and our MSBuild
        /// state.  The parents of the node must already be created.
        ///
        /// To do a general rename, call RenameFolder instead.
        /// </summary>
        internal void ReparentFolder(string newPath)
        {
            // Reparent the folder
            ProjectMgr.OnItemDeleted(this);
            Parent.RemoveChild(this);
            ID = ProjectMgr.ItemIdMap.Add(this);

            ItemNode.Rename(CommonUtils.GetRelativeDirectoryPath(ProjectMgr.ProjectHome, newPath));
            var parent = ProjectMgr.GetParentFolderForPath(newPath);

            Debug.Assert(parent != null, "ReparentFolder called without full path to parent being created");
            parent.AddChild(this);
        }
Esempio n. 3
0
        /// <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)
            string newPath = Path.Combine(Parent.FullPathToChildren, newName);
            string oldPath = Url;

            if (!String.Equals(Path.GetFileName(Url), newName, StringComparison.Ordinal))
            {
                RenameDirectory(CommonUtils.GetAbsoluteDirectoryPath(ProjectMgr.ProjectHome, newPath));
            }

            // Reparent the folder
            ProjectMgr.OnItemDeleted(this);
            Parent.RemoveChild(this);
            ID = ProjectMgr.ItemIdMap.Add(this);

            ItemNode.Rename(CommonUtils.GetRelativeDirectoryPath(ProjectMgr.ProjectHome, newPath));
            ProjectMgr.SetProjectFileDirty(true);

            Parent.AddChild(this);

            var oldTriggerFlag = ProjectMgr.EventTriggeringFlag;

            ProjectMgr.EventTriggeringFlag |= ProjectNode.EventTriggering.DoNotTriggerTrackerEvents;
            try
            {
                // Let all children know of the new path
                for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
                {
                    FolderNode node = child as FolderNode;

                    if (node == null)
                    {
                        child.SetEditLabel(child.GetEditLabel());
                    }
                    else
                    {
                        node.RenameFolder(node.Caption);
                    }
                }
            }
            finally
            {
                ProjectMgr.EventTriggeringFlag = oldTriggerFlag;
            }

            ProjectMgr.Tracker.OnItemRenamed(oldPath, newPath, VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_Directory);

            // Some of the previous operation may have changed the selection so set it back to us
            ExpandItem(EXPANDFLAGS.EXPF_SelectItem);
        }
Esempio n. 4
0
        /// <summary>
        /// Moves the HierarchyNode from the old path to be a child of the
        /// newly specified node.
        ///
        /// This is a low-level operation that only updates the hierarchy and our MSBuild
        /// state.  The parents of the node must already be created.
        ///
        /// To do a general rename, call RenameFolder instead.
        /// </summary>
        internal void ReparentFolder(string newPath)
        {
            // Reparent the folder
            ProjectMgr.OnItemDeleted(this);
            Parent.RemoveChild(this);
            ProjectMgr.Site.GetUIThread().MustBeCalledFromUIThread();
            ID = ProjectMgr.ItemIdMap.Add(this);

            ItemNode.Rename(CommonUtils.GetRelativeDirectoryPath(ProjectMgr.ProjectHome, newPath));
            var parent = ProjectMgr.GetParentFolderForPath(newPath);

            if (parent == null)
            {
                Debug.Fail("ReparentFolder called without full path to parent being created");
                throw new DirectoryNotFoundException(newPath);
            }
            parent.AddChild(this);
        }
Esempio n. 5
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(Parent.VirtualNodeName, newName);

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

            ItemNode.Rename(VirtualNodeName);

            // Let all children know of the new path
            for (HierarchyNode child = FirstChild; child != null; child = child.NextSibling)
            {
                var node = child as FolderNode;

                if (node == null)
                {
                    child.SetEditLabel(child.Caption);
                }
                else
                {
                    node.RenameFolder(node.Caption);
                }
            }

            // Some of the previous operation may have changed the selection so set it back to us
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(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(ProjectMgr.InteropSafeIVsUIHierarchy, ID, EXPANDFLAGS.EXPF_SelectItem));
            }
        }