Skip to content

Commit e32009f

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into next
2 parents a7ba64e + ba138e2 commit e32009f

File tree

357 files changed

+20389
-10947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+20389
-10947
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.user
77
*.sln.docstates
88
*.csproj.user
9+
*.csproj.DotSettings
910

1011
# External NuGet Packages
1112
[Pp]ackages/

.nuget/NuGet.exe

2.8 MB
Binary file not shown.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<img src="http://i.stack.imgur.com/jnBEp.jpg" width=100% />
22

3+
<!-- campaign is no longer accepting donations
34
### Donate!
45
56
If you like this project and would like to thank its contributors, you are welcome to support our GoFundMe campaign to finance Rubberduck swag and international shipping - contributors will be getting t-shirts, mugs, and other cool things.
67
78
[![GoFundMe campaign](https://user-images.githubusercontent.com/5751684/29191799-e3d20b72-7dec-11e7-8ec6-0c69da4a3135.png)](https://www.gofundme.com/rubberduckvba)
9+
-->
810

911
Branch | Description | Build Status |
1012
|------------|---|--------------|

RetailCoder.VBE/API/VBA/Declaration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ internal Declaration(RubberduckDeclaration declaration)
5656
{ Parsing.Symbols.DeclarationType.Control, DeclarationType.Control },
5757
{ Parsing.Symbols.DeclarationType.UserForm, DeclarationType.UserForm },
5858
{ Parsing.Symbols.DeclarationType.Document, DeclarationType.Document },
59-
{ Parsing.Symbols.DeclarationType.ModuleOption, DeclarationType.ModuleOption },
6059
{ Parsing.Symbols.DeclarationType.Procedure, DeclarationType.Procedure },
6160
{ Parsing.Symbols.DeclarationType.Function, DeclarationType.Function },
6261
{ Parsing.Symbols.DeclarationType.PropertyGet, DeclarationType.PropertyGet },

RetailCoder.VBE/API/VBA/DeclarationType.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public enum DeclarationType
1212
Control, //= 1 << 3,
1313
UserForm,// = 1 << 4,
1414
Document,// = 1 << 5,
15-
ModuleOption,// = 1 << 6,
1615
Procedure, //= 1 << 8,
1716
Function,// = 1 << 9,
1817
PropertyGet,// = 1 << 11,

RetailCoder.VBE/Common/Hotkeys/HotkeyInfo.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,35 @@ public struct HotkeyInfo
99
{
1010
private const Keys Modifiers = Keys.Alt | Keys.Control | Keys.Shift;
1111

12-
private readonly IntPtr _hookId;
13-
private readonly Keys _keys;
14-
1512
public HotkeyInfo(IntPtr hookId, Keys keys)
1613
{
17-
_hookId = hookId;
18-
_keys = keys;
14+
HookId = hookId;
15+
Keys = keys;
1916
}
2017

21-
public IntPtr HookId { get { return _hookId; } }
22-
public Keys Keys { get { return _keys; } }
18+
public IntPtr HookId { get; }
19+
public Keys Keys { get; }
2320

2421
public override string ToString()
2522
{
2623
var builder = new StringBuilder();
27-
if (_keys.HasFlag(Keys.Alt))
24+
if (Keys.HasFlag(Keys.Alt))
2825
{
2926
builder.Append(RubberduckUI.GeneralSettings_HotkeyAlt);
3027
builder.Append('+');
3128
}
32-
if (_keys.HasFlag(Keys.Control))
29+
if (Keys.HasFlag(Keys.Control))
3330
{
3431
builder.Append(RubberduckUI.GeneralSettings_HotkeyCtrl);
3532
builder.Append('+');
3633
}
37-
if (_keys.HasFlag(Keys.Shift))
34+
if (Keys.HasFlag(Keys.Shift))
3835
{
3936
builder.Append(RubberduckUI.GeneralSettings_HotkeyShift);
4037
builder.Append('+');
4138
}
4239

43-
builder.Append(HotkeyDisplayConverter.Convert(_keys & ~Modifiers));
40+
builder.Append(HotkeyDisplayConverter.Convert(Keys & ~Modifiers));
4441
return builder.ToString();
4542
}
4643
}

RetailCoder.VBE/Extension.cs

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
using Rubberduck.Settings;
2020
using Rubberduck.SettingsProvider;
2121
using Rubberduck.VBEditor.Events;
22-
using Rubberduck.VBEditor.SafeComWrappers;
2322
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
2423
using Rubberduck.VBEditor.WindowsApi;
2524
using User32 = Rubberduck.Common.WinAPI.User32;
25+
using Windows = Rubberduck.VBEditor.SafeComWrappers.VBA.Windows;
2626

2727
namespace Rubberduck
2828
{
@@ -204,56 +204,83 @@ private void InitializeAddIn()
204204

205205
private void Startup()
206206
{
207-
var currentDomain = AppDomain.CurrentDomain;
208-
currentDomain.AssemblyResolve += LoadFromSameFolder;
207+
try
208+
{
209+
var currentDomain = AppDomain.CurrentDomain;
210+
currentDomain.UnhandledException += HandlAppDomainException;
211+
currentDomain.AssemblyResolve += LoadFromSameFolder;
212+
213+
_kernel = new StandardKernel(new NinjectSettings {LoadExtensions = true}, new FuncModule(), new DynamicProxyModule());
214+
_kernel.Load(new RubberduckModule(_ide, _addin));
209215

210-
_kernel = new StandardKernel(new NinjectSettings {LoadExtensions = true}, new FuncModule(), new DynamicProxyModule());
211-
_kernel.Load(new RubberduckModule(_ide, _addin));
216+
_app = _kernel.Get<App>();
217+
_app.Startup();
212218

213-
_app = _kernel.Get<App>();
214-
_app.Startup();
219+
_isInitialized = true;
220+
221+
}
222+
catch (Exception e)
223+
{
224+
_logger.Log(LogLevel.Fatal, e, "Startup sequence threw an unexpected exception.");
225+
//throw; // <<~ uncomment to crash the process
226+
}
227+
}
215228

216-
_isInitialized = true;
229+
private void HandlAppDomainException(object sender, UnhandledExceptionEventArgs e)
230+
{
231+
_logger.Log(LogLevel.Fatal, e);
217232
}
218233

219234
private void ShutdownAddIn()
220235
{
221-
Debug.WriteLine("Extension unhooking VBENativeServices events.");
222-
VBENativeServices.UnhookEvents();
223-
224236
var currentDomain = AppDomain.CurrentDomain;
225-
currentDomain.AssemblyResolve -= LoadFromSameFolder;
226-
Debug.WriteLine("Extension broadcasting shutdown.");
227-
User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0));
228-
229-
Debug.WriteLine("Extension calling ReleaseDockableHosts.");
230-
VBEditor.SafeComWrappers.VBA.Windows.ReleaseDockableHosts();
231-
232-
if (_app != null)
233-
{
234-
Debug.WriteLine("Extension calling App.Shutdown.");
235-
_app.Shutdown();
236-
_app = null;
237-
}
238-
239-
if (_kernel != null)
237+
try
240238
{
241-
Debug.WriteLine("Extension calling Kernel.Dispose.");
242-
_kernel.Dispose();
243-
_kernel = null;
244-
}
245-
246-
Debug.WriteLine("Extension: Initiating garbage collection.");
239+
_logger.Log(LogLevel.Info, "Rubberduck is shutting down.");
240+
_logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events...");
241+
VBENativeServices.UnhookEvents();
247242

248-
GC.Collect();
243+
_logger.Log(LogLevel.Trace, "Broadcasting shutdown...");
244+
User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0));
249245

250-
Debug.WriteLine("Extension: Initiated garbage collection.");
246+
_logger.Log(LogLevel.Trace, "Releasing dockable hosts...");
247+
Windows.ReleaseDockableHosts();
251248

252-
GC.WaitForPendingFinalizers();
249+
if (_app != null)
250+
{
251+
_logger.Log(LogLevel.Trace, "Initiating App.Shutdown...");
252+
_app.Shutdown();
253+
_app = null;
254+
}
253255

254-
Debug.WriteLine("Extension: Finalizers have run.");
256+
if (_kernel != null)
257+
{
258+
_logger.Log(LogLevel.Trace, "Disposing IoC container...");
259+
_kernel.Dispose();
260+
_kernel = null;
261+
}
255262

256-
_isInitialized = false;
263+
_isInitialized = false;
264+
_logger.Log(LogLevel.Info, "No exceptions were thrown.");
265+
}
266+
catch (Exception e)
267+
{
268+
_logger.Error(e);
269+
_logger.Log(LogLevel.Warn, "Exception is swallowed.");
270+
//throw; // <<~ uncomment to crash the process
271+
}
272+
finally
273+
{
274+
_logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
275+
currentDomain.AssemblyResolve -= LoadFromSameFolder;
276+
currentDomain.UnhandledException -= HandlAppDomainException;
277+
_logger.Log(LogLevel.Trace, "Done. Initiating garbage collection...");
278+
GC.Collect();
279+
_logger.Log(LogLevel.Trace, "Done. Waiting for pending finalizers...");
280+
GC.WaitForPendingFinalizers();
281+
_logger.Log(LogLevel.Trace, "Done. Shutdown completed. Quack!");
282+
_isInitialized = false;
283+
}
257284
}
258285

259286
private static int EnumCallback(IntPtr hwnd, IntPtr lparam)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
5151
_name = _declaration.IdentifierName;
5252

5353
var component = declaration.QualifiedName.QualifiedModuleName.Component;
54-
if (component.Type == ComponentType.Document)
54+
try
5555
{
56-
try
56+
if (component.Type == ComponentType.Document)
5757
{
5858
var parenthesizedName = component.Properties["Name"].Value.ToString();
5959

@@ -72,10 +72,10 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
7272
_name += " (" + parenthesizedName + ")";
7373
}
7474
}
75-
catch
76-
{
77-
// gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
78-
}
75+
}
76+
catch
77+
{
78+
// gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
7979
}
8080
}
8181

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ public class CompareByType : Comparer<CodeExplorerItemViewModel>
3131
{
3232
private static readonly Dictionary<DeclarationType, int> SortOrder = new Dictionary<DeclarationType, int>
3333
{
34+
// Some DeclarationTypes we want to treat the same, like Subs and Functions,
35+
// or Property Gets, Lets, and Sets.
36+
// Give them the same number.
3437
{DeclarationType.LibraryFunction, 0},
35-
{DeclarationType.LibraryProcedure, 1},
36-
{DeclarationType.UserDefinedType, 2},
37-
{DeclarationType.Enumeration, 3},
38-
{DeclarationType.Event, 4},
39-
{DeclarationType.Constant, 5},
40-
{DeclarationType.Variable, 6},
41-
{DeclarationType.PropertyGet, 7},
42-
{DeclarationType.PropertyLet, 8},
43-
{DeclarationType.PropertySet, 9},
44-
{DeclarationType.Function, 10},
45-
{DeclarationType.Procedure, 11}
38+
{DeclarationType.LibraryProcedure, 0},
39+
{DeclarationType.UserDefinedType, 1},
40+
{DeclarationType.Enumeration, 2},
41+
{DeclarationType.Event, 3},
42+
{DeclarationType.Constant, 4},
43+
{DeclarationType.Variable, 5},
44+
{DeclarationType.PropertyGet, 6},
45+
{DeclarationType.PropertyLet, 6},
46+
{DeclarationType.PropertySet, 6},
47+
{DeclarationType.Function, 7},
48+
{DeclarationType.Procedure, 7}
4649
};
4750

4851
public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewModel y)
@@ -69,17 +72,21 @@ public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewMod
6972
if (SortOrder.TryGetValue(xNode.Declaration.DeclarationType, out xValue) &&
7073
SortOrder.TryGetValue(yNode.Declaration.DeclarationType, out yValue))
7174
{
72-
return xValue < yValue ? -1 : 1;
75+
if (xValue != yValue)
76+
{ return xValue < yValue ? -1 : 1; }
7377
}
74-
75-
return xNode.Declaration.DeclarationType < yNode.Declaration.DeclarationType ? -1 : 1;
7678
}
7779

78-
if (xNode.Declaration.Accessibility != yNode.Declaration.Accessibility)
80+
// The Tree shows Public and Private Subs/Functions with a seperate icon.
81+
// But Public and Implicit Subs/Functions appear the same, so treat Implicts like Publics.
82+
var xNodeAcc = xNode.Declaration.Accessibility == Accessibility.Implicit ? Accessibility.Public : xNode.Declaration.Accessibility;
83+
var yNodeAcc = yNode.Declaration.Accessibility == Accessibility.Implicit ? Accessibility.Public : yNode.Declaration.Accessibility;
84+
85+
if (xNodeAcc != yNodeAcc)
7986
{
80-
return xNode.Declaration.Accessibility < yNode.Declaration.Accessibility ? -1 : 1;
87+
return xNodeAcc > yNodeAcc ? -1 : 1;
8188
}
82-
89+
8390
if (x.ExpandedIcon != y.ExpandedIcon)
8491
{
8592
// ReSharper disable PossibleInvalidOperationException - this will have a component
@@ -121,12 +128,12 @@ public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewMod
121128
return x.QualifiedSelection.HasValue ? -1 : 1;
122129
}
123130

124-
if (x.QualifiedSelection.Value.Selection == y.QualifiedSelection.Value.Selection)
131+
if (x.QualifiedSelection.Value.Selection.StartLine == y.QualifiedSelection.Value.Selection.StartLine)
125132
{
126133
return 0;
127134
}
128135

129-
return x.QualifiedSelection.Value.Selection < y.QualifiedSelection.Value.Selection ? -1 : 1;
136+
return x.QualifiedSelection.Value.Selection.StartLine < y.QualifiedSelection.Value.Selection.StartLine ? -1 : 1;
130137
}
131138
}
132139

@@ -183,6 +190,17 @@ public bool IsExpanded
183190

184191
public bool IsSelected { get; set; }
185192

193+
private bool _isVisisble = true;
194+
public bool IsVisible
195+
{
196+
get { return _isVisisble; }
197+
set
198+
{
199+
_isVisisble = value;
200+
OnPropertyChanged();
201+
}
202+
}
203+
186204
public abstract string Name { get; }
187205
public abstract string NameWithSignature { get; }
188206
public abstract BitmapImage CollapsedIcon { get; }
@@ -221,9 +239,9 @@ public void AddChild(CodeExplorerItemViewModel item)
221239
_items.Add(item);
222240
}
223241

224-
public void ReorderItems(bool sortByName, bool sortByType)
242+
public void ReorderItems(bool sortByName, bool groupByType)
225243
{
226-
if (sortByType)
244+
if (groupByType)
227245
{
228246
Items = sortByName
229247
? Items.OrderBy(o => o, new CompareByType()).ThenBy(t => t, new CompareByName()).ToList()

0 commit comments

Comments
 (0)