1
1
using System . Collections . Generic ;
2
2
using System . Linq ;
3
3
using Rubberduck . Interaction ;
4
+ using Rubberduck . JunkDrawer . Extensions ;
5
+ using Rubberduck . Parsing . Symbols ;
4
6
using Rubberduck . Parsing . VBA ;
5
7
using Rubberduck . Resources ;
8
+ using Rubberduck . VBEditor ;
9
+ using Rubberduck . VBEditor . ComManagement ;
6
10
using Rubberduck . VBEditor . Events ;
7
- using Rubberduck . VBEditor . Extensions ;
8
- using Rubberduck . VBEditor . SafeComWrappers ;
9
11
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
12
+ using Rubberduck . VBEditor . Utility ;
10
13
11
14
namespace Rubberduck . UI . CodeExplorer . Commands
12
15
{
@@ -17,21 +20,28 @@ public ReplaceProjectContentsFromFilesCommand(
17
20
IFileSystemBrowserFactory dialogFactory ,
18
21
IVbeEvents vbeEvents ,
19
22
IParseManager parseManager ,
23
+ IDeclarationFinderProvider declarationFinderProvider ,
24
+ IProjectsProvider projectsProvider ,
25
+ IModuleNameFromFileExtractor moduleNameFromFileExtractor ,
26
+ IEnumerable < IRequiredBinaryFilesFromFileNameExtractor > binaryFileExtractors ,
27
+ IFileExistenceChecker fileExistenceChecker ,
20
28
IMessageBox messageBox )
21
- : base ( vbe , dialogFactory , vbeEvents , parseManager , messageBox )
22
- { }
29
+ : base ( vbe , dialogFactory , vbeEvents , parseManager , declarationFinderProvider , projectsProvider , moduleNameFromFileExtractor , binaryFileExtractors , fileExistenceChecker , messageBox )
30
+ { }
23
31
24
32
protected override string DialogsTitle => RubberduckUI . ReplaceProjectContentsFromFilesCommand_DialogCaption ;
25
33
26
- protected override void ImportFiles ( ICollection < string > filesToImport , IVBProject targetProject )
34
+ protected override ICollection < QualifiedModuleName > ModulesToRemoveBeforeImport ( IDictionary < string , QualifiedModuleName > existingModules )
27
35
{
28
- if ( ! UserConfirmsToReplaceProjectContents ( targetProject ) )
29
- {
30
- return ;
31
- }
36
+ return DeclarationFinderProvider . DeclarationFinder
37
+ . UserDeclarations ( DeclarationType . Module )
38
+ . Select ( decl => decl . QualifiedModuleName )
39
+ . ToHashSet ( ) ;
40
+ }
32
41
33
- RemoveReImportableComponents ( targetProject ) ;
34
- base . ImportFiles ( filesToImport , targetProject ) ;
42
+ protected override bool UserDeniesExecution ( IVBProject targetProject )
43
+ {
44
+ return ! UserConfirmsToReplaceProjectContents ( targetProject ) ;
35
45
}
36
46
37
47
private bool UserConfirmsToReplaceProjectContents ( IVBProject project )
@@ -40,29 +50,5 @@ private bool UserConfirmsToReplaceProjectContents(IVBProject project)
40
50
var message = string . Format ( RubberduckUI . ReplaceProjectContentsFromFilesCommand_DialogCaption , projectName ) ;
41
51
return MessageBox . ConfirmYesNo ( message , DialogsTitle , false ) ;
42
52
}
43
-
44
- private void RemoveReImportableComponents ( IVBProject project )
45
- {
46
- var reImportableComponentTypes = ReImportableComponentTypes ;
47
- using ( var components = project . VBComponents )
48
- {
49
- foreach ( var component in components )
50
- {
51
- using ( component )
52
- {
53
- if ( reImportableComponentTypes . Contains ( component . Type ) )
54
- {
55
- components . Remove ( component ) ;
56
- }
57
- }
58
- }
59
- }
60
- }
61
-
62
- //We currently do not take precautions for component types requiring a binary file to be present.
63
- private ICollection < ComponentType > ReImportableComponentTypes => ComponentTypesForExtension . Values
64
- . SelectMany ( componentTypes => componentTypes )
65
- . Where ( componentType => componentType != ComponentType . Document )
66
- . ToList ( ) ;
67
53
}
68
54
}
0 commit comments