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

Commit 2cfe748

Browse files
committed
[IDE] allow delete missing files from project
- After a file is deleted from Finder outside VS Mac, right click on the file will show "Remove" instead of "Delete" and a dialog will confirm user's choice to remove the file and its child from the project. If any child exists, it will be removed (not deleted) (Should we directly delete the child?) Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1051207
1 parent eaa320b commit 2cfe748

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -285,35 +285,34 @@ 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-
293+
string behavior = fileExists ? "delete" : "remove";
296294
if (hasChildren) {
297295
if (files.Count == 1)
298-
question = GettextCatalog.GetString ("Are you sure you want to delete the file {0} and " +
299-
"its code-behind children from project {1}?",
300-
Path.GetFileName (files [0].Name), files [0].Project.Name);
296+
question = GettextCatalog.GetString ("Are you sure you want to {0} the file {1} and " +
297+
"its code-behind children from project {2}?",
298+
behavior, Path.GetFileName (files [0].Name), files [0].Project.Name);
301299
else
302-
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files and " +
303-
"their code-behind children from the project?");
300+
question = GettextCatalog.GetString ("Are you sure you want to {0} the selected files and " +
301+
"their code-behind children from the project?", behavior);
304302
} else {
305303
if (files.Count == 1)
306-
question = GettextCatalog.GetString ("Are you sure you want to delete file {0} from project {1}?",
307-
Path.GetFileName (files [0].Name), files [0].Project.Name);
304+
question = GettextCatalog.GetString ("Are you sure you want to {0} file {1} from project {2}?",
305+
behavior, Path.GetFileName (files [0].Name), files [0].Project.Name);
308306
else
309-
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files from the project?");
307+
question = GettextCatalog.GetString ("Are you sure you want to {0} the selected files from the project?", behavior);
310308
}
311-
312-
var result = MessageService.AskQuestion (question, GetDeleteConfirmationButtons (filesExist));
313-
if (result != AlertButton.Delete)
314-
return;
315309

316-
RemoveFilesFromProject (true, files);
310+
var result = MessageService.AskQuestion (question, new [] { AlertButton.Cancel, fileExists ? AlertButton.Delete : AlertButton.Remove });
311+
312+
if(result == AlertButton.Cancel)
313+
return;
314+
else
315+
RemoveFilesFromProject (fileExists, files);
317316
}
318317

319318
IdeApp.ProjectOperations.SaveAsync (projects);
@@ -323,18 +322,13 @@ public override void DeleteMultipleItems ()
323322
[AllowMultiSelection]
324323
void OnUpdateDeleteMultipleItems (CommandInfo info)
325324
{
325+
var files = new List<ProjectFile> ();
326326
foreach (var node in CurrentNodes) {
327327
var pf = (ProjectFile)node.DataItem;
328-
if (pf.IsLink)
329-
info.Text = GettextCatalog.GetString ("Remove");
328+
files.Add (pf);
330329
}
331-
}
332-
333-
static AlertButton [] GetDeleteConfirmationButtons (bool includeDelete)
334-
{
335-
if (includeDelete)
336-
return new [] { AlertButton.Cancel, AlertButton.Delete };
337-
return new [] { AlertButton.Cancel };
330+
if( !CheckAnyFileExists(files) )
331+
info.Text = GettextCatalog.GetString ("Remove");
338332
}
339333

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

380374
// Delete file before removing them from the project to avoid Remove items being added
381375
// if the project is currently being saved in memory or to disk.
382-
if (delete && !file.IsLink)
376+
if (delete && !file.IsLink && File.Exists (file.Name))
383377
FileService.DeleteFile (file.Name);
384378
project.Files.Remove (file);
385379
}

0 commit comments

Comments
 (0)