Skip to content

Commit

Permalink
Changes following PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mansellan committed Jul 25, 2019
1 parent d421173 commit ae447f5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Rubberduck.Core/UI/CodeExplorer/Commands/DeleteCommand.cs
Expand Up @@ -25,7 +25,9 @@ public DeleteCommand(RemoveCommand removeCommand, IProjectsProvider projectsProv
_vbe = vbe;

AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
}
}

public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) };

private bool SpecialEvaluateCanExecute(object parameter)
{
Expand Down Expand Up @@ -79,7 +81,7 @@ protected override void OnExecute(object parameter)
}
catch (Exception exception)
{
Logger.Error(exception, "Failed to delete file");
Logger.Warn(exception, "Failed to delete file");
failedDeletions.Add(file);
}
}
Expand All @@ -92,7 +94,5 @@ protected override void OnExecute(object parameter)
}

}

public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) };
}
}
9 changes: 5 additions & 4 deletions Rubberduck.Core/UI/CodeExplorer/Commands/ExportCommand.cs
Expand Up @@ -36,15 +36,15 @@ public class ExportCommand : CommandBase
};

private readonly IFileSystemBrowserFactory _dialogFactory;
private readonly Dictionary<ComponentType, string> _ExportableFileExtensions;
private readonly Dictionary<ComponentType, string> _exportableFileExtensions;

public ExportCommand(IFileSystemBrowserFactory dialogFactory, IMessageBox messageBox, IProjectsProvider projectsProvider, IVBE vbe)
{
_dialogFactory = dialogFactory;
MessageBox = messageBox;
ProjectsProvider = projectsProvider;

_ExportableFileExtensions =
_exportableFileExtensions =
vbe.Kind == VBEKind.Hosted
? VBAExportableFileExtensions
: VB6ExportableFileExtensions;
Expand All @@ -65,7 +65,7 @@ private bool SpecialEvaluateCanExecute(object parameter)

var componentType = node.Declaration.QualifiedName.QualifiedModuleName.ComponentType;

return _ExportableFileExtensions.Select(s => s.Key).Contains(componentType);
return _exportableFileExtensions.ContainsKey(componentType);
}

protected override void OnExecute(object parameter)
Expand All @@ -81,7 +81,7 @@ protected override void OnExecute(object parameter)

public bool PromptFileNameAndExport(QualifiedModuleName qualifiedModule)
{
if (!_ExportableFileExtensions.TryGetValue(qualifiedModule.ComponentType, out var extension))
if (!_exportableFileExtensions.TryGetValue(qualifiedModule.ComponentType, out var extension))
{
return false;
}
Expand All @@ -104,6 +104,7 @@ public bool PromptFileNameAndExport(QualifiedModuleName qualifiedModule)
}
catch (Exception ex)
{
Logger.Warn(ex, $"Failed to export component {qualifiedModule.Name}");
MessageBox.NotifyWarn(ex.Message, string.Format(Resources.CodeExplorer.CodeExplorerUI.ExportError_Caption, qualifiedModule.ComponentName));
}
return true;
Expand Down
10 changes: 7 additions & 3 deletions Rubberduck.Core/UI/CodeExplorer/Commands/RemoveCommand.cs
@@ -1,16 +1,16 @@
using System;
using System.Collections.Generic;
using Rubberduck.Interaction;
using Rubberduck.Navigation.CodeExplorer;
using Rubberduck.Resources.CodeExplorer;
using Rubberduck.UI.Command;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.ComManagement;
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;

namespace Rubberduck.UI.CodeExplorer.Commands
{
public class RemoveCommand : CommandBase
public class RemoveCommand : CodeExplorerCommandBase
{
private readonly ExportCommand _exportCommand;
private readonly IProjectsRepository _projectsRepository;
Expand All @@ -27,6 +27,8 @@ public RemoveCommand(ExportCommand exportCommand, IProjectsRepository projectsRe
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
}

public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) };

private bool SpecialEvaluateCanExecute(object parameter)
{
return _exportCommand.CanExecute(parameter) &&
Expand Down Expand Up @@ -83,17 +85,19 @@ private bool TryExport(QualifiedModuleName qualifiedModuleName)
switch (_messageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, ConfirmationOutcome.Yes))
{
case ConfirmationOutcome.No:
// User elected to remove without export, return success.
return true;

case ConfirmationOutcome.Yes:
if (_exportCommand.PromptFileNameAndExport(qualifiedModuleName))
{
// Export complete
return true;
}
break;
}

return false; // Export cancelled or failed
return false; // Save dialog cancelled or export failed (failures will have already been displayed and logged by this point)
}
}
}
6 changes: 3 additions & 3 deletions Rubberduck.VBEEditor/ComManagement/ProjectsRepository.cs
Expand Up @@ -279,13 +279,13 @@ public void RemoveComponent(QualifiedModuleName qualifiedModuleName)
ExecuteWithinWriteLock(() =>
{
if (!_components.TryGetValue(qualifiedModuleName, out var component) ||
!_componentsCollections.TryGetValue(qualifiedModuleName.ProjectId, out var components))
!_componentsCollections.TryGetValue(qualifiedModuleName.ProjectId, out var componentsCollectionItem))
{
return;
}
_components.Remove(qualifiedModuleName);
components.Remove(component);
_components.Remove(qualifiedModuleName); // Remove our cached copy of the component
componentsCollectionItem.Remove(component); // Remove the actual component from the project
});
}

Expand Down

0 comments on commit ae447f5

Please sign in to comment.