diff options
author | Matt Ward <matt.ward@microsoft.com> | 2020-01-22 12:07:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 12:07:00 +0300 |
commit | ac3483941df21d275fa3a6f46481377c1da079c1 (patch) | |
tree | cd45a96a2d1f083b274fa8d26b5a887ad7e03ca5 | |
parent | d184f327b5ff4069517665a161fa9e48b2e8913d (diff) | |
parent | af3064e73ca918b1b8da2f10ef6340f73277e546 (diff) |
Merge pull request #9548 from mono/vsts-1051207-delete-missing-file
[IDE] Allow deleting missing files from project
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs index 4fe44f4e70..b5d291af29 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs @@ -285,35 +285,51 @@ namespace MonoDevelop.Ide.Gui.Pads.ProjectPad } string question; - bool allLinkedFiles = CheckAllLinkedFile (files); + bool fileExists = CheckAnyFileExists(files); - if (allLinkedFiles) { + if (CheckAllLinkedFile (files)) { RemoveFilesFromProject (false, files); } else { - - bool filesExist = CheckAnyFileExists (files); - if (hasChildren) { - if (files.Count == 1) - question = GettextCatalog.GetString ("Are you sure you want to delete the file {0} and " + + if (files.Count == 1) { + if (fileExists) + question = GettextCatalog.GetString ("Are you sure you want to delete the file {0} and " + + "its code-behind children from project {1}?", + Path.GetFileName (files [0].Name), files [0].Project.Name); + else + question = GettextCatalog.GetString ("Are you sure you want to remove the file {0} and " + "its code-behind children from project {1}?", Path.GetFileName (files [0].Name), files [0].Project.Name); - else - question = GettextCatalog.GetString ("Are you sure you want to delete the selected files and " + + } else { + if (fileExists) + question = GettextCatalog.GetString ("Are you sure you want to delete the selected files and " + "their code-behind children from the project?"); + else + question = GettextCatalog.GetString ("Are you sure you want to remove the selected files and " + + "their code-behind children from the project?"); + } } else { - if (files.Count == 1) - question = GettextCatalog.GetString ("Are you sure you want to delete file {0} from project {1}?", + if (files.Count == 1) { + if (fileExists) + question = GettextCatalog.GetString ("Are you sure you want to delete file {0} from project {1}?", Path.GetFileName (files [0].Name), files [0].Project.Name); - else - question = GettextCatalog.GetString ("Are you sure you want to delete the selected files from the project?"); + else + question = GettextCatalog.GetString ("Are you sure you want to remove file {0} from project {1}?", + Path.GetFileName (files [0].Name), files [0].Project.Name); + + } else { + if (fileExists) + question = GettextCatalog.GetString ("Are you sure you want to delete the selected files from the project?"); + else + question = GettextCatalog.GetString ("Are you sure you want to remove the selected files from the project?"); + } } - - var result = MessageService.AskQuestion (question, GetDeleteConfirmationButtons (filesExist)); - if (result != AlertButton.Delete) - return; - RemoveFilesFromProject (true, files); + var result = MessageService.AskQuestion (question, new [] { AlertButton.Cancel, fileExists ? AlertButton.Delete : AlertButton.Remove }); + if (result == AlertButton.Cancel) + return; + else + RemoveFilesFromProject (fileExists, files); } IdeApp.ProjectOperations.SaveAsync (projects); @@ -323,18 +339,13 @@ namespace MonoDevelop.Ide.Gui.Pads.ProjectPad [AllowMultiSelection] void OnUpdateDeleteMultipleItems (CommandInfo info) { + var files = new List<ProjectFile> (); foreach (var node in CurrentNodes) { var pf = (ProjectFile)node.DataItem; - if (pf.IsLink) - info.Text = GettextCatalog.GetString ("Remove"); + files.Add (pf); } - } - - static AlertButton [] GetDeleteConfirmationButtons (bool includeDelete) - { - if (includeDelete) - return new [] { AlertButton.Cancel, AlertButton.Delete }; - return new [] { AlertButton.Cancel }; + if (!CheckAnyFileExists(files)) + info.Text = GettextCatalog.GetString ("Remove"); } [CommandHandler (ProjectCommands.ExcludeFromProject)] @@ -379,7 +390,7 @@ namespace MonoDevelop.Ide.Gui.Pads.ProjectPad // Delete file before removing them from the project to avoid Remove items being added // if the project is currently being saved in memory or to disk. - if (delete && !file.IsLink) + if (delete && !file.IsLink && File.Exists (file.Name)) FileService.DeleteFile (file.Name); project.Files.Remove (file); } |