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

Commit 5c215b0

Browse files
authored
Merge pull request #8913 from mono/vsts-983801-delete-dialog
[IDE] Change the delete dialog
2 parents 93127d9 + 120551b commit 5c215b0

File tree

5 files changed

+128
-58
lines changed

5 files changed

+128
-58
lines changed

main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@
236236
_label = "Project _Options"
237237
_description = "Show project options window" />
238238

239+
<Command id= "MonoDevelop.Ide.Commands.ProjectCommands.ExcludeFromProject"
240+
defaultHandler = "MonoDevelop.Ide.Commands.ExcludeFromProjectHandler"
241+
_label = "Exclude from project"
242+
_description = "Exclude an item from the project" />
239243
<Command id = "MonoDevelop.Ide.Commands.ProjectCommands.AddReference"
240244
_description = "Add and remove project references"
241245
icon = "md-reference"

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/ProjectCommands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public enum ProjectCommands
9393
Unload,
9494
SetStartupProjects,
9595
AddEmptyClass,
96-
ToggleFileNesting
96+
ToggleFileNesting,
97+
ExcludeFromProject
9798
}
9899

99100
internal class SolutionOptionsHandler : CommandHandler

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

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -284,36 +284,58 @@ public override void DeleteMultipleItems ()
284284
files.Add (pf);
285285
}
286286

287-
var removeFromProject = new AlertButton (GettextCatalog.GetString ("_Remove from Project"), Gtk.Stock.Remove);
288287
string question;
289-
string secondaryText = null;
290-
291288
bool filesExist = CheckAnyFileExists (files);
292-
if (filesExist) {
293-
secondaryText = GettextCatalog.GetString ("The Delete option permanently removes the file from your hard disk. " +
294-
"Click Remove from Project if you only want to remove it from your current solution.");
295-
}
296-
289+
297290
if (hasChildren) {
298291
if (files.Count == 1)
299-
question = GettextCatalog.GetString ("Are you sure you want to remove the file {0} and " +
292+
question = GettextCatalog.GetString ("Are you sure you want to delete the file {0} and " +
300293
"its code-behind children from project {1}?",
301294
Path.GetFileName (files[0].Name), files[0].Project.Name);
302295
else
303-
question = GettextCatalog.GetString ("Are you sure you want to remove the selected files and " +
296+
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files and " +
304297
"their code-behind children from the project?");
305298
} else {
306299
if (files.Count == 1)
307-
question = GettextCatalog.GetString ("Are you sure you want to remove file {0} from project {1}?",
300+
question = GettextCatalog.GetString ("Are you sure you want to delete file {0} from project {1}?",
308301
Path.GetFileName (files[0].Name), files[0].Project.Name);
309302
else
310-
question = GettextCatalog.GetString ("Are you sure you want to remove the selected files from the project?");
303+
question = GettextCatalog.GetString ("Are you sure you want to delete the selected files from the project?");
311304
}
312305

313-
var result = MessageService.AskQuestion (question, secondaryText, GetDeleteConfirmationButtons (filesExist, removeFromProject));
314-
if (result != removeFromProject && result != AlertButton.Delete)
306+
var result = MessageService.AskQuestion (question, GetDeleteConfirmationButtons (filesExist));
307+
if (result != AlertButton.Delete)
315308
return;
316309

310+
RemoveFilesFromProject (true, files);
311+
IdeApp.ProjectOperations.SaveAsync (projects);
312+
}
313+
314+
static AlertButton [] GetDeleteConfirmationButtons (bool includeDelete)
315+
{
316+
if (includeDelete)
317+
return new [] { AlertButton.Cancel, AlertButton.Delete };
318+
return new [] { AlertButton.Cancel };
319+
}
320+
321+
[CommandHandler (ProjectCommands.ExcludeFromProject)]
322+
[AllowMultiSelection]
323+
void OnExcludeFilesFromProject ()
324+
{
325+
var projects = new Set<SolutionItem> ();
326+
var files = new List<ProjectFile> ();
327+
328+
foreach (var node in CurrentNodes) {
329+
var pf = (ProjectFile)node.DataItem;
330+
projects.Add (pf.Project);
331+
files.Add (pf);
332+
}
333+
RemoveFilesFromProject (false, files);
334+
IdeApp.ProjectOperations.SaveAsync (projects);
335+
}
336+
337+
public void RemoveFilesFromProject (bool delete, List<ProjectFile> files)
338+
{
317339
foreach (var file in files) {
318340
var project = file.Project;
319341
var inFolder = project.Files.GetFilesInVirtualPath (file.ProjectVirtualPath.ParentDirectory).ToList ();
@@ -330,17 +352,21 @@ public override void DeleteMultipleItems ()
330352
if (children != null) {
331353
foreach (var child in children.ToArray ()) {
332354
project.Files.Remove (child);
333-
if (result == AlertButton.Delete)
355+
if(delete)
334356
FileService.DeleteFile (child.Name);
335357
}
336358
}
337-
359+
338360
project.Files.Remove (file);
339-
if (result == AlertButton.Delete && !file.IsLink)
361+
if (delete && !file.IsLink)
340362
FileService.DeleteFile (file.Name);
341363
}
364+
}
342365

343-
IdeApp.ProjectOperations.SaveAsync (projects);
366+
[CommandUpdateHandler (ProjectCommands.ExcludeFromProject)]
367+
void UpdateExcludeFiles (CommandInfo info)
368+
{
369+
info.Enabled = CanDeleteMultipleItems ();
344370
}
345371

346372
static bool CheckAnyFileExists (IEnumerable<ProjectFile> files)
@@ -360,19 +386,12 @@ static bool CheckAnyFileExists (IEnumerable<ProjectFile> files)
360386
return false;
361387
}
362388

363-
static AlertButton[] GetDeleteConfirmationButtons (bool includeDelete, AlertButton removeFromProject)
364-
{
365-
if (includeDelete)
366-
return new [] { AlertButton.Delete, AlertButton.Cancel, removeFromProject };
367-
return new [] { AlertButton.Cancel, removeFromProject };
368-
}
369-
389+
370390
[CommandUpdateHandler (EditCommands.Delete)]
371391
public void UpdateRemoveItem (CommandInfo info)
372392
{
373393
//don't allow removing children from parents. The parent can be removed and will remove the whole group.
374394
info.Enabled = CanDeleteMultipleItems ();
375-
info.Text = GettextCatalog.GetString ("Remove");
376395
}
377396

378397
[CommandHandler (ViewCommands.OpenWithList)]

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

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -183,64 +183,50 @@ public async override void RenameItem (string newName)
183183
}
184184
}
185185
}
186-
186+
187187
public override void DeleteMultipleItems ()
188188
{
189189
var projects = new Set<SolutionItem> ();
190190
var folders = new List<ProjectFolder> ();
191191
foreach (ITreeNavigator node in CurrentNodes)
192192
folders.Add ((ProjectFolder) node.DataItem);
193193

194-
var removeButton = new AlertButton (GettextCatalog.GetString ("_Remove from Project"), Gtk.Stock.Remove);
195194
var question = new QuestionMessage () {
196-
AllowApplyToAll = folders.Count > 1,
197-
SecondaryText = GettextCatalog.GetString (
198-
"The Delete option permanently removes the directory and any files it contains from your hard disk. " +
199-
"Click Remove from Project if you only want to remove it from your current solution.")
195+
AllowApplyToAll = folders.Count > 1
200196
};
201-
question.Buttons.Add (AlertButton.Delete);
202-
question.Buttons.Add (removeButton);
203197
question.Buttons.Add (AlertButton.Cancel);
198+
question.Buttons.Add (AlertButton.Delete);
204199

205-
var deleteOnlyQuestion = new QuestionMessage () {
206-
AllowApplyToAll = folders.Count > 1,
207-
SecondaryText = GettextCatalog.GetString ("The directory and any files it contains will be permanently removed from your hard disk. ")
208-
};
209-
deleteOnlyQuestion.Buttons.Add (AlertButton.Delete);
210-
deleteOnlyQuestion.Buttons.Add (AlertButton.Cancel);
211-
212200
foreach (var folder in folders) {
213201
var project = folder.Project;
214202

215203
AlertButton result;
216204

217205
if (project == null) {
218-
deleteOnlyQuestion.Text = GettextCatalog.GetString ("Are you sure you want to remove directory {0}?", folder.Name);
219-
result = MessageService.AskQuestion (deleteOnlyQuestion);
206+
question.Text = GettextCatalog.GetString ("Are you sure you want to delete directory {0}?", folder.Name);
207+
result = MessageService.AskQuestion (question);
220208
if (result == AlertButton.Delete) {
221209
DeleteFolder (folder);
222210
continue;
223211
} else
224212
break;
225213
}
226-
227214
var folderRelativePath = folder.Path.ToRelative (project.BaseDirectory);
228215
var files = project.Files.GetFilesInVirtualPath (folderRelativePath).ToList ();
229216
var folderPf = project.Files.GetFileWithVirtualPath (folderRelativePath);
230217
bool isProjectFolder = files.Count == 0 && folderPf == null;
231218

232219
//if the parent directory has already been removed, there may be nothing to do
233220
if (isProjectFolder) {
234-
deleteOnlyQuestion.Text = GettextCatalog.GetString ("Are you sure you want to remove directory {0}?", folder.Name);
235-
result = MessageService.AskQuestion (deleteOnlyQuestion);
236-
if (result != AlertButton.Delete)
221+
question.Text = GettextCatalog.GetString ("Are you sure you want to delete directory {0}?", folder.Name);
222+
result = MessageService.AskQuestion (question);
223+
if (result != AlertButton.Delete)
237224
break;
238-
}
239-
else {
240-
question.Text = GettextCatalog.GetString ("Are you sure you want to remove directory {0} from project {1}?",
225+
} else {
226+
question.Text = GettextCatalog.GetString ("Are you sure you want to delete directory {0} from project {1}?",
241227
folder.Name, project.Name);
242228
result = MessageService.AskQuestion (question);
243-
if (result != removeButton && result != AlertButton.Delete)
229+
if (result != AlertButton.Delete)
244230
break;
245231

246232
projects.Add (project);
@@ -255,13 +241,63 @@ public override void DeleteMultipleItems ()
255241
project.Files.Remove (folderPf);
256242
}
257243

258-
if (result == AlertButton.Delete) {
259-
DeleteFolder (folder);
244+
DeleteFolder (folder);
245+
246+
if (isProjectFolder && folder.Path.ParentDirectory != project.BaseDirectory) {
247+
// If it's the last item in the parent folder, make sure we keep a reference to the parent
248+
// folder, so it is not deleted from the tree.
249+
var inParentFolder = project.Files.GetFilesInVirtualPath (folderRelativePath.ParentDirectory);
250+
if (!inParentFolder.Skip (1).Any ()) {
251+
project.Files.Add (new ProjectFile (folder.Path.ParentDirectory) {
252+
Subtype = Subtype.Directory,
253+
});
254+
}
255+
}
256+
}
257+
IdeApp.ProjectOperations.SaveAsync (projects);
258+
}
259+
260+
[CommandHandler (ProjectCommands.ExcludeFromProject)]
261+
[AllowMultiSelection]
262+
void OnExcludeFoldersFromProject ()
263+
{
264+
var projects = new Set<SolutionItem> ();
265+
var folders = new List<ProjectFolder> ();
266+
foreach (ITreeNavigator node in CurrentNodes)
267+
folders.Add ((ProjectFolder)node.DataItem);
268+
269+
foreach (var folder in folders) {
270+
var project = folder.Project;
271+
272+
AlertButton result;
273+
274+
if (project == null) {
275+
break;
276+
}
277+
278+
var folderRelativePath = folder.Path.ToRelative (project.BaseDirectory);
279+
var files = project.Files.GetFilesInVirtualPath (folderRelativePath).ToList ();
280+
var folderPf = project.Files.GetFileWithVirtualPath (folderRelativePath);
281+
bool isProjectFolder = files.Count == 0 && folderPf == null;
282+
283+
//if the parent directory has already been removed, there may be nothing to do
284+
if (isProjectFolder) {
285+
break;
260286
} else {
261-
//explictly remove the node from the tree, since it currently only tracks real folder deletions
262-
folder.Remove ();
287+
projects.Add (project);
288+
289+
//remove the files and link files in the directory
290+
foreach (var f in files)
291+
project.Files.Remove (f);
292+
293+
// also remove the folder's own ProjectFile, if it exists
294+
// FIXME: it probably was already in the files list
295+
if (folderPf != null)
296+
project.Files.Remove (folderPf);
263297
}
264-
298+
299+
folder.Remove ();
300+
265301
if (isProjectFolder && folder.Path.ParentDirectory != project.BaseDirectory) {
266302
// If it's the last item in the parent folder, make sure we keep a reference to the parent
267303
// folder, so it is not deleted from the tree.
@@ -274,6 +310,13 @@ public override void DeleteMultipleItems ()
274310
}
275311
}
276312
IdeApp.ProjectOperations.SaveAsync (projects);
313+
314+
}
315+
316+
[CommandUpdateHandler (ProjectCommands.ExcludeFromProject)]
317+
void UpdateExcludeFolders (CommandInfo info)
318+
{
319+
info.Enabled = CanDeleteMultipleItems ();
277320
}
278321

279322
static void DeleteFolder (ProjectFolder folder)
@@ -292,7 +335,6 @@ static void DeleteFolder (ProjectFolder folder)
292335
public void UpdateRemoveItem (CommandInfo info)
293336
{
294337
info.Enabled = CanDeleteMultipleItems ();
295-
info.Text = GettextCatalog.GetString ("Remove");
296338
}
297339

298340
[CommandHandler (ProjectCommands.IncludeToProject)]

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectPadContextMenu.addin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
</Condition>
130130
<SeparatorItem id = "ToolsSectionEnd" />
131131

132+
<Condition id="ItemType" value="ProjectFile|ProjectFolder">
133+
<CommandItem id= "MonoDevelop.Ide.Commands.ProjectCommands.ExcludeFromProject" />
134+
</Condition>
135+
132136
<!-- Edit section -->
133137

134138
<SeparatorItem id = "EditSectionStart" />

0 commit comments

Comments
 (0)