Skip to content

Commit 1d60053

Browse files
authored
Merge pull request #2078 from rubberduck-vba/next
Release 2.0.6
2 parents b54cbb2 + a4b38d0 commit 1d60053

File tree

168 files changed

+8464
-1525
lines changed

Some content is hidden

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

168 files changed

+8464
-1525
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Which basically means it's a reimplementation of Git in C. It also [happens to b
8585

8686
This library makes localizing WPF applications at runtime using resx files a breeze. Thank you [Grant Frisken](http://www.codeproject.com/script/Membership/View.aspx?mid=1079060)!
8787

88-
> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx).
88+
> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx) with the [author's permission](http://www.codeproject.com/Messages/5272045/Re-License.aspx) to re-release under the GPLv3.
8989
9090
###[Using Raw Input from C# to handle multiple keyboards](http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard)
9191

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ public static IEnumerable<Declaration> FindEventHandlers(this IEnumerable<Declar
262262
&& declaration.IdentifierName.StartsWith(control.IdentifierName + "_"));
263263
}
264264

265+
public static IEnumerable<Declaration> FindUserEventHandlers(this IEnumerable<Declaration> declarations)
266+
{
267+
var declarationList = declarations.ToList();
268+
269+
var userEvents =
270+
declarationList.Where(item => !item.IsBuiltIn && item.DeclarationType == DeclarationType.Event).ToList();
271+
272+
var handlers = new List<Declaration>();
273+
foreach (var @event in userEvents)
274+
{
275+
handlers.AddRange(declarations.FindHandlersForEvent(@event).Select(s => s.Item2));
276+
}
277+
278+
return handlers;
279+
}
280+
265281
public static IEnumerable<Declaration> FindBuiltInEventHandlers(this IEnumerable<Declaration> declarations)
266282
{
267283
var declarationList = declarations.ToList();
@@ -451,6 +467,12 @@ public static IEnumerable<Declaration> FindInterfaceImplementationMembers(this I
451467
.Where(m => m.IdentifierName.EndsWith(interfaceMember));
452468
}
453469

470+
public static IEnumerable<Declaration> FindInterfaceImplementationMembers(this IEnumerable<Declaration> declarations, Declaration interfaceDeclaration)
471+
{
472+
return FindInterfaceImplementationMembers(declarations)
473+
.Where(m => m.IdentifierName == interfaceDeclaration.ComponentName + "_" + interfaceDeclaration.IdentifierName);
474+
}
475+
454476
public static Declaration FindInterfaceMember(this IEnumerable<Declaration> declarations, Declaration implementation)
455477
{
456478
var members = FindInterfaceMembers(declarations);

RetailCoder.VBE/Common/Hotkeys/HotkeyInfo.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using System.Windows.Forms;
4+
using Rubberduck.UI;
45

56
namespace Rubberduck.Common.Hotkeys
67
{
@@ -25,20 +26,21 @@ public override string ToString()
2526
var builder = new StringBuilder();
2627
if (_keys.HasFlag(Keys.Alt))
2728
{
28-
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyAlt);
29+
builder.Append(RubberduckUI.GeneralSettings_HotkeyAlt);
2930
builder.Append('+');
3031
}
3132
if (_keys.HasFlag(Keys.Control))
3233
{
33-
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyCtrl);
34+
builder.Append(RubberduckUI.GeneralSettings_HotkeyCtrl);
3435
builder.Append('+');
3536
}
3637
if (_keys.HasFlag(Keys.Shift))
3738
{
38-
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyShift);
39+
builder.Append(RubberduckUI.GeneralSettings_HotkeyShift);
3940
builder.Append('+');
4041
}
41-
builder.Append(_keys & ~Modifiers);
42+
43+
builder.Append(HotkeyDisplayConverter.Convert(_keys & ~Modifiers));
4244
return builder.ToString();
4345
}
4446
}

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55
using System.Linq;
66
using System.Runtime.InteropServices;
77
using System.Windows.Forms;
8-
using System.Windows.Input;
98
using Microsoft.Vbe.Interop;
109
using Rubberduck.Common.Hotkeys;
1110
using Rubberduck.Common.WinAPI;
1211
using Rubberduck.Settings;
1312
using Rubberduck.UI.Command;
14-
using Rubberduck.UI.Command.Refactorings;
1513
using NLog;
1614

1715
namespace Rubberduck.Common
1816
{
1917
public class RubberduckHooks : IRubberduckHooks
2018
{
21-
private readonly VBE _vbe;
2219
private readonly IntPtr _mainWindowHandle;
2320
private readonly IntPtr _oldWndPointer;
2421
private readonly User32.WndProc _oldWndProc;
@@ -33,7 +30,6 @@ public class RubberduckHooks : IRubberduckHooks
3330

3431
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<CommandBase> commands)
3532
{
36-
_vbe = vbe;
3733
_mainWindowHandle = (IntPtr)vbe.MainWindow.HWnd;
3834
_oldWndProc = WindowProc;
3935
_newWndProc = WindowProc;
@@ -174,7 +170,7 @@ public void Detach()
174170
private void hook_MessageReceived(object sender, HookEventArgs e)
175171
{
176172
var hotkey = sender as IHotkey;
177-
if (hotkey != null)
173+
if (hotkey != null && hotkey.Command.CanExecute(null))
178174
{
179175
hotkey.Command.Execute(null);
180176
return;

RetailCoder.VBE/Common/WinAPI/RawInput.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,41 @@ protected override void WndProc(ref Message message)
3939
switch ((WM)message.Msg)
4040
{
4141
case WM.INPUT:
42+
{
43+
if (message.LParam == IntPtr.Zero)
44+
{
45+
break;
46+
}
47+
InputData rawBuffer;
48+
var dwSize = 0;
49+
var res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
50+
if (res != 0)
51+
{
52+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
53+
Logger.Error(ex, "Error sizing the rawinput buffer: {0}", ex.Message);
54+
break;
55+
}
56+
57+
res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, out rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
58+
if (res == -1)
59+
{
60+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
61+
Logger.Error(ex, "Error getting the rawinput buffer: {0}", ex.Message);
62+
break;
63+
}
64+
if (res == dwSize)
4265
{
43-
InputData _rawBuffer;
44-
var dwSize = 0;
45-
User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
46-
int res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, out _rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
47-
if (dwSize != res)
48-
{
49-
var ex = new Win32Exception(Marshal.GetLastWin32Error());
50-
Logger.Error(ex, "Error getting the rawinput buffer: {0}", ex.Message);
51-
return;
52-
}
5366
foreach (var device in _devices)
5467
{
55-
device.ProcessRawInput(_rawBuffer);
68+
device.ProcessRawInput(rawBuffer);
5669
}
5770
}
58-
break;
71+
else
72+
{
73+
//Something is seriously f'd up with Windows - the number of bytes copied does not match the reported buffer size.
74+
}
75+
}
76+
break;
5977
}
6078
base.WndProc(ref message);
6179
}

RetailCoder.VBE/Inspections/AssignedByValParameterInspectionResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public class AssignedByValParameterInspectionResult : InspectionResultBase
1313
public AssignedByValParameterInspectionResult(IInspection inspection, Declaration target)
1414
: base(inspection, target)
1515
{
16-
_quickFixes = new[]
16+
_quickFixes = new CodeInspectionQuickFix[]
1717
{
1818
new PassParameterByReferenceQuickFix(target.Context, QualifiedSelection),
19+
new IgnoreOnceQuickFix(Context, QualifiedSelection, inspection.AnnotationName)
1920
};
2021
}
2122

RetailCoder.VBE/Inspections/CodeInspectionQuickFix.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Antlr4.Runtime;
1+
using System.Windows.Threading;
2+
using Antlr4.Runtime;
23
using Rubberduck.VBEditor;
34

45
namespace Rubberduck.Inspections
@@ -11,6 +12,9 @@ public abstract class CodeInspectionQuickFix
1112

1213
public CodeInspectionQuickFix(ParserRuleContext context, QualifiedSelection selection, string description)
1314
{
15+
Dispatcher.CurrentDispatcher.Thread.CurrentCulture = UI.Settings.Settings.Culture;
16+
Dispatcher.CurrentDispatcher.Thread.CurrentUICulture = UI.Settings.Settings.Culture;
17+
1418
_context = context;
1519
_selection = selection;
1620
_description = description;

RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2626
{
2727
return new InspectionResultBase[] { };
2828
}
29-
return ParseTreeResults.EmptyStringLiterals.Select(
30-
context => new EmptyStringLiteralInspectionResult(this,
29+
return ParseTreeResults.EmptyStringLiterals
30+
.Where(s => !IsInspectionDisabled(s.ModuleName.Component, s.Context.Start.Line))
31+
.Select(context => new EmptyStringLiteralInspectionResult(this,
3132
new QualifiedContext<ParserRuleContext>(context.ModuleName, context.Context)));
3233
}
3334

RetailCoder.VBE/Inspections/EmptyStringLiteralInspectionResult.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public class EmptyStringLiteralInspectionResult : InspectionResultBase
1313
public EmptyStringLiteralInspectionResult(IInspection inspection, QualifiedContext<ParserRuleContext> qualifiedContext)
1414
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context)
1515
{
16-
_quickFixes = new[]
16+
_quickFixes = new CodeInspectionQuickFix[]
1717
{
18-
new RepaceEmptyStringLiteralStatementQuickFix(Context, QualifiedSelection),
18+
new RepaceEmptyStringLiteralStatementQuickFix(Context, QualifiedSelection),
19+
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName)
1920
};
2021
}
2122

RetailCoder.VBE/Inspections/EncapsulatePublicFieldInspectionResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ public class EncapsulatePublicFieldInspectionResult : InspectionResultBase
1616
public EncapsulatePublicFieldInspectionResult(IInspection inspection, Declaration target, RubberduckParserState state)
1717
: base(inspection, target)
1818
{
19-
_quickFixes = new[]
19+
_quickFixes = new CodeInspectionQuickFix[]
2020
{
2121
new EncapsulateFieldQuickFix(target.Context, target.QualifiedSelection, target, state),
22+
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName)
2223
};
2324
}
2425

RetailCoder.VBE/Inspections/FunctionReturnValueNotUsedInspectionResult.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ public FunctionReturnValueNotUsedInspectionResult(
3434
var root = new ConvertToProcedureQuickFix(context, QualifiedSelection, returnStatements);
3535
var compositeFix = new CompositeCodeInspectionFix(root);
3636
children.ToList().ForEach(child => compositeFix.AddChild(new ConvertToProcedureQuickFix(child.Item1, child.Item2, child.Item3)));
37-
_quickFixes = new[]
37+
_quickFixes = new CodeInspectionQuickFix[]
3838
{
39-
compositeFix
39+
compositeFix,
40+
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName)
4041
};
4142
}
4243

RetailCoder.VBE/Inspections/IParseTreeInspection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Rubberduck.Parsing;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using Rubberduck.Parsing.Grammar;
45

56
namespace Rubberduck.Inspections
67
{
@@ -17,11 +18,13 @@ public ParseTreeResults()
1718
ObsoleteLetContexts = Enumerable.Empty<QualifiedContext>();
1819
ArgListsWithOneByRefParam = Enumerable.Empty<QualifiedContext>();
1920
EmptyStringLiterals = Enumerable.Empty<QualifiedContext>();
21+
MalformedAnnotations = Enumerable.Empty<QualifiedContext<VBAParser.AnnotationContext>>();
2022
}
2123

2224
public IEnumerable<QualifiedContext> ObsoleteCallContexts;
2325
public IEnumerable<QualifiedContext> ObsoleteLetContexts;
2426
public IEnumerable<QualifiedContext> ArgListsWithOneByRefParam;
2527
public IEnumerable<QualifiedContext> EmptyStringLiterals;
28+
public IEnumerable<QualifiedContext<VBAParser.AnnotationContext>> MalformedAnnotations;
2629
}
2730
}

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2626

2727
var issues = (from item in UserDeclarations
2828
where
29-
!item.IsInspectionDisabled(AnnotationName)
29+
!IsInspectionDisabled(item, AnnotationName)
3030
&& item.DeclarationType == DeclarationType.Parameter
3131
// ParamArray parameters do not allow an explicit "ByRef" parameter mechanism.
3232
&& !((ParameterDeclaration)item).IsParamArray

RetailCoder.VBE/Inspections/ImplicitPublicMemberInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ImplicitPublicMemberInspection(RubberduckParserState state)
3030
public override IEnumerable<InspectionResultBase> GetInspectionResults()
3131
{
3232
var issues = from item in UserDeclarations
33-
where !item.IsInspectionDisabled(AnnotationName)
33+
where !IsInspectionDisabled(item, AnnotationName)
3434
&& ProcedureTypes.Contains(item.DeclarationType)
3535
&& item.Accessibility == Accessibility.Implicit
3636
let context = new QualifiedContext<ParserRuleContext>(item.QualifiedName, item.Context)

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ImplicitVariantReturnTypeInspection(RubberduckParserState state)
2828
public override IEnumerable<InspectionResultBase> GetInspectionResults()
2929
{
3030
var issues = from item in UserDeclarations
31-
where !item.IsInspectionDisabled(AnnotationName)
31+
where !IsInspectionDisabled(item, AnnotationName)
3232
&& ProcedureTypes.Contains(item.DeclarationType)
3333
&& !item.IsTypeSpecified
3434
let issue = new {Declaration = item, QualifiedContext = new QualifiedContext<ParserRuleContext>(item.QualifiedName, item.Context)}

RetailCoder.VBE/Inspections/InspectionBase.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using Microsoft.Vbe.Interop;
5+
using Rubberduck.Parsing.Annotations;
46
using Rubberduck.Parsing.Symbols;
57
using Rubberduck.Parsing.VBA;
68

@@ -73,20 +75,56 @@ protected InspectionBase(RubberduckParserState state, CodeInspectionSeverity def
7375
/// </summary>
7476
protected virtual IEnumerable<Declaration> Declarations
7577
{
76-
get { return State.AllDeclarations.Where(declaration => !declaration.IsInspectionDisabled(AnnotationName)); }
78+
get { return State.AllDeclarations.Where(declaration => !IsInspectionDisabled(declaration, AnnotationName)); }
79+
}
80+
81+
/// <summary>
82+
/// Gets all user declarations in the parser state without an @Ignore annotation for this inspection.
83+
/// </summary>
84+
protected virtual IEnumerable<Declaration> UserDeclarations
85+
{
86+
get { return State.AllUserDeclarations.Where(declaration => !IsInspectionDisabled(declaration, AnnotationName)); }
7787
}
7888

7989
protected virtual IEnumerable<Declaration> BuiltInDeclarations
8090
{
8191
get { return State.AllDeclarations.Where(declaration => declaration.IsBuiltIn); }
8292
}
8393

84-
/// <summary>
85-
/// Gets all user declarations in the parser state without an @Ignore annotation for this inspection.
86-
/// </summary>
87-
protected virtual IEnumerable<Declaration> UserDeclarations
94+
protected bool IsInspectionDisabled(VBComponent component, int line)
8895
{
89-
get { return State.AllUserDeclarations.Where(declaration => !declaration.IsInspectionDisabled(AnnotationName)); }
96+
var annotations = State.GetModuleAnnotations(component).ToList();
97+
98+
if (State.GetModuleAnnotations(component) == null)
99+
{
100+
return false;
101+
}
102+
103+
// VBE 1-based indexing
104+
for (var i = line - 1; i >= 1; i--)
105+
{
106+
var annotation = annotations.SingleOrDefault(a => a.QualifiedSelection.Selection.StartLine == i) as IgnoreAnnotation;
107+
if (annotation != null && annotation.InspectionNames.Contains(AnnotationName))
108+
{
109+
return true;
110+
}
111+
}
112+
113+
return false;
114+
}
115+
116+
protected bool IsInspectionDisabled(Declaration declaration, string inspectionName)
117+
{
118+
if (declaration.DeclarationType == DeclarationType.Parameter)
119+
{
120+
return declaration.ParentDeclaration.Annotations.Any(annotation =>
121+
annotation.AnnotationType == AnnotationType.Ignore
122+
&& ((IgnoreAnnotation)annotation).IsIgnored(inspectionName));
123+
}
124+
125+
return declaration.Annotations.Any(annotation =>
126+
annotation.AnnotationType == AnnotationType.Ignore
127+
&& ((IgnoreAnnotation)annotation).IsIgnored(inspectionName));
90128
}
91129

92130
public int CompareTo(IInspection other)

0 commit comments

Comments
 (0)