From 73720fe798a8d3d711b48213ebf67c1f3ddb5762 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 12 Mar 2006 16:07:55 +0000 Subject: [PATCH] SD2-712 - Adding existing files to a project containing those files already breaks the build. If a file already exists in the MSBuild project it is not added again. User prompted to confirm copy if the files being copied already exist in the destination folder. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1217 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Commands/FolderNodeCommands.cs | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs index cede0dc000..8692097e03 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs @@ -24,6 +24,13 @@ namespace ICSharpCode.SharpDevelop.Project.Commands { public class AddExistingItemsToProject : AbstractMenuCommand { + enum ReplaceExistingFile { + Yes = 0, + YesToAll = 1, + No = 2, + Cancel = 3 + } + int GetFileFilterIndex(IProject project, string[] fileFilters) { if (project != null) { @@ -102,22 +109,21 @@ namespace ICSharpCode.SharpDevelop.Project.Commands string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(fileName)); if (!FileUtility.IsEqualFileName(fileName, copiedFileName)) { File.Copy(fileName, copiedFileName, true); - FileNode newNode = new FileNode(copiedFileName); - newNode.AddTo(node); - if (includeInProject) { - return IncludeFileInProject.IncludeFileNode(newNode); - } - } else if (includeInProject) { + } + if (includeInProject) { FileNode fileNode; foreach (TreeNode childNode in node.AllNodes) { if (childNode is FileNode) { fileNode = (FileNode)childNode; if (FileUtility.IsEqualFileName(fileNode.FileName, copiedFileName)) { - return IncludeFileInProject.IncludeFileNode(fileNode); + if (fileNode.FileNodeStatus == FileNodeStatus.Missing) { + fileNode.FileNodeStatus = FileNodeStatus.InProject; + } + return fileNode.ProjectItem as FileProjectItem; } } } - fileNode = new FileNode(fileName); + fileNode = new FileNode(copiedFileName); fileNode.AddTo(node); return IncludeFileInProject.IncludeFileNode(fileNode); } @@ -208,7 +214,24 @@ namespace ICSharpCode.SharpDevelop.Project.Commands return; } } + bool replaceAll = false; foreach (KeyValuePair pair in fileNames) { + copiedFileName = Path.Combine(node.Directory, Path.GetFileName(pair.Key)); + if (!replaceAll && File.Exists(copiedFileName) && !FileUtility.IsEqualFileName(pair.Key, copiedFileName)) { + ReplaceExistingFile res = (ReplaceExistingFile)MessageService.ShowCustomDialog(fdiag.Title, "A file with the name '" + Path.GetFileName(pair.Key) + "' already exists. Do you want to replace it?", + 0, 3, + "${res:Global.Yes}", + "Yes to All", + "${res:Global.No}", + "${res:Global.CancelButtonText}"); + if (res == ReplaceExistingFile.YesToAll) { + replaceAll = true; + } else if (res == ReplaceExistingFile.No) { + continue; + } else if (res == ReplaceExistingFile.Cancel) { + break; + } + } FileProjectItem item = CopyFile(pair.Key, node, true); if (item != null) { item.DependentUpon = pair.Value;