Skip to content

Commit ae447f5

Browse files
committed
Changes following PR comments
1 parent d421173 commit ae447f5

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

Rubberduck.Core/UI/CodeExplorer/Commands/DeleteCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public DeleteCommand(RemoveCommand removeCommand, IProjectsProvider projectsProv
2525
_vbe = vbe;
2626

2727
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
28-
}
28+
}
29+
30+
public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) };
2931

3032
private bool SpecialEvaluateCanExecute(object parameter)
3133
{
@@ -79,7 +81,7 @@ protected override void OnExecute(object parameter)
7981
}
8082
catch (Exception exception)
8183
{
82-
Logger.Error(exception, "Failed to delete file");
84+
Logger.Warn(exception, "Failed to delete file");
8385
failedDeletions.Add(file);
8486
}
8587
}
@@ -92,7 +94,5 @@ protected override void OnExecute(object parameter)
9294
}
9395

9496
}
95-
96-
public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) };
9797
}
9898
}

Rubberduck.Core/UI/CodeExplorer/Commands/ExportCommand.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public class ExportCommand : CommandBase
3636
};
3737

3838
private readonly IFileSystemBrowserFactory _dialogFactory;
39-
private readonly Dictionary<ComponentType, string> _ExportableFileExtensions;
39+
private readonly Dictionary<ComponentType, string> _exportableFileExtensions;
4040

4141
public ExportCommand(IFileSystemBrowserFactory dialogFactory, IMessageBox messageBox, IProjectsProvider projectsProvider, IVBE vbe)
4242
{
4343
_dialogFactory = dialogFactory;
4444
MessageBox = messageBox;
4545
ProjectsProvider = projectsProvider;
4646

47-
_ExportableFileExtensions =
47+
_exportableFileExtensions =
4848
vbe.Kind == VBEKind.Hosted
4949
? VBAExportableFileExtensions
5050
: VB6ExportableFileExtensions;
@@ -65,7 +65,7 @@ private bool SpecialEvaluateCanExecute(object parameter)
6565

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

68-
return _ExportableFileExtensions.Select(s => s.Key).Contains(componentType);
68+
return _exportableFileExtensions.ContainsKey(componentType);
6969
}
7070

7171
protected override void OnExecute(object parameter)
@@ -81,7 +81,7 @@ protected override void OnExecute(object parameter)
8181

8282
public bool PromptFileNameAndExport(QualifiedModuleName qualifiedModule)
8383
{
84-
if (!_ExportableFileExtensions.TryGetValue(qualifiedModule.ComponentType, out var extension))
84+
if (!_exportableFileExtensions.TryGetValue(qualifiedModule.ComponentType, out var extension))
8585
{
8686
return false;
8787
}
@@ -104,6 +104,7 @@ public bool PromptFileNameAndExport(QualifiedModuleName qualifiedModule)
104104
}
105105
catch (Exception ex)
106106
{
107+
Logger.Warn(ex, $"Failed to export component {qualifiedModule.Name}");
107108
MessageBox.NotifyWarn(ex.Message, string.Format(Resources.CodeExplorer.CodeExplorerUI.ExportError_Caption, qualifiedModule.ComponentName));
108109
}
109110
return true;

Rubberduck.Core/UI/CodeExplorer/Commands/RemoveCommand.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
using System;
2+
using System.Collections.Generic;
23
using Rubberduck.Interaction;
34
using Rubberduck.Navigation.CodeExplorer;
45
using Rubberduck.Resources.CodeExplorer;
5-
using Rubberduck.UI.Command;
66
using Rubberduck.VBEditor;
77
using Rubberduck.VBEditor.ComManagement;
88
using Rubberduck.VBEditor.SafeComWrappers;
99
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1010

1111
namespace Rubberduck.UI.CodeExplorer.Commands
1212
{
13-
public class RemoveCommand : CommandBase
13+
public class RemoveCommand : CodeExplorerCommandBase
1414
{
1515
private readonly ExportCommand _exportCommand;
1616
private readonly IProjectsRepository _projectsRepository;
@@ -27,6 +27,8 @@ public RemoveCommand(ExportCommand exportCommand, IProjectsRepository projectsRe
2727
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
2828
}
2929

30+
public override IEnumerable<Type> ApplicableNodeTypes => new List<Type> { typeof(CodeExplorerComponentViewModel) };
31+
3032
private bool SpecialEvaluateCanExecute(object parameter)
3133
{
3234
return _exportCommand.CanExecute(parameter) &&
@@ -83,17 +85,19 @@ private bool TryExport(QualifiedModuleName qualifiedModuleName)
8385
switch (_messageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, ConfirmationOutcome.Yes))
8486
{
8587
case ConfirmationOutcome.No:
88+
// User elected to remove without export, return success.
8689
return true;
8790

8891
case ConfirmationOutcome.Yes:
8992
if (_exportCommand.PromptFileNameAndExport(qualifiedModuleName))
9093
{
94+
// Export complete
9195
return true;
9296
}
9397
break;
9498
}
9599

96-
return false; // Export cancelled or failed
100+
return false; // Save dialog cancelled or export failed (failures will have already been displayed and logged by this point)
97101
}
98102
}
99103
}

Rubberduck.VBEEditor/ComManagement/ProjectsRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ public void RemoveComponent(QualifiedModuleName qualifiedModuleName)
279279
ExecuteWithinWriteLock(() =>
280280
{
281281
if (!_components.TryGetValue(qualifiedModuleName, out var component) ||
282-
!_componentsCollections.TryGetValue(qualifiedModuleName.ProjectId, out var components))
282+
!_componentsCollections.TryGetValue(qualifiedModuleName.ProjectId, out var componentsCollectionItem))
283283
{
284284
return;
285285
}
286286

287-
_components.Remove(qualifiedModuleName);
288-
components.Remove(component);
287+
_components.Remove(qualifiedModuleName); // Remove our cached copy of the component
288+
componentsCollectionItem.Remove(component); // Remove the actual component from the project
289289
});
290290
}
291291

0 commit comments

Comments
 (0)