Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit ac34839

Browse files
authored
Merge pull request #9548 from mono/vsts-1051207-delete-missing-file
[IDE] Allow deleting missing files from project
2 parents d184f32 + af3064e commit ac34839

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -285,35 +285,51 @@ public override void DeleteMultipleItems ()
285285
}
286286

287287
string question;
288-
bool allLinkedFiles = CheckAllLinkedFile (files);
288+
bool fileExists = CheckAnyFileExists(files);
289289

290-
if (allLinkedFiles) {
290+
if (CheckAllLinkedFile (files)) {
291291
RemoveFilesFromProject (false, files);
292292
} else {
293-
294-
bool filesExist = CheckAnyFileExists (files);
295-
296293
if (hasChildren) {
297-
if (files.Count == 1)
298-
question = GettextCatalog.GetString ("Are you sure you want to delete the file {0} and " +
294+
if (files.Count == 1) {
295+
if (fileExists)
296+
question = GettextCatalog.GetString ("Are you sure you want to delete the file {0} and " +
297+
"its code-behind children from project {1}?",
298+
Path.GetFileName (files [0].Name), files [0].Project.Name);
299+
else
300+
question = GettextCatalog.GetString ("Are you sure you want to remove the file {0} and " +
299301
"its code-behind children from project {1}?",
300302
Path.GetFileName (files [0].Name), files [0].Project.Name);
301-
else
302-
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files and " +
303+
} else {
304+
if (fileExists)
305+
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files and " +
303306
"their code-behind children from the project?");
307+
else
308+
question = GettextCatalog.GetString ("Are you sure you want to remove the selected files and " +
309+
"their code-behind children from the project?");
310+
}
304311
} else {
305-
if (files.Count == 1)
306-
question = GettextCatalog.GetString ("Are you sure you want to delete file {0} from project {1}?",
312+
if (files.Count == 1) {
313+
if (fileExists)
314+
question = GettextCatalog.GetString ("Are you sure you want to delete file {0} from project {1}?",
307315
Path.GetFileName (files [0].Name), files [0].Project.Name);
308-
else
309-
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files from the project?");
316+
else
317+
question = GettextCatalog.GetString ("Are you sure you want to remove file {0} from project {1}?",
318+
Path.GetFileName (files [0].Name), files [0].Project.Name);
319+
320+
} else {
321+
if (fileExists)
322+
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files from the project?");
323+
else
324+
question = GettextCatalog.GetString ("Are you sure you want to remove the selected files from the project?");
325+
}
310326
}
311-
312-
var result = MessageService.AskQuestion (question, GetDeleteConfirmationButtons (filesExist));
313-
if (result != AlertButton.Delete)
314-
return;
315327

316-
RemoveFilesFromProject (true, files);
328+
var result = MessageService.AskQuestion (question, new [] { AlertButton.Cancel, fileExists ? AlertButton.Delete : AlertButton.Remove });
329+
if (result == AlertButton.Cancel)
330+
return;
331+
else
332+
RemoveFilesFromProject (fileExists, files);
317333
}
318334

319335
IdeApp.ProjectOperations.SaveAsync (projects);
@@ -323,18 +339,13 @@ public override void DeleteMultipleItems ()
323339
[AllowMultiSelection]
324340
void OnUpdateDeleteMultipleItems (CommandInfo info)
325341
{
342+
var files = new List<ProjectFile> ();
326343
foreach (var node in CurrentNodes) {
327344
var pf = (ProjectFile)node.DataItem;
328-
if (pf.IsLink)
329-
info.Text = GettextCatalog.GetString ("Remove");
345+
files.Add (pf);
330346
}
331-
}
332-
333-
static AlertButton [] GetDeleteConfirmationButtons (bool includeDelete)
334-
{
335-
if (includeDelete)
336-
return new [] { AlertButton.Cancel, AlertButton.Delete };
337-
return new [] { AlertButton.Cancel };
347+
if (!CheckAnyFileExists(files))
348+
info.Text = GettextCatalog.GetString ("Remove");
338349
}
339350

340351
[CommandHandler (ProjectCommands.ExcludeFromProject)]
@@ -379,7 +390,7 @@ public void RemoveFilesFromProject (bool delete, List<ProjectFile> files)
379390

380391
// Delete file before removing them from the project to avoid Remove items being added
381392
// if the project is currently being saved in memory or to disk.
382-
if (delete && !file.IsLink)
393+
if (delete && !file.IsLink && File.Exists (file.Name))
383394
FileService.DeleteFile (file.Name);
384395
project.Files.Remove (file);
385396
}

0 commit comments

Comments
 (0)