@@ -26,8 +26,6 @@ public class ImportCommand : CodeExplorerCommandBase
26
26
27
27
private readonly IVBE _vbe ;
28
28
private readonly IFileSystemBrowserFactory _dialogFactory ;
29
- private readonly IList < string > _importableExtensions ;
30
- private readonly string _filterExtensions ;
31
29
private readonly IParseManager _parseManager ;
32
30
33
31
protected readonly IMessageBox MessageBox ;
@@ -48,10 +46,7 @@ public ImportCommand(
48
46
49
47
AddToCanExecuteEvaluation ( SpecialEvaluateCanExecute ) ;
50
48
51
- ComponentTypeForExtension = ComponentTypeExtensions . ComponentTypeForExtension ( _vbe . Kind ) ;
52
-
53
- _importableExtensions = ComponentTypeForExtension . Keys . ToList ( ) ;
54
- _filterExtensions = string . Join ( "; " , _importableExtensions . Select ( ext => $ "*{ ext } ") ) ;
49
+ ComponentTypesForExtension = ComponentTypeExtensions . ComponentTypesForExtension ( _vbe . Kind ) ;
55
50
56
51
AddToCanExecuteEvaluation ( SpecialEvaluateCanExecute ) ;
57
52
AddToOnExecuteEvaluation ( SpecialEvaluateCanExecute ) ;
@@ -118,7 +113,7 @@ protected virtual ICollection<string> FilesToImport(object parameter)
118
113
dialog . ShowHelp = false ;
119
114
dialog . Title = DialogsTitle ;
120
115
dialog . Filter =
121
- $ "{ RubberduckUI . ImportCommand_OpenDialog_Filter_VBFiles } ({ _filterExtensions } )|{ _filterExtensions } |" +
116
+ $ "{ RubberduckUI . ImportCommand_OpenDialog_Filter_VBFiles } ({ FilterExtension } )|{ FilterExtension } |" +
122
117
$ "{ RubberduckUI . ImportCommand_OpenDialog_Filter_AllFiles } , (*.*)|*.*";
123
118
124
119
if ( dialog . ShowDialog ( ) != DialogResult . OK )
@@ -128,7 +123,8 @@ protected virtual ICollection<string> FilesToImport(object parameter)
128
123
129
124
var fileNames = dialog . FileNames ;
130
125
var fileExtensions = fileNames . Select ( Path . GetExtension ) ;
131
- if ( fileExtensions . Any ( fileExt => ! _importableExtensions . Contains ( fileExt ) ) )
126
+ var importableExtensions = ImportableExtensions ;
127
+ if ( fileExtensions . Any ( fileExt => ! importableExtensions . Contains ( fileExt ) ) )
132
128
{
133
129
NotifyUserAboutAbortDueToUnsupportedFileExtensions ( fileNames ) ;
134
130
return new List < string > ( ) ;
@@ -142,7 +138,7 @@ protected virtual ICollection<string> FilesToImport(object parameter)
142
138
143
139
private void NotifyUserAboutAbortDueToUnsupportedFileExtensions ( IEnumerable < string > fileNames )
144
140
{
145
- var firstUnsupportedFile = fileNames . First ( filename => ! _importableExtensions . Contains ( Path . GetExtension ( filename ) ) ) ;
141
+ var firstUnsupportedFile = fileNames . First ( filename => ! ImportableExtensions . Contains ( Path . GetExtension ( filename ) ) ) ;
146
142
var unsupportedFileName = Path . GetFileName ( firstUnsupportedFile ) ;
147
143
var message = string . Format ( RubberduckUI . ImportCommand_UnsupportedFileExtensions , unsupportedFileName ) ;
148
144
MessageBox . NotifyWarn ( message , DialogsTitle ) ;
@@ -165,8 +161,8 @@ protected virtual void ImportFiles(ICollection<string> filesToImport, IVBProject
165
161
{
166
162
var fileExtension = Path . GetExtension ( filename ) ;
167
163
if ( fileExtension != null
168
- && ComponentTypeForExtension . TryGetValue ( fileExtension , out var componentType )
169
- && componentType == ComponentType . Document )
164
+ && ComponentTypesForExtension . TryGetValue ( fileExtension , out var componentTypes )
165
+ && componentTypes . Contains ( ComponentType . Document ) )
170
166
{
171
167
//We have to dispose the return value.
172
168
using ( components . ImportSourceFile ( filename ) ) { }
@@ -204,6 +200,10 @@ protected override void OnExecute(object parameter)
204
200
}
205
201
}
206
202
207
- protected IDictionary < string , ComponentType > ComponentTypeForExtension { get ; }
203
+ protected virtual ICollection < string > ImportableExtensions => ComponentTypesForExtension . Keys . ToList ( ) ;
204
+
205
+ private string FilterExtension => string . Join ( "; " , ImportableExtensions . Select ( ext => $ "*{ ext } ") ) ;
206
+
207
+ protected IDictionary < string , ICollection < ComponentType > > ComponentTypesForExtension { get ; }
208
208
}
209
209
}
0 commit comments