Skip to content

Commit 619ab9b

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into next
2 parents c47cc43 + 48dcdce commit 619ab9b

31 files changed

+851
-62
lines changed

RetailCoder.VBE/AppMenu.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ public void Dispose()
7070
_parser.State.StateChanged -= OnParserStateChanged;
7171
_selectionService.SelectedDeclarationChanged -= OnSelectedDeclarationChange;
7272

73-
// note: doing this wrecks the teardown process. counter-intuitive? sure. but hey it works.
74-
//foreach (var menu in _menus.Where(menu => menu.Item != null))
75-
//{
76-
// menu.RemoveChildren();
77-
// menu.Item.Delete();
78-
//}
73+
RemoveMenus();
74+
}
75+
76+
private void RemoveMenus()
77+
{
78+
foreach (var menu in _menus.Where(menu => menu.Item != null))
79+
{
80+
menu.RemoveMenu();
81+
}
7982
}
8083
}
8184
}

RetailCoder.VBE/Extension.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ private void ShutdownAddIn()
243243
_kernel = null;
244244
}
245245

246+
Debug.WriteLine("Extension: Initiating garbage collection.");
247+
248+
GC.Collect();
249+
250+
Debug.WriteLine("Extension: Initiated garbage collection.");
251+
252+
GC.WaitForPendingFinalizers();
253+
254+
Debug.WriteLine("Extension: Finalizers have run.");
255+
246256
_isInitialized = false;
247257
}
248258

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 31 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,11 @@ public CodeExplorerItemViewModel SelectedItem
99102
OnPropertyChanged("CanExecuteIndenterCommand");
100103
OnPropertyChanged("CanExecuteRenameCommand");
101104
OnPropertyChanged("CanExecuteFindAllReferencesCommand");
105+
OnPropertyChanged("ExportVisibility");
106+
OnPropertyChanged("ExportAllVisibility");
102107
OnPropertyChanged("PanelTitle");
103108
OnPropertyChanged("Description");
109+
104110
// ReSharper restore ExplicitCallerInfoArgument
105111
}
106112
}
@@ -463,13 +469,15 @@ private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
463469

464470
public CommandBase ImportCommand { get; }
465471
public CommandBase ExportCommand { get; }
472+
public CommandBase ExportAllCommand { get; }
473+
466474
public CommandBase RemoveCommand { get; }
467475

468476
public CommandBase PrintCommand { get; }
469477

470478
public CommandBase CommitCommand { get; }
471479
public CommandBase UndoCommand { get; }
472-
480+
473481
private readonly CommandBase _externalRemoveCommand;
474482

475483
// this is a special case--we have to reset SelectedItem to prevent a crash
@@ -482,6 +490,28 @@ private void ExecuteRemoveComand(object param)
482490
_externalRemoveCommand.Execute(param);
483491
}
484492

493+
private bool CanExecuteExportAllCommand => ExportAllCommand.CanExecute(SelectedItem);
494+
495+
public Visibility ExportVisibility
496+
{
497+
get
498+
{
499+
if (CanExecuteExportAllCommand == false)
500+
{ return Visibility.Visible; }
501+
else { return Visibility.Collapsed; }
502+
}
503+
}
504+
505+
public Visibility ExportAllVisibility
506+
{
507+
get
508+
{
509+
if (CanExecuteExportAllCommand == true)
510+
{ return Visibility.Visible; }
511+
else { return Visibility.Collapsed; }
512+
}
513+
}
514+
485515
public void Dispose()
486516
{
487517
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+
}

0 commit comments

Comments
 (0)