@@ -35,7 +35,7 @@ public class ImportCommand : CodeExplorerCommandBase
35
35
private readonly IParseManager _parseManager ;
36
36
private readonly IProjectsProvider _projectsProvider ;
37
37
private readonly IModuleNameFromFileExtractor _moduleNameFromFileExtractor ;
38
- private readonly IDictionary < ComponentType , IRequiredBinaryFilesFromFileNameExtractor > _binaryFileExtractors ;
38
+ private readonly IDictionary < ComponentType , List < IRequiredBinaryFilesFromFileNameExtractor > > _binaryFileExtractors ;
39
39
private readonly IFileExistenceChecker _fileExistenceChecker ;
40
40
41
41
protected readonly IDeclarationFinderProvider DeclarationFinderProvider ;
@@ -58,13 +58,13 @@ public ImportCommand(
58
58
_dialogFactory = dialogFactory ;
59
59
_parseManager = parseManager ;
60
60
_projectsProvider = projectsProvider ;
61
- DeclarationFinderProvider = declarationFinderProvider ;
62
61
_moduleNameFromFileExtractor = moduleNameFromFileExtractor ;
63
62
_fileExistenceChecker = fileExistenceChecker ;
64
63
65
64
_binaryFileExtractors = BinaryFileExtractors ( binaryFileExtractors ) ;
66
65
67
66
MessageBox = messageBox ;
67
+ DeclarationFinderProvider = declarationFinderProvider ;
68
68
69
69
AddToCanExecuteEvaluation ( SpecialEvaluateCanExecute ) ;
70
70
@@ -123,19 +123,19 @@ private IVBProject TargetProjectFromVbe()
123
123
: null ;
124
124
}
125
125
126
- private IDictionary < ComponentType , IRequiredBinaryFilesFromFileNameExtractor > BinaryFileExtractors ( IEnumerable < IRequiredBinaryFilesFromFileNameExtractor > extractors )
126
+ private IDictionary < ComponentType , List < IRequiredBinaryFilesFromFileNameExtractor > > BinaryFileExtractors ( IEnumerable < IRequiredBinaryFilesFromFileNameExtractor > extractors )
127
127
{
128
- var dict = new Dictionary < ComponentType , IRequiredBinaryFilesFromFileNameExtractor > ( ) ;
128
+ var dict = new Dictionary < ComponentType , List < IRequiredBinaryFilesFromFileNameExtractor > > ( ) ;
129
129
foreach ( var extractor in extractors )
130
130
{
131
131
foreach ( var componentType in extractor . SupportedComponentTypes )
132
- {
133
- if ( dict . ContainsKey ( componentType ) )
132
+ {
133
+ if ( ! dict . ContainsKey ( componentType ) )
134
134
{
135
- continue ;
135
+ dict . Add ( componentType , new List < IRequiredBinaryFilesFromFileNameExtractor > ( ) ) ;
136
136
}
137
137
138
- dict . Add ( componentType , extractor ) ;
138
+ dict [ componentType ] . Add ( extractor ) ;
139
139
}
140
140
}
141
141
@@ -164,8 +164,7 @@ protected virtual ICollection<string> FilesToImport(object parameter)
164
164
165
165
var fileNames = dialog . FileNames ;
166
166
var fileExtensions = fileNames . Select ( Path . GetExtension ) ;
167
- var importableExtensions = ImportableExtensions ;
168
- if ( fileExtensions . Any ( fileExt => ! importableExtensions . Contains ( fileExt ) ) )
167
+ if ( fileExtensions . Any ( fileExt => ! ImportableExtensions . Contains ( fileExt ) ) )
169
168
{
170
169
NotifyUserAboutAbortDueToUnsupportedFileExtensions ( fileNames ) ;
171
170
return new List < string > ( ) ;
@@ -177,6 +176,7 @@ protected virtual ICollection<string> FilesToImport(object parameter)
177
176
178
177
protected virtual string DialogsTitle => RubberduckUI . ImportCommand_OpenDialog_Title ;
179
178
179
+ //TODO: Gather all conflicts and report them in one error dialog instead of reporting them one at a time.
180
180
private void NotifyUserAboutAbortDueToUnsupportedFileExtensions ( IEnumerable < string > fileNames )
181
181
{
182
182
var firstUnsupportedFile = fileNames . First ( filename => ! ImportableExtensions . Contains ( Path . GetExtension ( filename ) ) ) ;
@@ -193,6 +193,7 @@ private void ImportFilesWithSuspension(ICollection<string> filesToImport, IVBPro
193
193
{
194
194
if ( suspendOutcome == SuspensionOutcome . UnexpectedError || suspendOutcome == SuspensionOutcome . Canceled )
195
195
{
196
+ //This rethrows the exception with the original stack trace.
196
197
ExceptionDispatchInfo . Capture ( suspendResult . EncounteredException ) . Throw ( ) ;
197
198
return ;
198
199
}
@@ -382,16 +383,19 @@ private Dictionary<string, ICollection<string>> RequiredBinaryFiles(ICollection<
382
383
private ICollection < string > RequiredBinaryFiles ( string filename )
383
384
{
384
385
var extension = Path . GetExtension ( filename ) ;
385
- if ( ! ComponentTypesForExtension . TryGetValue ( extension , out var componentTypes ) )
386
+ if ( extension == null || ! ComponentTypesForExtension . TryGetValue ( extension , out var componentTypes ) )
386
387
{
387
388
return new List < string > ( ) ;
388
389
}
389
390
390
391
foreach ( var componentType in componentTypes )
391
392
{
392
- if ( _binaryFileExtractors . TryGetValue ( componentType , out var binaryExtractor ) )
393
+ if ( _binaryFileExtractors . TryGetValue ( componentType , out var binaryExtractors ) )
393
394
{
394
- return binaryExtractor . RequiredBinaryFiles ( filename , componentType ) ;
395
+ return binaryExtractors
396
+ . SelectMany ( binaryExtractor => binaryExtractor
397
+ . RequiredBinaryFiles ( filename , componentType ) )
398
+ . ToHashSet ( ) ;
395
399
}
396
400
}
397
401
@@ -523,8 +527,8 @@ protected override void OnExecute(object parameter)
523
527
}
524
528
525
529
526
- //We only allow extensions to be imported for which we might be able to determine that the conditions are met to actually import the file.
527
- //The exception are specif exceptions to the rule.
530
+ //We usually only allow extensions to be imported for which we might be able to determine that the conditions are met to actually import the file.
531
+ //However, we ignore this cautionary rule for the extensions specified in AlwaysImportableExtensions;
528
532
protected ICollection < string > ImportableExtensions =>
529
533
ComponentTypesForExtension . Keys
530
534
. Where ( fileExtension => ComponentTypesForExtension . TryGetValue ( fileExtension , out var componentTypes )
@@ -534,6 +538,7 @@ protected override void OnExecute(object parameter)
534
538
. Concat ( AlwaysImportableExtensions )
535
539
. ToHashSet ( ) ;
536
540
541
+ //TODO: Implement the binary extractors necessary to allow us to remove this member.
537
542
protected virtual IEnumerable < string > AlwaysImportableExtensions => _vbe . Kind == VBEKind . Standalone
538
543
? ComponentTypesForExtension . Keys
539
544
: Enumerable . Empty < string > ( ) ;
0 commit comments