public override int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] projects, int[] firstIndices, string[] oldFileNames, string[] newFileNames, VSRENAMEFILEFLAGS[] flags)
        {
            if (!_project.IsRefreshing) {
                //Get the current value of the StartupFile Property
                string currentStartupFile = _project.GetProjectProperty(CommonConstants.StartupFile, true);
                string fullPathToStartupFile = Path.Combine(_project.ProjectDir, currentStartupFile);

                //Investigate all of the oldFileNames if they are equal to the current StartupFile
                int index = 0;
                foreach (string oldfile in oldFileNames) {
                    //Compare the files and update the StartupFile Property if the currentStartupFile is an old file
                    if (NativeMethods.IsSamePath(oldfile, fullPathToStartupFile)) {
                        //Get the newfilename and update the StartupFile property
                        string newfilename = newFileNames[index];
                        CommonFileNode node = _project.FindChild(newfilename) as CommonFileNode;
                        if (node == null)
                            throw new InvalidOperationException("Could not find the CommonFileNode object");
                        //Startup file has been renamed
                        _project.SetProjectProperty(CommonConstants.StartupFile, node.Url);
                        break;
                    }
                    index++;
                }
            }
            return VSConstants.S_OK;
        }
 int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(
     int cProjects,
     int cFiles,
     IVsProject[] rgpProjects,
     int[] rgFirstIndices,
     string[] rgszMkOldNames,
     string[] rgszMkNewNames,
     VSRENAMEFILEFLAGS[] rgFlags)
 {
     this.OnNotifyTestFileAddRemove(cProjects, rgpProjects, rgszMkOldNames, rgFirstIndices, TestFileChangedReason.Removed);
     return this.OnNotifyTestFileAddRemove(cProjects, rgpProjects, rgszMkNewNames, rgFirstIndices, TestFileChangedReason.Added);
 }
Example #3
0
        int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
        {
            Dictionary<string, string> ruleSetRenames = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < rgszMkOldNames.Length; i++)
            {
                string oldFileFullPath = rgszMkOldNames[i];
                if (Path.GetExtension(oldFileFullPath).Equals(".ruleset", StringComparison.OrdinalIgnoreCase))
                {
                    string newFileFullPath = rgszMkNewNames[i];
                    ruleSetRenames[oldFileFullPath] = newFileFullPath;
                }
            }

            foreach (var renamePair in ruleSetRenames)
            {
                UpdateCodeAnalysisRuleSetPropertiesInAllProjects(renamePair.Key, renamePair.Value);
            }

            return VSConstants.S_OK;
        }
        public override int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] projects, int[] firstIndices, string[] oldFileNames, string[] newFileNames, VSRENAMEFILEFLAGS[] flags) {
            if (!_project.IsRefreshing) {
                //Get the current value of the StartupFile Property
                string currentStartupFile = _project.GetProjectProperty(CommonConstants.StartupFile, true);
                string fullPathToStartupFile = CommonUtils.GetAbsoluteFilePath(_project.ProjectHome, currentStartupFile);

                //Investigate all of the oldFileNames if they are equal to the current StartupFile
                int index = 0;
                foreach (string oldfile in oldFileNames) {
                    FileNode node = null;
                    if ((flags[index] & VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_Directory) != 0) {
                        if (CommonUtils.IsSubpathOf(oldfile, fullPathToStartupFile)) {
                            // Get the newfilename and update the StartupFile property
                            string newfilename = Path.Combine(
                                newFileNames[index],
                                CommonUtils.GetRelativeFilePath(oldfile, fullPathToStartupFile)
                            );

                            node = _project.FindNodeByFullPath(newfilename) as FileNode;
                            Debug.Assert(node != null);
                        }
                    } else if (CommonUtils.IsSamePath(oldfile, fullPathToStartupFile)) {
                        //Get the newfilename and update the StartupFile property
                        string newfilename = newFileNames[index];
                        node = _project.FindNodeByFullPath(newfilename) as FileNode;
                        Debug.Assert(node != null);
                    }

                    if (node != null) {
                        // Startup file has been renamed
                        _project.SetProjectProperty(
                            CommonConstants.StartupFile,
                            CommonUtils.GetRelativeFilePath(_project.ProjectHome, node.Url));
                        break;
                    }
                    index++;
                }
            }
            return VSConstants.S_OK;
        }
		/// <summary>
		/// Get's called to tell the env that a file was renamed
		/// </summary>
		/// 
		internal void OnItemRenamed(string strOldName, string strNewName, VSRENAMEFILEFLAGS flag)
		{
			if((this.projectMgr.EventTriggeringFlag & ProjectNode.EventTriggering.DoNotTriggerTrackerEvents) == 0)
			{
				ErrorHandler.ThrowOnFailure(this.GetIVsTrackProjectDocuments2().OnAfterRenameFile(this.projectMgr, strOldName, strNewName, flag));
			}
		}
 public int OnQueryRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags, out int pfRenameCanContinue) {
     pfRenameCanContinue = 1;
     return VSConstants.S_OK;
 }
 public int OnAfterRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags) {
     return VSConstants.S_OK;
 }
 public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     return VsConstants.S_OK;
 }
        public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
        {
            if (rgszMkNewNames == null || rgpProjects == null || rgszMkOldNames == null || rgszMkOldNames.Length != rgszMkNewNames.Length)
                return VSConstants.E_POINTER;

            // TODO: C++ projects do not send directory renames; but do send OnAfterRenameFile() events
            //       for all files (one at a time). We should detect that case here and fix up this dirt!

            int iFile = 0;

            for (int i = 0; i < cFiles; i++)
            {
                string s = rgszMkOldNames[i];
                if (!string.IsNullOrEmpty(s) && GitItem.IsValidPath(s))
                    StatusCache.MarkDirty(s);

                s = rgszMkNewNames[i];
                if (!string.IsNullOrEmpty(s) && GitItem.IsValidPath(s))
                    StatusCache.MarkDirty(s);
            }

            if (SccProvider.IsActive)
            {
                FixWorkingCopyAfterRenames(rgszMkOldNames, rgszMkNewNames);

                for (int iProject = 0; (iProject < cProjects) && (iFile < cFiles); iProject++)
                {
                    int iLastFileThisProject = (iProject < cProjects - 1) ? rgFirstIndices[iProject + 1] : cFiles;

                    if (rgpProjects[iProject] != null)
                    {
                        IVsSccProject2 sccProject = rgpProjects[iProject] as IVsSccProject2;

                        bool track = SccProvider.TrackProjectChanges(sccProject);

                        for (; iFile < iLastFileThisProject; iFile++)
                        {
                            if (sccProject == null || !track)
                                continue; // Not handled by our provider

                            if (string.IsNullOrEmpty(rgszMkOldNames[iFile]) || !GitItem.IsValidPath(rgszMkOldNames[iFile]))
                                continue;

                            string oldName = GitTools.GetNormalizedFullPath(rgszMkOldNames[iFile]);
                            string newName = GitTools.GetNormalizedFullPath(rgszMkNewNames[iFile]);

                            if (oldName == newName)
                                continue;

                            SccProvider.OnProjectRenamedFile(sccProject, oldName, newName,rgFlags[iFile]);
                        }
                    }
                    else
                    {
                        // Renaming something in the solution (= solution file itself)

                        for (; iFile < iLastFileThisProject; iFile++)
                        {
                            if (string.IsNullOrEmpty(rgszMkOldNames[iFile]) || !GitItem.IsValidPath(rgszMkOldNames[iFile]))
                                continue;

                            string oldName = GitTools.GetNormalizedFullPath(rgszMkOldNames[iFile]);
                            string newName = GitTools.GetNormalizedFullPath(rgszMkNewNames[iFile]);

                            if (oldName == newName)
                                continue;

                            SccProvider.OnSolutionRenamedFile(oldName, newName, rgFlags[iFile]);
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
        /// <summary>
        ///  Asks the environment for permission to rename files.
        /// </summary>
        /// <param name="oldFileName">Path to the file to be renamed.</param>
        /// <param name="newFileName">Path to the new file.</param>
        /// <param name="flag">The VSRENAMEFILEFLAGS associated with the file to be renamed.</param>
        /// <returns>true if the file can be renamed. Otherwise false.</returns>
        /*internal, but public for FSharp.Project.dll*/ public bool CanRenameItem(string oldFileName, string newFileName, VSRENAMEFILEFLAGS flag)
        {
            // If we are silent then we assume that the file can be renamed, since we do not want to trigger this event.
            if ((this.projectMgr.EventTriggeringFlag & ProjectNode.EventTriggering.DoNotTriggerTrackerEvents) != 0)
            {
                return(true);
            }

            int iCanContinue = 0;

            ErrorHandler.ThrowOnFailure(this.GetIVsTrackProjectDocuments2().OnQueryRenameFile(projectMgr.InteropSafeIVsProject, oldFileName, newFileName, flag, out iCanContinue));
            return(iCanContinue != 0);
        }
 public int OnAfterRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags)
 {
     return(VSConstants.S_OK);
 }
        public int OnAfterRenameFiles(
            int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames,
            VSRENAMEFILEFLAGS[] rgFlags)
        {
            var hr = VSConstants.S_OK;
            var handler = AfterRenameFile;
            if (handler != null)
            {
                for (var fileCount = 0; fileCount < cFiles; fileCount++)
                {
                    var args = new ModelChangeEventArgs();
                    args.OldFileName = rgszMkOldNames[fileCount];
                    args.NewFileName = rgszMkNewNames[fileCount];
                    args.ProjectObj = GetProjectFromArray(cProjects, fileCount, rgpProjects, rgFirstIndices);
                    if (args.ProjectObj == null)
                    {
                        continue;
                    }

                    var newUri = Utils.FileName2Uri(args.NewFileName);
                    ModelManager modelManager = PackageManager.Package.ModelManager;
                    var artifact = modelManager.GetArtifact(newUri);
                    ModelManager tempModelManager = null;
                    try
                    {
                        if (artifact == null
                            && Path.GetExtension(args.NewFileName)
                                   .Equals(EntityDesignArtifact.ExtensionEdmx, StringComparison.CurrentCulture))
                        {
                            tempModelManager = new EntityDesignModelManager(new EFArtifactFactory(), new VSArtifactSetFactory());
                            artifact = tempModelManager.GetNewOrExistingArtifact(
                                newUri, new StandaloneXmlModelProvider(PackageManager.Package));
                        }
                        args.Artifact = artifact;

                        hr = handler(this, args);
                    }
                    finally
                    {
                        if (tempModelManager != null)
                        {
                            tempModelManager.Dispose();
                        }
                    }
                }
            }
            return hr;
        }
Example #13
0
        /// <summary>
        /// Get's called to rename the eventually running document this hierarchyitem points to
        /// </summary>
        /// returns FALSE if the doc can not be renamed
        public bool RenameDocument(string oldName, string newName)
        {
            IVsRunningDocumentTable pRDT = this.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (pRDT == null)
            {
                return(false);
            }
            IntPtr       docData = IntPtr.Zero;
            IVsHierarchy pIVsHierarchy;
            uint         itemId;
            uint         uiVsDocCookie;

            SuspendFileChanges sfc = new SuspendFileChanges(this.ProjectMgr.Site, oldName);

            sfc.Suspend();

            try
            {
                VSRENAMEFILEFLAGS renameflag = VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags;
                ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie));

                if (pIVsHierarchy != null && !Utilities.IsSameComObject(pIVsHierarchy, this.ProjectMgr))
                {
                    // Don't rename it if it wasn't opened by us.
                    return(false);
                }

                // ask other potentially running packages
                if (!this.ProjectMgr.Tracker.CanRenameItem(oldName, newName, renameflag))
                {
                    return(false);
                }
                // Allow the user to "fix" the project by renaming the item in the hierarchy
                // to the real name of the file on disk.
                bool shouldRenameInStorage = IsFileOnDisk(oldName) || !IsFileOnDisk(newName);
                Transactional.Try(
                    // Action
                    () => { if (shouldRenameInStorage)
                            {
                                RenameInStorage(oldName, newName);
                            }
                    },
                    // Compensation
                    () => { if (shouldRenameInStorage)
                            {
                                RenameInStorage(newName, oldName);
                            }
                    },
                    // Continuation
                    () =>
                {
                    string newFileName = Path.GetFileName(newName);
                    string oldCaption  = this.Caption;
                    Transactional.Try(
                        // Action
                        () => DocumentManager.UpdateCaption(this.ProjectMgr.Site, newFileName, docData),
                        // Compensation
                        () => DocumentManager.UpdateCaption(this.ProjectMgr.Site, oldCaption, docData),
                        // Continuation
                        () =>
                    {
                        bool caseOnlyChange = NativeMethods.IsSamePath(oldName, newName);
                        if (!caseOnlyChange)
                        {
                            // Check out the project file if necessary.
                            if (!this.ProjectMgr.QueryEditProjectFile(false))
                            {
                                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                            }
                            this.RenameFileNode(oldName, newName);
                        }
                        else
                        {
                            this.RenameCaseOnlyChange(newFileName);
                        }
                        bool extensionWasChanged = (0 != String.Compare(Path.GetExtension(oldName), Path.GetExtension(newName), StringComparison.OrdinalIgnoreCase));
                        if (extensionWasChanged)
                        {
                            // Update the BuildAction
                            this.ItemNode.ItemName = this.ProjectMgr.DefaultBuildAction(newName);
                        }
                        this.ProjectMgr.Tracker.OnItemRenamed(oldName, newName, renameflag);
                    });
                });
            }
            finally
            {
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
                sfc.Resume(); // can throw, e.g. when RenameFileNode failed, but file was renamed on disk and now editor cannot find file
            }

            return(true);
        }
 public int OnAfterRenameFiles(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                               string[] oldNames, string[] newNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     try
     {
         for (int i = 0; i < projectsLength; ++i)
         {
             EnvDTE.Project project = DTEUtil.GetProject(projects[i] as IVsHierarchy);
             if (DTEUtil.IsIceBuilderEnabled(project))
             {
                 int j = indices[i];
                 int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                 for (; j < k; ++j)
                 {
                     ProjectUtil.DeleteItems(project, ProjectUtil.GetGeneratedFiles(project, oldNames[j]));
                     if (ProjectUtil.IsSliceFileName(newNames[j]))
                     {
                         ProjectUtil.SetupGenerated(project, newNames[j]);
                     }
                 }
                 Package.Instance.FileTracker.Reap(project);
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return 0;
 }
Example #15
0
 int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     _flavoredProjectBase.GenerateEvents(rgpProjects, rgFirstIndices, rgszMkNewNames, _flavoredProjectBase.FileRenamed, new ProjectDocumentsChangeEventArgs());
     return VSConstants.S_OK;
 }
Example #16
0
        public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
        {
            if (FileRenamed != null)
            {
                var oldPaths = ExtractPath(cProjects, cFiles, rgpProjects, rgFirstIndices, rgszMkOldNames).ToArray();
                var newPaths = ExtractPath(cProjects, cFiles, rgpProjects, rgFirstIndices, rgszMkNewNames).ToArray();

                for (var i = 0; i < oldPaths.Length; i++)
                {
                    FileRenamed(this, new FileRenamedEventArgs(oldPaths[i], newPaths[i]));
                }
            }

            return VSConstants.S_OK;
        }
Example #17
0
 /// <summary>
 /// This method notifies the client when files have been renamed in the project.
 /// </summary>
 /// <param name="cProjects"></param>
 /// <param name="cFiles"></param>
 /// <param name="rgpProjects"></param>
 /// <param name="rgFirstIndices"></param>
 /// <param name="rgszMkOldNames"></param>
 /// <param name="rgszMkNewNames"></param>
 /// <param name="rgFlags"></param>
 /// <returns></returns>
 int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(int cProjects,
                                                        int cFiles,
                                                        IVsProject[] rgpProjects,
                                                        int[] rgFirstIndices,
                                                        string[] rgszMkOldNames,
                                                        string[] rgszMkNewNames,
                                                        VSRENAMEFILEFLAGS[] rgFlags) {
     //////SrcMLFileLogger.DefaultLogger.Info("==> Triggered IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles()");
     OnNotifyFileAddRemove(cProjects, cFiles, rgpProjects, rgFirstIndices, rgszMkOldNames, FileEventType.FileDeleted);
     return OnNotifyFileAddRemove(cProjects, cFiles, rgpProjects, rgFirstIndices, rgszMkNewNames, FileEventType.FileAdded);
 }
 /// <summary>
 /// Get's called to tell the env that a file was renamed
 /// </summary>
 ///
 /*internal, but public for FSharp.Project.dll*/ public void OnItemRenamed(string strOldName, string strNewName, VSRENAMEFILEFLAGS flag)
 {
     if ((this.projectMgr.EventTriggeringFlag & ProjectNode.EventTriggering.DoNotTriggerTrackerEvents) == 0)
     {
         ErrorHandler.ThrowOnFailure(this.GetIVsTrackProjectDocuments2().OnAfterRenameFile(projectMgr.InteropSafeIVsProject, strOldName, strNewName, flag));
     }
 }
 public virtual int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     return VSConstants.E_NOTIMPL;
 }
 public int OnQueryRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags, out int pfRenameCanContinue)
 {
     throw new NotImplementedException();
 }
Example #21
0
        public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
        {
            HandleRenameFiles(cProjects, cFiles, rgpProjects, rgFirstIndices, rgszMkOldNames, rgszMkNewNames, CsFileRenamed, TemplateRenamed);

            return VSConstants.S_OK;
        }
 public int OnAfterRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags)
 {
     throw new NotImplementedException();
 }
 public int OnQueryRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags, out int pfRenameCanContinue)
 {
     pfRenameCanContinue = 1;
     return(VSConstants.S_OK);
 }
 public int OnAfterRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     throw new NotImplementedException();
 }
        public override int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] projects, int[] firstIndices, string[] oldFileNames, string[] newFileNames, VSRENAMEFILEFLAGS[] flags)
        {
            //Get the current value of the MainFile Property
            string currentMainFile = this.project.GetProjectProperty(PythonProjectFileConstants.MainFile, true);
            string fullPathToMainFile = Path.Combine(Path.GetDirectoryName(this.project.BaseURI.Uri.LocalPath), currentMainFile);

            //Investigate all of the oldFileNames if they belong to the current project and if they are equal to the current MainFile
            int index = 0;
            foreach(string oldfile in oldFileNames)
            {
                //Compare this project with the project that the old file belongs to
                IVsProject belongsToProject = projects[firstIndices[index]];
                if(Utilities.IsSameComObject(belongsToProject, this.project))
                {
                    //Compare the files and update the MainFile Property if the currentMainFile is an old file
                    if(NativeMethods.IsSamePath(oldfile, fullPathToMainFile))
                    {
                        //Get the newfilename and update the MainFile property
                        string newfilename = newFileNames[index];
                        PythonFileNode node = this.project.FindChild(newfilename) as PythonFileNode;
                        if(node == null)
                            throw new InvalidOperationException("Could not find the PythonFileNode object");
                        this.project.SetProjectProperty(PythonProjectFileConstants.MainFile, node.GetRelativePath());
                        break;
                    }
                }

                index++;
            }

            return VSConstants.S_OK;
        }
Example #26
0
        void IAnkhSccProviderEvents.OnProjectFileRenamed(IVsSccProject2 sccProject, string oldName, string newName, VSRENAMEFILEFLAGS vSRENAMEFILEFLAGS)
        {
            SccProjectData data;

            ProjectMap.EnsureSccProject(sccProject, out data);
            OnProjectFileRenamed(data, oldName, newName);
        }
Example #27
0
 int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     GenerateEvents(rgpProjects, rgFirstIndices, rgszMkNewNames, FileRenamed, new ProjectDocumentsChangeEventArgs());
     return NativeMethods.S_OK;
 }
        int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
        {
            for (int i = 0; i < rgpProjects.Length; i++)
            {
                int indexOfFirstDocumentInProject = IndexOfFirstDocumentInProject(i, rgFirstIndices);
                int indexOfFirstDocumentInNextProject = IndexOfFirstDocumentInProject(i + 1, rgFirstIndices);
                for (int j = indexOfFirstDocumentInProject; j < indexOfFirstDocumentInNextProject; j++)
                {
                    string oldFileFullPath = rgszMkOldNames[j];
                    string newFileFullPath = rgszMkNewNames[j];
                    if (Path.GetExtension(oldFileFullPath).Equals(".ruleset", StringComparison.OrdinalIgnoreCase))
                    {
                        EnvDTE.Project project;
                        IVsHierarchy hierarchy = rgpProjects[i] as IVsHierarchy;
                        if (hierarchy != null &&
                            hierarchy.TryGetProject(out project))
                        {
                            UpdateCodeAnalysisRuleSetPropertiesInProject(project, oldFileFullPath, newFileFullPath);
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
        /// <summary>
        /// Get's called to rename the eventually running document this hierarchyitem points to
        /// </summary>
        /// returns FALSE if the doc can not be renamed
        internal bool RenameDocument(string oldName, string newName)
        {
            IVsRunningDocumentTable pRDT = this.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (pRDT == null)
            {
                return(false);
            }
            IntPtr       docData = IntPtr.Zero;
            IVsHierarchy pIVsHierarchy;
            uint         itemId;
            uint         uiVsDocCookie;

            SuspendFileChanges sfc = new SuspendFileChanges(this.ProjectMgr.Site, oldName);

            sfc.Suspend();

            try
            {
                // Suspend ms build since during a rename operation no msbuild re-evaluation should be performed until we have finished.
                // Scenario that could fail if we do not suspend.
                // We have a project system relying on MPF that triggers a Compile target build (re-evaluates itself) whenever the project changes. (example: a file is added, property changed.)
                // 1. User renames a file in  the above project sytem relying on MPF
                // 2. Our rename funstionality implemented in this method removes and readds the file and as a post step copies all msbuild entries from the removed file to the added file.
                // 3. The project system mentioned will trigger an msbuild re-evaluate with the new item, because it was listening to OnItemAdded.
                //    The problem is that the item at the "add" time is only partly added to the project, since the msbuild part has not yet been copied over as mentioned in part 2 of the last step of the rename process.
                //    The result is that the project re-evaluates itself wrongly.
                VSRENAMEFILEFLAGS renameflag = VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags;
                try
                {
                    this.ProjectMgr.SuspendMSBuild();
                    ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie));

                    if (pIVsHierarchy != null && !Utilities.IsSameComObject(pIVsHierarchy, this.ProjectMgr))
                    {
                        // Don't rename it if it wasn't opened by us.
                        return(false);
                    }

                    // ask other potentially running packages
                    if (!this.ProjectMgr.Tracker.CanRenameItem(oldName, newName, renameflag))
                    {
                        return(false);
                    }
                    // Allow the user to "fix" the project by renaming the item in the hierarchy
                    // to the real name of the file on disk.
                    if (IsFileOnDisk(oldName) || !IsFileOnDisk(newName))
                    {
                        RenameInStorage(oldName, newName);
                    }

                    string newFileName = Path.GetFileName(newName);
                    DocumentManager.UpdateCaption(this.ProjectMgr.Site, newFileName, docData);
                    bool caseOnlyChange = NativeMethods.IsSamePath(oldName, newName);
                    if (!caseOnlyChange)
                    {
                        // Check out the project file if necessary.
                        if (!this.ProjectMgr.QueryEditProjectFile(false))
                        {
                            throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                        }

                        this.RenameFileNode(oldName, newName);
                    }
                    else
                    {
                        this.RenameCaseOnlyChange(newFileName);
                    }
                }
                finally
                {
                    this.ProjectMgr.ResumeMSBuild(this.ProjectMgr.ReEvaluateProjectFileTargetName);
                }

                this.ProjectMgr.Tracker.OnItemRenamed(oldName, newName, renameflag);
            }
            finally
            {
                sfc.Resume();
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }

            return(true);
        }
        /// <summary>
        /// Called when a file in a project is renamed
        /// </summary>
        /// <param name="project">The SCC project.</param>
        /// <param name="oldName">The old name.</param>
        /// <param name="newName">The new name.</param>
        /// <param name="flags">The flags.</param>
        internal void OnProjectRenamedFile(IVsSccProject2 project, string oldName, string newName, VSRENAMEFILEFLAGS flags)
        {
            SccProjectData data;
            if (!_projectMap.TryGetValue(project, out data))
                return; // Not managed by us
            else
                data.CheckProjectRename(project, oldName, newName); // Just to be sure (should be handled by other event)

            data.RemovePath(oldName);
            data.AddPath(newName);

            if (!IsActive)
                return;

            using (GitSccContext git = new GitSccContext(Context))
            {
                if (!git.IsUnversioned(oldName))
                {
                    if (!Directory.Exists(newName)) // Fails if the new name is a directory!
                        git.SafeWcMoveFixup(oldName, newName);
                }

                MarkDirty(new string[] { oldName, newName }, true);
            }
        }
 public int OnAfterRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags) {
     return VSConstants.S_OK;
 }
        internal void OnSolutionRenamedFile(string oldName, string newName, VSRENAMEFILEFLAGS flags)
        {
            if (!IsActive)
                return;

            _solutionDirectory = _solutionFile = null; // Get new data after this rename

            using (GitSccContext git = new GitSccContext(Context))
            {
                if (!git.IsUnversioned(oldName))
                {
                    try
                    {
                        git.SafeWcMoveFixup(oldName, newName);
                    }
                    catch (IOException)
                    {
                        if (_delayedMove == null)
                            _delayedMove = new List<FixUp>();
                        _delayedMove.Add(new FixUp(oldName, newName));

                        RegisterForSccCleanup();
                    }

                    MarkDirty(new string[] { oldName, newName }, true);
                }
            }

            Monitor.ScheduleGlyphUpdate(SolutionFilename);
        }
		/// <summary>
		///  Asks the environment for permission to rename files.
		/// </summary>
		/// <param name="oldFileName">Path to the file to be renamed.</param>
		/// <param name="newFileName">Path to the new file.</param>
		/// <param name="flag">The VSRENAMEFILEFLAGS associated with the file to be renamed.</param>
		/// <returns>true if the file can be renamed. Otherwise false.</returns>
		internal bool CanRenameItem(string oldFileName, string newFileName, VSRENAMEFILEFLAGS flag)
		{
			// If we are silent then we assume that the file can be renamed, since we do not want to trigger this event.
			if((this.projectMgr.EventTriggeringFlag & ProjectNode.EventTriggering.DoNotTriggerTrackerEvents) != 0)
			{
				return true;
			}

			int iCanContinue = 0;
			ErrorHandler.ThrowOnFailure(this.GetIVsTrackProjectDocuments2().OnQueryRenameFile(this.projectMgr, oldFileName, newFileName, flag, out iCanContinue));
			return (iCanContinue != 0);
		}
 /// <summary>
 /// Get's called to tell the env that a file was renamed
 /// </summary>
 /// 
 public virtual void OnItemRenamed(string strOldName, string strNewName, VSRENAMEFILEFLAGS flag)
 {
     if((this.projectMgr.EventTriggeringFlag & SuppressEvents.Tracker) == 0)
     {
         ErrorHandler.ThrowOnFailure(this.GetIVsTrackProjectDocuments2().OnAfterRenameFile(this.projectMgr.InteropSafeIVsProject3, strOldName, strNewName, flag));
     }
 }
Example #35
0
 public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices,
                               string[] oldNames, string[] newNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     foreach(string newName in newNames)
     {
         if(!Util.isSliceFilename(newName))
         {
             continue;
         }
         ProjectItem item = Util.findItem(newName);
         if(item == null)
         {
             continue;
         }
         Project project = item.ContainingProject;
         if(project == null)
         {
             continue;
         }
         if(!Util.isSliceBuilderEnabled(project))
         {
             continue;
         }
         buildProject(project, false, vsBuildScope.vsBuildScopeProject);
     }
     return 0;
 }
 public int OnQueryRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags, out int pfRenameCanContinue)
 {
     throw new NotImplementedException();
 }
 public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     renaimng_in_progress = false;
     InvalidateParentItems(rgszMkOldNames, rgszMkNewNames);
     return VSConstants.S_OK;
 }
 public int OnAfterRenameFile(IVsProject pProject, string pszMkOldName, string pszMkNewName, VSRENAMEFILEFLAGS flags)
 {
     throw new NotImplementedException();
 }
Example #39
0
        /// <summary>
        /// Gets called to rename the eventually running document this hierarchyitem points to
        /// </summary>
        /// returns FALSE if the doc can not be renamed
        internal bool RenameDocument(string oldName, string newName)
        {
            IVsRunningDocumentTable pRDT = this.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (pRDT == null)
            {
                return(false);
            }
            IntPtr       docData = IntPtr.Zero;
            IVsHierarchy pIVsHierarchy;
            uint         itemId;
            uint         uiVsDocCookie;

            SuspendFileChanges sfc = null;

            if (File.Exists(oldName))
            {
                sfc = new SuspendFileChanges(this.ProjectMgr.Site, oldName);
                sfc.Suspend();
            }

            try {
                // Suspend ms build since during a rename operation no msbuild re-evaluation should be performed until we have finished.
                // Scenario that could fail if we do not suspend.
                // We have a project system relying on MPF that triggers a Compile target build (re-evaluates itself) whenever the project changes. (example: a file is added, property changed.)
                // 1. User renames a file in  the above project sytem relying on MPF
                // 2. Our rename funstionality implemented in this method removes and readds the file and as a post step copies all msbuild entries from the removed file to the added file.
                // 3. The project system mentioned will trigger an msbuild re-evaluate with the new item, because it was listening to OnItemAdded.
                //    The problem is that the item at the "add" time is only partly added to the project, since the msbuild part has not yet been copied over as mentioned in part 2 of the last step of the rename process.
                //    The result is that the project re-evaluates itself wrongly.
                VSRENAMEFILEFLAGS renameflag = VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags;
                ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie));

                if (pIVsHierarchy != null && !Utilities.IsSameComObject(pIVsHierarchy, this.ProjectMgr))
                {
                    // Don't rename it if it wasn't opened by us.
                    return(false);
                }

                // ask other potentially running packages
                if (!this.ProjectMgr.Tracker.CanRenameItem(oldName, newName, renameflag))
                {
                    return(false);
                }

                if (IsFileOnDisk(oldName))
                {
                    RenameInStorage(oldName, newName);
                }

                // For some reason when ignoreFileChanges is called in Resume, we get an ArgumentException because
                // Somewhere a required fileWatcher is null.  This issue only occurs when you copy and rename a typescript file,
                // Calling Resume here prevents said fileWatcher from being null. Don't know why it works, but it does.
                // Also fun! This is the only location it can go (between RenameInStorage and RenameFileNode)
                // So presumably there is some condition that is no longer met once both of these methods are called with a ts file.
                // https://nodejstools.codeplex.com/workitem/1510
                if (sfc != null)
                {
                    sfc.Resume();
                    sfc.Suspend();
                }

                if (!CommonUtils.IsSamePath(oldName, newName))
                {
                    // Check out the project file if necessary.
                    if (!this.ProjectMgr.QueryEditProjectFile(false))
                    {
                        throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                    }

                    this.RenameFileNode(oldName, newName);
                }
                else
                {
                    this.RenameCaseOnlyChange(oldName, newName);
                }

                DocumentManager.UpdateCaption(this.ProjectMgr.Site, Caption, docData);

                // changed from MPFProj:
                // http://mpfproj10.codeplex.com/WorkItem/View.aspx?WorkItemId=8231
                this.ProjectMgr.Tracker.OnItemRenamed(oldName, newName, renameflag);
            } finally {
                if (sfc != null)
                {
                    sfc.Resume();
                }
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }

            return(true);
        }
 public int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags) {
     for (int i = 0; i < rgszMkOldNames.Length; i++) {
         DocumentEvents.Add("OnAfterRenameFiles " + rgszMkOldNames[i] + " " + rgszMkNewNames[i] + " " + rgFlags[i]);
         CodeDocumentEvents.Add("OnAfterRenameFiles(" + GetRelativePath(rgpProjects[0], rgszMkOldNames[i]) + ", " + GetRelativePath(rgpProjects[0], rgszMkNewNames[i]) + ", " + GetEnum(rgFlags[i]) + ")");
     }
     return VSConstants.S_OK;
 }