Skip to content

Commit 08683fc

Browse files
shadowofsiliconretailcoder
authored andcommitted
Adds "Export Active Project" menu item (#3256)
* Introduces ExportAllCommand with default hotkey Ctrl+Shift+E (VBE's own "Export [module]" command is Ctrl+E), to export all modules of the active project into a folder. * Default hotkey for the RefactorEncapsulateField command now defaults to Ctrl+Shift+F (old default was Ctrl+Shift+E). E for Export, F for Field.
1 parent bc4f24b commit 08683fc

File tree

16 files changed

+764
-11
lines changed

16 files changed

+764
-11
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Rubberduck.VBEditor;
1717
using Rubberduck.VBEditor.SafeComWrappers;
1818
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
19+
using System.Windows;
1920

2021
// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
2122

@@ -60,6 +61,8 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
6061

6162
ImportCommand = commands.OfType<ImportCommand>().SingleOrDefault();
6263
ExportCommand = commands.OfType<ExportCommand>().SingleOrDefault();
64+
ExportAllCommand = commands.OfType<Rubberduck.UI.Command.ExportAllCommand>().SingleOrDefault();
65+
6366
_externalRemoveCommand = commands.OfType<RemoveCommand>().SingleOrDefault();
6467
if (_externalRemoveCommand != null)
6568
{
@@ -99,8 +102,10 @@ public CodeExplorerItemViewModel SelectedItem
99102
OnPropertyChanged("CanExecuteIndenterCommand");
100103
OnPropertyChanged("CanExecuteRenameCommand");
101104
OnPropertyChanged("CanExecuteFindAllReferencesCommand");
105+
OnPropertyChanged("CanExecuteExportAllCommand");
102106
OnPropertyChanged("PanelTitle");
103107
OnPropertyChanged("Description");
108+
104109
// ReSharper restore ExplicitCallerInfoArgument
105110
}
106111
}
@@ -463,13 +468,15 @@ private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
463468

464469
public CommandBase ImportCommand { get; }
465470
public CommandBase ExportCommand { get; }
471+
public CommandBase ExportAllCommand { get; }
472+
466473
public CommandBase RemoveCommand { get; }
467474

468475
public CommandBase PrintCommand { get; }
469476

470477
public CommandBase CommitCommand { get; }
471478
public CommandBase UndoCommand { get; }
472-
479+
473480
private readonly CommandBase _externalRemoveCommand;
474481

475482
// this is a special case--we have to reset SelectedItem to prevent a crash
@@ -482,6 +489,28 @@ private void ExecuteRemoveComand(object param)
482489
_externalRemoveCommand.Execute(param);
483490
}
484491

492+
private bool CanExecuteExportAllCommand => ExportAllCommand.CanExecute(SelectedItem);
493+
494+
public Visibility ExportVisibility
495+
{
496+
get
497+
{
498+
if (CanExecuteExportAllCommand == false)
499+
{ return Visibility.Visible; }
500+
else { return Visibility.Collapsed; }
501+
}
502+
}
503+
504+
public Visibility ExportAllVisibility
505+
{
506+
get
507+
{
508+
if (CanExecuteExportAllCommand == true)
509+
{ return Visibility.Visible; }
510+
else { return Visibility.Collapsed; }
511+
}
512+
}
513+
485514
public void Dispose()
486515
{
487516
if (_state != null)

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ private IMenuItem GetToolsParentMenu()
596596
var items = new List<IMenuItem> ()
597597
{
598598
KernelInstance.Get<RegexAssistantCommandMenuItem>(),
599-
KernelInstance.Get<ToDoExplorerCommandMenuItem>()
599+
KernelInstance.Get<ToDoExplorerCommandMenuItem>(),
600+
KernelInstance.Get<ExportAllCommandMenuItem>()
600601
};
601602

602603

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@
396396
<Compile Include="UI\CodeExplorer\Commands\CommitCommand.cs" />
397397
<Compile Include="UI\CodeExplorer\Commands\AddUserFormCommand.cs" />
398398
<Compile Include="UI\CodeExplorer\Commands\CopyResultsCommand.cs" />
399+
<Compile Include="UI\Command\ExportAllCommand.cs" />
399400
<Compile Include="UI\CodeExplorer\Commands\OpenProjectPropertiesCommand.cs" />
400401
<Compile Include="UI\CodeExplorer\Commands\RenameCommand.cs" />
401402
<Compile Include="UI\CodeExplorer\Commands\FindAllReferencesCommand.cs" />
@@ -414,6 +415,7 @@
414415
<Compile Include="UI\Command\IndentCurrentProjectCommand.cs" />
415416
<Compile Include="UI\Command\MenuItems\CommandBars\ContextDescriptionLabelMenuItem.cs" />
416417
<Compile Include="UI\Command\MenuItems\IndentCurrentProjectCommandMenuItem.cs" />
418+
<Compile Include="UI\Command\MenuItems\ExportAllCommandMenuItem.cs" />
417419
<Compile Include="UI\EnvironmentProvider.cs" />
418420
<Compile Include="UI\Inspections\AggregateInspectionResult.cs" />
419421
<Compile Include="UI\ModernFolderBrowser.cs" />

RetailCoder.VBE/Settings/HotkeySettings.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IHotkeySettings
1212

1313
public class HotkeySettings : IHotkeySettings, IEquatable<HotkeySettings>
1414
{
15-
private static readonly HotkeySetting[] Defaults =
15+
private static readonly HotkeySetting[] Defaults =
1616
{
1717
new HotkeySetting{Name=RubberduckHotkey.ParseAll.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="`" },
1818
new HotkeySetting{Name=RubberduckHotkey.IndentProcedure.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="P" },
@@ -25,7 +25,8 @@ public class HotkeySettings : IHotkeySettings, IEquatable<HotkeySettings>
2525
new HotkeySetting{Name=RubberduckHotkey.RefactorRename.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="R" },
2626
new HotkeySetting{Name=RubberduckHotkey.RefactorExtractMethod.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="M" },
2727
new HotkeySetting{Name=RubberduckHotkey.SourceControl.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="D6" },
28-
new HotkeySetting{Name=RubberduckHotkey.RefactorEncapsulateField.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="E" }
28+
new HotkeySetting{Name=RubberduckHotkey.RefactorEncapsulateField.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="F" },
29+
new HotkeySetting{Name=RubberduckHotkey.ExportActiveProject.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1="E" }
2930
};
3031

3132
private HashSet<HotkeySetting> _settings;

RetailCoder.VBE/Settings/RubberduckHotkey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum RubberduckHotkey
1414
RefactorRename,
1515
RefactorExtractMethod,
1616
RefactorEncapsulateField,
17-
SourceControl
17+
SourceControl,
18+
ExportActiveProject
1819
}
1920
}

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@
274274
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
275275
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
276276
<Setter Property="HorizontalAlignment" Value="Left" />
277-
<EventSetter Event="PreviewMouseRightButtonDown" Handler="OnPreviewMouseRightButtonDown" />
278277
<EventSetter Event="MouseDoubleClick" Handler="TreeView_OnMouseDoubleClick" />
278+
<EventSetter Event="MouseRightButtonDown" Handler="TreeView_OnMouseRightButtonDown" />
279279
<Style.Triggers>
280280
<Trigger Property="IsSelected" Value="True">
281281
<Setter Property="BorderBrush" Value="#adc6e5"/>
@@ -425,7 +425,12 @@
425425
CommandParameter="{Binding SelectedItem}" />
426426
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_Export}"
427427
Command="{Binding ExportCommand}"
428-
CommandParameter="{Binding SelectedItem}" />
428+
CommandParameter="{Binding SelectedItem}"
429+
Visibility="{Binding ExportVisibility}" />
430+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ExportAll}"
431+
Command="{Binding ExportAllCommand}"
432+
CommandParameter="{Binding SelectedItem}"
433+
Visibility="{Binding ExportAllVisibility}" />
429434
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_Remove}"
430435
Command="{Binding RemoveCommand}"
431436
CommandParameter="{Binding SelectedItem}" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ private void TreeView_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
2222
{
2323
ViewModel.NavigateCommand.Execute(ViewModel.SelectedItem);
2424
}
25+
e.Handled = true;
2526
}
2627

27-
private void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
28+
private void TreeView_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
2829
{
2930
((TreeViewItem)sender).IsSelected = true;
31+
e.Handled = true;
3032
}
3133
}
3234
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System.IO;
2+
using System.Windows.Forms;
3+
using NLog;
4+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
5+
using Rubberduck.Navigation.CodeExplorer;
6+
using Rubberduck.UI.CodeExplorer.Commands;
7+
using Rubberduck.Settings;
8+
9+
namespace Rubberduck.UI.Command
10+
{
11+
[CodeExplorerCommand]
12+
public class ExportAllCommand : CommandBase
13+
{
14+
private readonly IVBE _vbe;
15+
private IFolderBrowserFactory _factory;
16+
17+
public ExportAllCommand(IVBE vbe, IFolderBrowserFactory folderBrowserFactory) : base(LogManager.GetCurrentClassLogger())
18+
{
19+
_vbe = vbe;
20+
_factory = folderBrowserFactory;
21+
}
22+
23+
public override RubberduckHotkey Hotkey
24+
{
25+
get { return RubberduckHotkey.ExportActiveProject; }
26+
}
27+
28+
protected override bool EvaluateCanExecute(object parameter)
29+
{
30+
if (!(parameter is CodeExplorerProjectViewModel) && parameter is CodeExplorerItemViewModel)
31+
{
32+
return false;
33+
}
34+
35+
var projectNode = parameter as CodeExplorerProjectViewModel;
36+
37+
var project = parameter as IVBProject;
38+
39+
return Evaluate(projectNode?.Declaration.Project ?? project ?? _vbe.ActiveVBProject);
40+
41+
}
42+
43+
private bool Evaluate(IVBProject project)
44+
{
45+
return project != null && !project.IsWrappingNullReference && project.VBComponents.Count > 0;
46+
}
47+
48+
protected override void OnExecute(object parameter)
49+
{
50+
var projectNode = parameter as CodeExplorerProjectViewModel;
51+
52+
var vbproject = parameter as IVBProject;
53+
54+
IVBProject project = projectNode?.Declaration.Project ?? vbproject ?? _vbe.ActiveVBProject;
55+
56+
var desc = string.Format(RubberduckUI.ExportAllCommand_SaveAsDialog, project.Name);
57+
58+
// If .GetDirectoryName is passed an empty string for a RootFolder,
59+
// it defaults to the Documents library (Win 7+) or equivalent.
60+
var path = string.Empty;
61+
if (!string.IsNullOrWhiteSpace(project.FileName))
62+
{
63+
path = Path.GetDirectoryName(project.FileName);
64+
}
65+
66+
using (var _folderBrowser = _factory.CreateFolderBrowser(desc, true, path))
67+
{
68+
var result = _folderBrowser.ShowDialog();
69+
70+
if (result == DialogResult.OK)
71+
{
72+
project.ExportSourceFiles(_folderBrowser.SelectedPath);
73+
}
74+
}
75+
}
76+
}
77+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Rubberduck.Parsing.VBA;
2+
using Rubberduck.UI.Command.MenuItems.ParentMenus;
3+
4+
namespace Rubberduck.UI.Command.MenuItems
5+
{
6+
class ExportAllCommandMenuItem : CommandMenuItemBase
7+
{
8+
public ExportAllCommandMenuItem(CommandBase command) : base(command)
9+
{
10+
}
11+
12+
public override string Key => "ToolsMenu_ExportProject";
13+
14+
public override int DisplayOrder => (int)ToolsMenuItemDisplayOrder.ExportAll;
15+
16+
public override bool EvaluateCanExecute(RubberduckParserState state)
17+
{
18+
return Command.CanExecute(null);
19+
}
20+
}
21+
}

RetailCoder.VBE/UI/Command/MenuItems/ParentMenus/ToolsParentMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ public enum ToolsMenuItemDisplayOrder
1717
SourceControl,
1818
ToDoExplorer,
1919
RegexAssistant,
20+
ExportAll,
2021
}
2122
}

0 commit comments

Comments
 (0)