Exemplo n.º 1
0
        /// <summary>
        /// Rename all childnodes
        /// </summary>
        /// <param name="newFileNode">The newly added Parent node.</param>
        protected virtual void RenameChildNodes(FileNode parentNode)
        {
            foreach (HierarchyNode child in GetChildNodes())
            {
                FileNode childNode = child as FileNode;
                if (null == childNode)
                {
                    continue;
                }
                string newfilename;
                if (childNode.HasParentNodeNameRelation)
                {
                    string relationalName = childNode.Parent.GetRelationalName();
                    string extension      = childNode.GetRelationNameExtension();
                    newfilename = relationalName + extension;
                    newfilename = Path.Combine(Path.GetDirectoryName(childNode.Parent.GetMkDocument()), newfilename);
                }
                else
                {
                    newfilename = Path.Combine(Path.GetDirectoryName(childNode.Parent.GetMkDocument()), childNode.Caption);
                }

                childNode.RenameDocument(childNode.GetMkDocument(), newfilename);

                //We must update the DependsUpon property since the rename operation will not do it if the childNode is not renamed
                //which happens if the is no name relation between the parent and the child
                string dependentOf = childNode.ItemNode.GetMetadata(ProjectFileConstants.DependentUpon);
                if (!string.IsNullOrEmpty(dependentOf))
                {
                    childNode.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, childNode.Parent.ItemNode.GetMetadata(ProjectFileConstants.Include));
                }
            }
        }
Exemplo n.º 2
0
        private void MoveFilesForDeferredSave(HierarchyNode node, string basePath, string baseNewPath)
        {
            if (node != null)
            {
                for (var child = node.FirstChild; child != null; child = child.NextSibling)
                {
                    bool isOpen, isDirty, isOpenedByUs;
                    uint docCookie;
                    IVsPersistDocData persist;
                    var docMgr = child.GetDocumentManager();
                    if (docMgr != null)
                    {
                        docMgr.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out persist);
                        int cancelled;
                        if (isDirty)
                        {
                            child.SaveItem(VSSAVEFLAGS.VSSAVE_Save, null, docCookie, IntPtr.Zero, out cancelled);
                        }

                        FileNode fn = child as FileNode;
                        if (fn != null)
                        {
                            string newLoc = GetNewFilePathForDeferredSave(basePath, baseNewPath, child.Url);

                            // make sure the directory is there
                            Directory.CreateDirectory(Path.GetDirectoryName(newLoc));
                            fn.RenameDocument(child.Url, newLoc);
                        }

                        FolderNode folder = child as FolderNode;
                        if (folder != null)
                        {
                            folder.VirtualNodeName = GetNewFilePathForDeferredSave(basePath, baseNewPath, child.Url);
                        }
                    }

                    MoveFilesForDeferredSave(child, basePath, baseNewPath);
                }
            }
        }