diff options
author | Michael Hutchinson <mhutchinson@novell.com> | 2010-12-21 06:56:59 +0300 |
---|---|---|
committer | Michael Hutchinson <mhutchinson@novell.com> | 2010-12-21 06:56:59 +0300 |
commit | 0a452e368063e18765e556895d8d9959150e8491 (patch) | |
tree | 45deb469dee5916f6e1a699edae068e58a6b8131 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs | |
parent | 743032e1b568a3b441ad8e745b8b006491f55244 (diff) |
[Ide] User choice between removing or deleting folders
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs | 99 |
1 files changed, 65 insertions, 34 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs index bc8a1a469a..76a655e744 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFolderNodeBuilder.cs @@ -106,12 +106,16 @@ namespace MonoDevelop.Ide.Gui.Pads.ProjectPad void OnFolderRemoved (object sender, FileEventArgs e) { - ITreeBuilder tb = Context.GetTreeBuilder (sender); - if (tb != null) { - if (!tb.HasChildren()) - tb.Remove (); - else - tb.UpdateAll (); + var tb = Context.GetTreeBuilder (sender); + if (tb == null) + return; + if (!tb.HasChildren ()) { + tb.Remove (); + } else { + //this may have been removed but HasChildren could still be false, not sure why + //but fully updating the parent's children works + tb.MoveToParent (); + tb.UpdateChildren (); } } @@ -167,55 +171,82 @@ namespace MonoDevelop.Ide.Gui.Pads.ProjectPad public override void DeleteMultipleItems () { - var projects = new HashSet<SolutionEntityItem> (); - - var confirmMsg = new ConfirmationMessage () { - ConfirmButton = AlertButton.Delete, - AllowApplyToAll = CurrentNodes.Length > 1, + var projects = new Set<SolutionEntityItem> (); + var folders = new List<ProjectFolder> (); + foreach (ITreeNavigator node in CurrentNodes) + folders.Add ((ProjectFolder) node.DataItem); + + var removeButton = new AlertButton (GettextCatalog.GetString ("_Remove from Project"), Gtk.Stock.Remove); + var question = new QuestionMessage () { + AllowApplyToAll = folders.Count > 1, + SecondaryText = GettextCatalog.GetString ( + "The Delete option permanently removes the directory and any files it contains from your hard disk. " + + "Click Remove from Project if you only want to remove it from your current solution.") }; - - foreach (ITreeNavigator node in CurrentNodes) { - var folder = node.DataItem as ProjectFolder; + question.Buttons.Add (AlertButton.Cancel); + question.Buttons.Add (AlertButton.Delete); + question.Buttons.Add (removeButton); + + foreach (var folder in folders) { var project = folder.Project; - confirmMsg.Text = GettextCatalog.GetString ("Are you sure you want to permanently delete folder {0}?", folder.Path); - if (!MessageService.Confirm (confirmMsg)) - continue; - var folderRelativePath = folder.Path.ToRelative (project.BaseDirectory); - var files = project.Files.GetFilesInVirtualPath (folder.Path).ToList (); + var files = project.Files.GetFilesInVirtualPath (folderRelativePath).ToList (); var folderPf = project.Files.GetFileWithVirtualPath (folderRelativePath); - - try { - if (Directory.Exists (folder.Path)) - // Indirect events will remove the files from the project - FileService.DeleteDirectory (folder.Path); - } catch (Exception ex) { - MessageService.ShowError (GettextCatalog.GetString ("The folder {0} could not be deleted from disk: {1}", folder.Path, ex.Message)); - } - - // even if we removed the directory successfully there may still be link files - // so make sure we remove all the files + + //if the parent directory has already been removed, there may be nothing to do + if (files.Count == 0 && folderPf == null) + continue; + + question.Text = GettextCatalog.GetString ("Are you sure you want to remove directory {0} from project {1}?", + folder.Name, project.Name); + var result = MessageService.AskQuestion (question); + if (result != removeButton && result != AlertButton.Delete) + break; + + projects.Add (project); + + //remove the files and link files in the directory foreach (var f in files) project.Files.Remove (f); - + // also remove the folder's own ProjectFile, if it exists + // FIXME: it probably was already in the files list if (folderPf != null) project.Files.Remove (folderPf); + + if (result == AlertButton.Delete) { + try { + if (Directory.Exists (folder.Path)) + // FileService events should remove remaining files from the project + FileService.DeleteDirectory (folder.Path); + } catch (Exception ex) { + MessageService.ShowError (GettextCatalog.GetString ( + "The folder {0} could not be deleted from disk: {1}", folder.Path, ex.Message)); + } + } else { + //explictly remove the node from the tree, since it currently only tracks real folder deletions + folder.Remove (); + } // If it's the last item in the parent folder, make sure we keep a reference to the parent // folder, so it is not deleted from the tree. var inParentFolder = project.Files.GetFilesInVirtualPath (folderRelativePath.ParentDirectory); - if (!inParentFolder.Skip (1).Any()) { + if (!inParentFolder.Skip (1).Any ()) { project.Files.Add (new ProjectFile (folder.Path.ParentDirectory) { Subtype = Subtype.Directory, }); } - - projects.Add (project); } IdeApp.ProjectOperations.Save (projects); } + + [CommandUpdateHandler (EditCommands.Delete)] + public void UpdateRemoveItem (CommandInfo info) + { + info.Enabled = CanDeleteMultipleItems (); + info.Text = GettextCatalog.GetString ("Remove"); + } [CommandHandler (ProjectCommands.IncludeToProject)] [AllowMultiSelection] |