Skip to content

Commit e9d4b65

Browse files
authored
Merge pull request #5026 from mansellan/5008
Change Import... to Add -> Existing file...
2 parents d871ac0 + 50acb10 commit e9d4b65

File tree

4 files changed

+76
-60
lines changed

4 files changed

+76
-60
lines changed

Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
6565

6666
<CompositeCollection x:Key="AddModuleCommands">
67+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddExistingFileText}"
68+
Command="{Binding ImportCommand}"
69+
CommandParameter="{Binding SelectedItem, Mode=OneWay}">
70+
71+
</MenuItem>
72+
<Separator />
6773
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddVBFormText}"
6874
Command="{Binding AddVBFormCommand}"
6975
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
@@ -453,57 +459,53 @@
453459
<Image Source="{StaticResource AddModuleImage}" />
454460
</MenuItem.Icon>
455461
</MenuItem>
462+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Export}"
463+
Command="{Binding ExportCommand}"
464+
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
465+
Visibility="{Binding ExportVisibility}" />
466+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_ExportAll}"
467+
Command="{Binding ExportAllCommand}"
468+
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
469+
Visibility="{Binding ExportAllVisibility}" />
470+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Remove}"
471+
Command="{Binding RemoveCommand}"
472+
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
473+
Visibility="{Binding VBAVisibility}">
474+
<MenuItem.Icon>
475+
<Image Source="{StaticResource RemoveImage}" Style="{StaticResource ToolbarImageOpacity}" />
476+
</MenuItem.Icon>
477+
</MenuItem>
478+
<Separator />
456479
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=Find}">
457480
<MenuItem.Icon>
458481
<Image Source="{StaticResource FindImage}" />
459482
</MenuItem.Icon>
460483
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_FindAllReferencesText}"
461-
Command="{Binding FindAllReferencesCommand}"
462-
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
484+
Command="{Binding FindAllReferencesCommand}"
485+
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
463486
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_FindAllImplementationsText}"
464-
Command="{Binding FindAllImplementationsCommand}"
465-
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
487+
Command="{Binding FindAllImplementationsCommand}"
488+
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
466489
</MenuItem>
467490
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Indent}"
468-
Command="{Binding IndenterCommand}"
469-
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
491+
Command="{Binding IndenterCommand}"
492+
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
470493
<Separator />
471-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_CollapseSubnodesToolTip}"
472-
Command="{Binding CollapseAllSubnodesCommand}"
473-
CommandParameter="{Binding SelectedItem, Mode=OneWay}">
474-
<MenuItem.Icon>
475-
<Image Source="{StaticResource CollapseNodesImage}" />
476-
</MenuItem.Icon>
477-
</MenuItem>
478494
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_ExpandSubnodesToolTip}"
479-
Command="{Binding ExpandAllSubnodesCommand}"
480-
CommandParameter="{Binding SelectedItem, Mode=OneWay}">
495+
Command="{Binding ExpandAllSubnodesCommand}"
496+
CommandParameter="{Binding SelectedItem, Mode=OneWay}">
481497
<MenuItem.Icon>
482498
<Image Source="{StaticResource ExpandNodesImage}" />
483499
</MenuItem.Icon>
484500
</MenuItem>
485-
<Separator />
486-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Import}"
487-
Command="{Binding ImportCommand}"
488-
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
489-
Visibility="{Binding VBAVisibility}" />
490-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Export}"
491-
Command="{Binding ExportCommand}"
492-
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
493-
Visibility="{Binding ExportVisibility}" />
494-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_ExportAll}"
495-
Command="{Binding ExportAllCommand}"
496-
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
497-
Visibility="{Binding ExportAllVisibility}" />
498-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Remove}"
499-
Command="{Binding RemoveCommand}"
500-
CommandParameter="{Binding SelectedItem, Mode=OneWay}"
501-
Visibility="{Binding VBAVisibility}">
501+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_CollapseSubnodesToolTip}"
502+
Command="{Binding CollapseAllSubnodesCommand}"
503+
CommandParameter="{Binding SelectedItem, Mode=OneWay}">
502504
<MenuItem.Icon>
503-
<Image Source="{StaticResource RemoveImage}" Style="{StaticResource ToolbarImageOpacity}" />
505+
<Image Source="{StaticResource CollapseNodesImage}" />
504506
</MenuItem.Icon>
505507
</MenuItem>
506-
<Separator Visibility="{Binding VBAVisibility}" />
508+
<Separator />
507509
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Print}"
508510
Command="{Binding PrintCommand}"
509511
CommandParameter="{Binding SelectedItem, Mode=OneWay}">
@@ -550,7 +552,7 @@
550552
</MultiBinding.Bindings>
551553
</MultiBinding>
552554
</Image.Source>
553-
</Image>
555+
</Image>
554556
<Image Source="{Binding Declaration, Converter={StaticResource AccessibilityToIcon}}" Style="{StaticResource ToolbarIconStyle}" />
555557
</Grid>
556558
<TextBlock Style="{StaticResource TreeViewItemStyle}" />

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Forms;
55
using Rubberduck.Navigation.CodeExplorer;
66
using Rubberduck.Resources;
7+
using Rubberduck.VBEditor.SafeComWrappers;
78
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
89

910
namespace Rubberduck.UI.CodeExplorer.Commands
@@ -20,12 +21,21 @@ public class ImportCommand : CodeExplorerCommandBase
2021

2122
private readonly IVBE _vbe;
2223
private readonly IFileSystemBrowserFactory _dialogFactory;
24+
private readonly IList<string> _importableExtensions;
25+
private readonly string _filterExtensions;
2326

2427
public ImportCommand(IVBE vbe, IFileSystemBrowserFactory dialogFactory)
2528
{
2629
_vbe = vbe;
2730
_dialogFactory = dialogFactory;
2831

32+
_importableExtensions =
33+
vbe.Kind == VBEKind.Hosted
34+
? new List<string> {"bas", "cls", "frm", "doccls"} // VBA
35+
: new List<string> {"bas", "cls", "frm", "ctl", "pag", "dob"}; // VB6
36+
37+
_filterExtensions = string.Join("; ", _importableExtensions.Select(ext => $"*.{ext}"));
38+
2939
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
3040
}
3141

@@ -44,8 +54,6 @@ private bool ThereIsAValidActiveProject()
4454
}
4555
}
4656

47-
private static readonly List<string> ImportableExtensions = new List<string> { "bas", "cls", "frm" };
48-
4957
protected override void OnExecute(object parameter)
5058
{
5159
if (!CanExecute(parameter))
@@ -79,7 +87,16 @@ protected override void OnExecute(object parameter)
7987

8088
using (var dialog = _dialogFactory.CreateOpenFileDialog())
8189
{
82-
ConfigureOpenDialog(dialog);
90+
dialog.AddExtension = true;
91+
dialog.AutoUpgradeEnabled = true;
92+
dialog.CheckFileExists = true;
93+
dialog.CheckPathExists = true;
94+
dialog.Multiselect = true;
95+
dialog.ShowHelp = false;
96+
dialog.Title = RubberduckUI.ImportCommand_OpenDialog_Title;
97+
dialog.Filter =
98+
$"{RubberduckUI.ImportCommand_OpenDialog_Filter_VBFiles} ({_filterExtensions})|{_filterExtensions}|" +
99+
$"{RubberduckUI.ImportCommand_OpenDialog_Filter_AllFiles}, (*.*)|*.*";
83100

84101
if (project == null || dialog.ShowDialog() != DialogResult.OK)
85102
{
@@ -91,7 +108,7 @@ protected override void OnExecute(object parameter)
91108
}
92109

93110
var fileExists = dialog.FileNames.Select(s => s.Split('.').Last());
94-
if (fileExists.Any(fileExt => !ImportableExtensions.Contains(fileExt)))
111+
if (fileExists.Any(fileExt => !_importableExtensions.Contains(fileExt)))
95112
{
96113
if (usingFreshProjectWrapper)
97114
{
@@ -114,20 +131,5 @@ protected override void OnExecute(object parameter)
114131
project.Dispose();
115132
}
116133
}
117-
118-
private static void ConfigureOpenDialog(IOpenFileDialog dialog)
119-
{
120-
dialog.AddExtension = true;
121-
dialog.AutoUpgradeEnabled = true;
122-
dialog.CheckFileExists = true;
123-
dialog.CheckPathExists = true;
124-
dialog.Multiselect = true;
125-
dialog.ShowHelp = false; // we don't want 1996's file picker.
126-
//TODO - Filter needs descriptions.
127-
dialog.Filter = string.Concat(RubberduckUI.ImportCommand_OpenDialog_Filter_VBFiles,
128-
@" (*.cls, *.bas, *.frm, *.doccls)|*.cls; *.bas; *.frm; *.doccls|",
129-
RubberduckUI.ImportCommand_OpenDialog_Filter_AllFiles, @" (*.*)|*.*");
130-
dialog.Title = RubberduckUI.ImportCommand_OpenDialog_Title;
131-
}
132134
}
133135
}

Rubberduck.Resources/CodeExplorer/CodeExplorerUI.Designer.cs

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/CodeExplorer/CodeExplorerUI.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
<comment>TC</comment>
211211
</data>
212212
<data name="CodeExplorer_AddModule" xml:space="preserve">
213-
<value>Add Module</value>
213+
<value>Add</value>
214214
</data>
215215
<data name="CodeExplorer_AddStdModuleText" xml:space="preserve">
216216
<value>Standard module (.bas)</value>
@@ -225,7 +225,7 @@
225225
<comment>TC</comment>
226226
</data>
227227
<data name="CodeExplorer_CollapseSubnodesToolTip" xml:space="preserve">
228-
<value>Collapse node and all child nodes</value>
228+
<value>Collapse all</value>
229229
</data>
230230
<data name="CodeExplorer_CopyToolTip" xml:space="preserve">
231231
<value>Copy to clipboard</value>
@@ -240,7 +240,7 @@
240240
<value>Display full &amp;signatures</value>
241241
</data>
242242
<data name="CodeExplorer_ExpandSubnodesToolTip" xml:space="preserve">
243-
<value>Expand node and all child nodes</value>
243+
<value>Expand all</value>
244244
</data>
245245
<data name="CodeExplorer_Export" xml:space="preserve">
246246
<value>Export...</value>
@@ -415,4 +415,7 @@
415415
<data name="ObjectTestMethod" type="System.Resources.ResXFileRef, System.Windows.Forms">
416416
<value>..\Icons\Custom\PNG\TestMethod.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
417417
</data>
418+
<data name="CodeExplorer_AddExistingFileText" xml:space="preserve">
419+
<value>Existing file...</value>
420+
</data>
418421
</root>

0 commit comments

Comments
 (0)