public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { renaimng_in_progress = true; return VSConstants.S_OK; }
int IVsTrackProjectDocumentsEvents2.OnQueryRenameFiles( IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { return VSConstants.S_OK; }
public int OnQueryRenameFiles(IVsProject ivsProject, int cFiles, string[] oldNames, string[] newNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { for(int i = 0; i < oldNames.Length; ++i) { string oldName = oldNames[i]; string newName = newNames[i]; if(String.IsNullOrEmpty(oldName) || String.IsNullOrEmpty(newName)) { continue; } if(!Util.isSliceFilename(oldName) ) { continue; } ProjectItem item = Util.findItem(oldName); if(item == null) { continue; } if(!Util.isProjectItemFile(item)) { continue; } Project project = item.ContainingProject; if(project == null) { continue; } try { if(Util.isCSharpProject(project)) { String csPath = getCSharpGeneratedFileName(project, newName, "cs"); if(File.Exists(csPath) || Util.findItem(csPath, project.ProjectItems) != null) { MessageBox.Show("A file named '" + Path.GetFileName(csPath) + "' already exists.\n" + oldName + " could not be renamed to '" + item.Name + "'.", "Ice Visual Studio Add-in", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return -1; } // // Get rid of generated files, for the removed .ice file. // fileTracker().reap(project); ProjectItem generatedItem = Util.findItem(getCSharpGeneratedFileName(project, item, "cs"), project.ProjectItems); if(generatedItem == null) { continue; } generatedItem.Delete(); } else if(Util.isCppProject(project)) { string cppPath = getCppGeneratedFileName(project, newName, "." + Util.getSourceExt(project)); string hPath = Path.ChangeExtension(cppPath, "." + Util.getHeaderExt(project)); if(File.Exists(cppPath) || Util.findItem(cppPath, project.ProjectItems) != null) { MessageBox.Show("A file named '" + Path.GetFileName(cppPath) + "' already exists.\n" + "If you want to add '" + Path.GetFileName(newName) + "' first remove " + " '" + Path.GetFileName(cppPath) + "' and '" + Path.GetFileName(hPath) + "' from your project.", "Ice Visual Studio Add-in", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return -1; } if(File.Exists(hPath) || Util.findItem(hPath, project.ProjectItems) != null) { MessageBox.Show("A file named '" + Path.GetFileName(hPath) + "' already exists.\n" + "If you want to add '" + Path.GetFileName(newName) + "' first remove " + " '" + Path.GetFileName(cppPath) + "' and '" + Path.GetFileName(hPath) + "' from your project.", "Ice Visual Studio Add-in", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return -1; } // // Get rid of generated files, for the removed .ice file. // fileTracker().reap(project); string cppGeneratedPath = getCppGeneratedFileName(project, oldName, Util.getSourceExt(project)); string hGeneratedPath = Path.ChangeExtension(cppGeneratedPath, Util.getHeaderExt(project)); ProjectItem generatedItem = Util.findItem(cppGeneratedPath, project.ProjectItems); if(generatedItem != null) { generatedItem.Delete(); } generatedItem = Util.findItem(hGeneratedPath, project.ProjectItems); if(generatedItem != null) { generatedItem.Delete(); } } } catch(Exception ex) { Util.write(null, Util.msgLevel.msgError, ex.ToString() + "\n"); Util.unexpectedExceptionWarning(ex); throw; } } return 0; }
public virtual int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { return VSConstants.E_NOTIMPL; }
public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { if (rgszMkNewNames == null || rgszMkOldNames == null) return VSConstants.E_POINTER; bool allOk = true; if (pProject == null) { // We are renaming the solution file (or something in the solution itself) for (int i = 0; i < cFiles; i++) { bool ok = true; if(!GitItem.IsValidPath(rgszMkOldNames[i])) continue; string oldName = GitTools.GetNormalizedFullPath(rgszMkOldNames[i]); string newName = GitTools.GetNormalizedFullPath(rgszMkNewNames[i]); if(oldName == newName) continue; SccProvider.OnBeforeSolutionRenameFile(oldName,newName, rgFlags[i], out ok); if (rgResults != null) rgResults[i] = ok ? VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameOK : VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK; if (!ok) allOk = false; } } else { IVsSccProject2 sccProject = pProject as IVsSccProject2; bool track = SccProvider.TrackProjectChanges(sccProject); for (int i = 0; i < cFiles; i++) { bool ok = true; if (!GitItem.IsValidPath(rgszMkOldNames[i])) continue; string oldName = GitTools.GetNormalizedFullPath(rgszMkOldNames[i]); string newName = GitTools.GetNormalizedFullPath(rgszMkNewNames[i]); if (oldName == newName) continue; if (track) SccProvider.OnBeforeProjectRenameFile(sccProject, oldName, newName, rgFlags[i], out ok); if (rgResults != null) rgResults[i] = ok ? VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameOK : VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK; if (!ok) allOk = false; } } if (pSummaryResult != null) pSummaryResult[0] = allOk ? VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameOK : VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK; if (!allOk) _batchOk = false; return VSConstants.S_OK; }
public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { throw new NotImplementedException(); }
public void TestTPDEvents() { int result = 0; SccProviderService target = GetSccProviderServiceInstance; solution.SolutionFile = Path.GetTempFileName(); MockIVsProject project = new MockIVsProject(Path.GetTempFileName()); solution.AddProject(project); Hashtable uncontrolled = new Hashtable(); uncontrolled[project as IVsSccProject2] = true; target.AddProjectsToSourceControl(ref uncontrolled, true); // In real live, a QueryEdit call on the project file would be necessary to add/rename/delete items // Add a new item and fire the appropriate events string pendingAddFile = Path.GetTempFileName(); VSQUERYADDFILERESULTS[] pSummaryResultAdd = new VSQUERYADDFILERESULTS[1]; VSQUERYADDFILERESULTS[] rgResultsAdd = new VSQUERYADDFILERESULTS[1]; result = target.OnQueryAddFiles(project as IVsProject, 1, new string[] { pendingAddFile }, null, pSummaryResultAdd, rgResultsAdd); Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result); project.AddItem(pendingAddFile); result = target.OnAfterAddFilesEx(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { pendingAddFile }, null); Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result); Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(pendingAddFile), "Incorrect status returned"); // Checkin the pending add file target.AddFileToSourceControl(pendingAddFile); // Rename the item and verify the file remains is controlled string newName = pendingAddFile + ".renamed"; VSQUERYRENAMEFILERESULTS[] pSummaryResultRen = new VSQUERYRENAMEFILERESULTS[1]; VSQUERYRENAMEFILERESULTS[] rgResultsRen = new VSQUERYRENAMEFILERESULTS[1]; result = target.OnQueryRenameFiles(project as IVsProject, 1, new string[] { pendingAddFile }, new string[] { newName }, null, pSummaryResultRen, rgResultsRen); Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result); project.RenameItem(pendingAddFile, newName); result = target.OnAfterRenameFiles(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { pendingAddFile }, new string[] { newName }, new VSRENAMEFILEFLAGS[] { VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags }); Assert.AreEqual <int>(VSConstants.S_OK, result); Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(pendingAddFile), "Incorrect status returned"); Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(newName), "Incorrect status returned"); // Mock the UIShell service to answer Cancel to the dialog invocation BaseMock mockUIShell = MockUiShellProvider.GetShowMessageBoxCancel(); serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true); // Try to delete the file from project; the delete should not be allowed VSQUERYREMOVEFILERESULTS[] pSummaryResultDel = new VSQUERYREMOVEFILERESULTS[1]; VSQUERYREMOVEFILERESULTS[] rgResultsDel = new VSQUERYREMOVEFILERESULTS[1]; result = target.OnQueryRemoveFiles(project as IVsProject, 1, new string[] { newName }, null, pSummaryResultDel, rgResultsDel); Assert.AreEqual <int>(VSConstants.S_OK, result); Assert.AreEqual <VSQUERYREMOVEFILERESULTS>(VSQUERYREMOVEFILERESULTS.VSQUERYREMOVEFILERESULTS_RemoveNotOK, pSummaryResultDel[0]); // Mock the UIShell service to answer Yes to the dialog invocation serviceProvider.RemoveService(typeof(IVsUIShell)); mockUIShell = MockUiShellProvider.GetShowMessageBoxYes(); serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true); // Try to delete the file from project; the delete should be allowed this time result = target.OnQueryRemoveFiles(project as IVsProject, 1, new string[] { newName }, null, pSummaryResultDel, rgResultsDel); Assert.AreEqual <int>(VSConstants.S_OK, result); Assert.AreEqual <VSQUERYREMOVEFILERESULTS>(VSQUERYREMOVEFILERESULTS.VSQUERYREMOVEFILERESULTS_RemoveOK, pSummaryResultDel[0]); // Remove the file from project project.RemoveItem(newName); result = target.OnAfterRemoveFiles(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { newName }, null); Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result); }
int IVsTrackProjectDocumentsEvents2.OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { return NativeMethods.S_OK; // We are not interested in this one }
public int OnQueryRenameFiles(IVsProject ivsProject, int filesLength, string[] oldNames, string[] newNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { try { EnvDTE.Project project = DTEUtil.GetProject(ivsProject as IVsHierarchy); if(DTEUtil.IsIceBuilderEnabled(project)) { for(int i = 0; i < filesLength; ++i) { if(Path.GetExtension(oldNames[i]).Equals(".ice") && Path.GetExtension(newNames[i]).Equals(".ice")) { if(!ProjectUtil.CheckGenerateFileIsValid(project, newNames[i])) { rgResults[i] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK; } } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return 0; }
public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { TraceAdviseEvent("OnQueryRenameFiles", rgszMkOldNames); return VSConstants.E_NOTIMPL; }
public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { var args = new QueryProjectRenameFilesEventArgs(this.events) { OldFiles = rgszMkOldNames, NewFiles = rgszMkNewNames }; //VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddOK; //VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddNotOK; this.events.TriggerQueryProjectRenameFiles(args); return VSConstants.S_OK; }
public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { for (int i = 0; i < rgszMkOldNames.Length; i++) { DocumentEvents.Add("OnQueryRenameFiles " + rgszMkOldNames[i] + " " + rgszMkNewNames[i] + " " + rgFlags[i]); CodeDocumentEvents.Add("OnQueryRenameFiles(" + GetRelativePath(pProject, rgszMkOldNames[i]) + ", " + GetRelativePath(pProject, rgszMkNewNames[i]) + ", " + GetEnum(rgFlags[i]) + ")"); } return VSConstants.S_OK; }
public void TestTPDEvents() { int result = 0; SccProviderService target = GetSccProviderServiceInstance; solution.SolutionFile = Path.GetTempFileName(); MockIVsProject project = new MockIVsProject(Path.GetTempFileName()); solution.AddProject(project); Hashtable uncontrolled = new Hashtable(); uncontrolled[project as IVsSccProject2] = true; target.AddProjectsToSourceControl(ref uncontrolled, true); // In real live, a QueryEdit call on the project file would be necessary to add/rename/delete items // Add a new item and fire the appropriate events string pendingAddFile = Path.GetTempFileName(); VSQUERYADDFILERESULTS[] pSummaryResultAdd = new VSQUERYADDFILERESULTS[1]; VSQUERYADDFILERESULTS[] rgResultsAdd = new VSQUERYADDFILERESULTS[1]; result = target.OnQueryAddFiles(project as IVsProject, 1, new string[] {pendingAddFile}, null, pSummaryResultAdd, rgResultsAdd); Assert.AreEqual<int>(VSConstants.E_NOTIMPL, result); project.AddItem(pendingAddFile); result = target.OnAfterAddFilesEx(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { pendingAddFile }, null); Assert.AreEqual<int>(VSConstants.E_NOTIMPL, result); Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(pendingAddFile), "Incorrect status returned"); // Checkin the pending add file target.AddFileToSourceControl(pendingAddFile); // Rename the item and verify the file remains is controlled string newName = pendingAddFile + ".renamed"; VSQUERYRENAMEFILERESULTS[] pSummaryResultRen = new VSQUERYRENAMEFILERESULTS[1]; VSQUERYRENAMEFILERESULTS[] rgResultsRen = new VSQUERYRENAMEFILERESULTS[1]; result = target.OnQueryRenameFiles(project as IVsProject, 1, new string[] { pendingAddFile }, new string[] { newName }, null, pSummaryResultRen, rgResultsRen); Assert.AreEqual<int>(VSConstants.E_NOTIMPL, result); project.RenameItem(pendingAddFile, newName); result = target.OnAfterRenameFiles(1, 1, new IVsProject[] {project as IVsProject}, new int[] {0}, new string[] { pendingAddFile }, new string[] { newName }, new VSRENAMEFILEFLAGS[] {VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags}); Assert.AreEqual<int>(VSConstants.S_OK, result); Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(pendingAddFile), "Incorrect status returned"); Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(newName), "Incorrect status returned"); // Mock the UIShell service to answer Cancel to the dialog invocation BaseMock mockUIShell = MockUiShellProvider.GetShowMessageBoxCancel(); serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true); // Try to delete the file from project; the delete should not be allowed VSQUERYREMOVEFILERESULTS[] pSummaryResultDel = new VSQUERYREMOVEFILERESULTS[1]; VSQUERYREMOVEFILERESULTS[] rgResultsDel = new VSQUERYREMOVEFILERESULTS[1]; result = target.OnQueryRemoveFiles(project as IVsProject, 1, new string[] { newName }, null, pSummaryResultDel, rgResultsDel); Assert.AreEqual<int>(VSConstants.S_OK, result); Assert.AreEqual<VSQUERYREMOVEFILERESULTS>(VSQUERYREMOVEFILERESULTS.VSQUERYREMOVEFILERESULTS_RemoveNotOK, pSummaryResultDel[0]); // Mock the UIShell service to answer Yes to the dialog invocation serviceProvider.RemoveService(typeof(IVsUIShell)); mockUIShell = MockUiShellProvider.GetShowMessageBoxYes(); serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true); // Try to delete the file from project; the delete should be allowed this time result = target.OnQueryRemoveFiles(project as IVsProject, 1, new string[] { newName }, null, pSummaryResultDel, rgResultsDel); Assert.AreEqual<int>(VSConstants.S_OK, result); Assert.AreEqual<VSQUERYREMOVEFILERESULTS>(VSQUERYREMOVEFILERESULTS.VSQUERYREMOVEFILERESULTS_RemoveOK, pSummaryResultDel[0]); // Remove the file from project project.RemoveItem(newName); result = target.OnAfterRemoveFiles(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { newName }, null); Assert.AreEqual<int>(VSConstants.E_NOTIMPL, result); }