Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
208 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Rubberduck.Interaction; | ||
using Rubberduck.Navigation.CodeExplorer; | ||
using Rubberduck.VBEditor.ComManagement; | ||
using Rubberduck.VBEditor.SafeComWrappers; | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.UI.CodeExplorer.Commands | ||
{ | ||
public class DeleteCommand : CodeExplorerCommandBase | ||
{ | ||
public DeleteCommand() | ||
private readonly RemoveCommand _removeCommand; | ||
private readonly IProjectsRepository _projectsRepository; | ||
private readonly IMessageBox _messageBox; | ||
private readonly IVBE _vbe; | ||
|
||
public DeleteCommand(RemoveCommand removeCommand, IProjectsRepository projectsRepository, IMessageBox messageBox, IVBE vbe) | ||
{ | ||
// TODO | ||
_removeCommand = removeCommand; | ||
_projectsRepository = projectsRepository; | ||
_messageBox = messageBox; | ||
_vbe = vbe; | ||
|
||
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute); | ||
} | ||
|
||
private bool SpecialEvaluateCanExecute(object parameter) | ||
{ | ||
return _vbe.Kind == VBEKind.Standalone && | ||
_removeCommand.CanExecute(parameter); | ||
} | ||
|
||
protected override void OnExecute(object parameter) | ||
{ | ||
// TODO | ||
if (!(parameter is CodeExplorerComponentViewModel node) || node.Declaration is null) | ||
{ | ||
return; | ||
} | ||
|
||
var qualifiedModuleName = node.Declaration.QualifiedName.QualifiedModuleName; | ||
var component = _projectsRepository.Component(qualifiedModuleName); | ||
if (component is null) | ||
{ | ||
return; | ||
} | ||
|
||
// Permanent operation, prompt for confirm | ||
var message = string.Format(Resources.CodeExplorer.CodeExplorerUI.ConfirmBeforeDelete_Prompt, qualifiedModuleName.Name); | ||
if (!_messageBox.ConfirmYesNo(message, Resources.CodeExplorer.CodeExplorerUI.ConfirmBeforeDelete_Caption)) | ||
{ | ||
return; | ||
} | ||
|
||
// Have to build the file list *before* removing the component! | ||
var files = new List<string>(); | ||
for (short i = 1; i <= component.FileCount; i++) | ||
{ | ||
var fileName = component.GetFileName(i); | ||
if (fileName != null) // Unsaved components have a null filename for some reason | ||
{ | ||
files.Add(component.GetFileName(i)); | ||
} | ||
} | ||
|
||
if (!_removeCommand.RemoveComponent(qualifiedModuleName, false)) | ||
{ | ||
return; // Remove was cancelled or failed | ||
} | ||
|
||
var failedDeletions = new List<string>(); | ||
foreach (var file in files) | ||
{ | ||
try | ||
{ | ||
File.Delete(file); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Logger.Error(exception, "Failed to delete file"); | ||
failedDeletions.Add(file); | ||
} | ||
} | ||
|
||
// Let the user know if there are any component files left on disk | ||
if (failedDeletions.Any()) | ||
{ | ||
message = string.Format(Resources.CodeExplorer.CodeExplorerUI.DeleteFailed_Message, string.Join(Environment.NewLine, failedDeletions)); | ||
_messageBox.NotifyWarn(message, Resources.CodeExplorer.CodeExplorerUI.DeleteFailed_Caption); | ||
} | ||
|
||
} | ||
|
||
public override IEnumerable<Type> ApplicableNodeTypes => new List<Type>(); // TODO!! | ||
public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) }; | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
Rubberduck.Core/UI/CodeExplorer/Commands/ExcludeCommand.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.