Skip to content

Commit edc2df2

Browse files
authored
Merge pull request #1863 from rubberduck-vba/next
Merge next into master
2 parents f306582 + 788dc2d commit edc2df2

File tree

116 files changed

+12936
-7714
lines changed

Some content is hidden

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

116 files changed

+12936
-7714
lines changed

License.rtf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{\pntxtb (}{\pntxta )}}\pard\plain \ltrpar\ql \li0\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid12126636 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0
4747
\f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid12126636 Rubberduck is a COM add-in for the VBA IDE (VBE).
4848
\par
49-
\par Copyright (C) 2014-2015 Mathieu Guindon & Christopher McClellan
49+
\par Copyright (C) 2014-2016 Mathieu Guindon & Christopher McClellan
5050
\par
5151
\par This program is free software: you can redistribute it and/or modify
5252
\par it under the terms of the GNU General Public License as published by
@@ -845,4 +845,4 @@ ffffffffffffffffffffffffffffffff52006f006f007400200045006e0074007200790000000000
845845
40e4695ed001feffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000
846846
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000
847847
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff000000000000000000000000000000000000000000000000
848-
0000000000000000000000000000000000000000000000000105000000000000}}
848+
0000000000000000000000000000000000000000000000000105000000000000}}

RetailCoder.VBE/API/ParserState.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.Linq;
45
using System.Runtime.InteropServices;
@@ -8,6 +9,7 @@
89
using Rubberduck.UI.Command.MenuItems;
910
using Rubberduck.Parsing.Preprocessing;
1011
using System.Globalization;
12+
using Rubberduck.Parsing.Symbols;
1113

1214
namespace Rubberduck.API
1315
{
@@ -65,7 +67,8 @@ public void Initialize(VBE vbe)
6567
}
6668
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture));
6769
_attributeParser = new AttributeParser(new ModuleExporter(), preprocessorFactory);
68-
_parser = new RubberduckParser(vbe, _state, _attributeParser, preprocessorFactory);
70+
_parser = new RubberduckParser(vbe, _state, _attributeParser, preprocessorFactory,
71+
new List<ICustomDeclarationLoader> { new DebugDeclarations(_state), new FormEventDeclarations(_state) });
6972
}
7073

7174
/// <summary>

RetailCoder.VBE/App.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public App(VBE vbe, IMessageBox messageBox,
7979

8080
_hooks.MessageReceived += _hooks_MessageReceived;
8181
_configService.SettingsChanged += _configService_SettingsChanged;
82-
_configService.LanguageChanged += ConfigServiceLanguageChanged;
8382
_parser.State.StateChanged += Parser_StateChanged;
8483
_parser.State.StatusMessageUpdate += State_StatusMessageUpdate;
8584
_stateBar.Refresh += _stateBar_Refresh;
@@ -156,13 +155,18 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
156155
(selectedDeclaration == null && _lastSelectedDeclaration != null);
157156
}
158157

159-
private void _configService_SettingsChanged(object sender, EventArgs e)
158+
private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
160159
{
161160
_config = _configService.LoadConfiguration();
162161
_hooks.HookHotkeys();
163162
// also updates the ShortcutKey text
164163
_appMenus.Localize();
165164
UpdateLoggingLevel();
165+
166+
if (e.LanguageChanged)
167+
{
168+
LoadConfig();
169+
}
166170
}
167171

168172
private void UpdateLoggingLevel()
@@ -172,7 +176,7 @@ private void UpdateLoggingLevel()
172176

173177
public void Startup()
174178
{
175-
CleanReloadConfig();
179+
LoadConfig();
176180
_appMenus.Initialize();
177181
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
178182
_appMenus.Localize();
@@ -417,16 +421,6 @@ private void Parser_StateChanged(object sender, EventArgs e)
417421
_appMenus.EvaluateCanExecute(_parser.State);
418422
}
419423

420-
private void CleanReloadConfig()
421-
{
422-
LoadConfig();
423-
}
424-
425-
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
426-
{
427-
CleanReloadConfig();
428-
}
429-
430424
private void LoadConfig()
431425
{
432426
_logger.Debug("Loading configuration");
@@ -488,7 +482,6 @@ public void Dispose()
488482
if (_configService != null)
489483
{
490484
_configService.SettingsChanged -= _configService_SettingsChanged;
491-
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
492485
_configService = null;
493486
}
494487

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void Dispose(bool disposing)
6969

7070
if (_configService != null)
7171
{
72-
_configService.LanguageChanged -= ConfigServiceSettingsChanged;
72+
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
7373
}
7474

7575
if (_timer != null)

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Rubberduck.Parsing;
99
using Rubberduck.Parsing.Grammar;
1010
using Rubberduck.Parsing.Symbols;
11+
using Rubberduck.Parsing.VBA;
1112
using Rubberduck.Properties;
1213
using Rubberduck.UI;
1314
using Rubberduck.VBEditor;
@@ -330,9 +331,9 @@ public static Declaration FindSelectedDeclaration(this IEnumerable<Declaration>
330331
return declaration;
331332
}
332333

333-
public static IEnumerable<Declaration> FindFormEventHandlers(this IEnumerable<Declaration> declarations)
334+
public static IEnumerable<Declaration> FindFormEventHandlers(this RubberduckParserState state)
334335
{
335-
var items = declarations.ToList();
336+
var items = state.AllDeclarations.ToList();
336337

337338
var forms = items.Where(item => item.DeclarationType == DeclarationType.ClassModule
338339
&& item.QualifiedName.QualifiedModuleName.Component != null
@@ -342,18 +343,24 @@ public static IEnumerable<Declaration> FindFormEventHandlers(this IEnumerable<De
342343
var result = new List<Declaration>();
343344
foreach (var declaration in forms)
344345
{
345-
result.AddRange(FindFormEventHandlers(items, declaration));
346+
result.AddRange(FindFormEventHandlers(state, declaration));
346347
}
347348

348349
return result;
349350
}
350351

351-
public static IEnumerable<Declaration> FindFormEventHandlers(this IEnumerable<Declaration> declarations, Declaration userForm)
352+
public static IEnumerable<Declaration> FindFormEventHandlers(this RubberduckParserState state, Declaration userForm)
352353
{
353-
var items = declarations as IList<Declaration> ?? declarations.ToList();
354+
var items = state.AllDeclarations.ToList();
354355
var events = items.Where(item => item.IsBuiltIn
355-
&& item.ParentScope == "MSForms.UserForm"
356+
&& item.ParentScope == "FM20.DLL;MSForms.FormEvents"
356357
&& item.DeclarationType == DeclarationType.Event).ToList();
358+
359+
var e = items.Where(item => item.DeclarationType == DeclarationType.Event).ToList();
360+
var e1 = items.Where(item => item.DeclarationType == DeclarationType.Event && item.IdentifierName == "QueryClose").ToList();
361+
362+
var s = items.Where(item => item.IdentifierName.Contains("QueryClose") || item.IdentifierName.Contains("Initialize") || item.IdentifierName.Contains("Activate")).ToList();
363+
357364
var handlerNames = events.Select(item => "UserForm_" + item.IdentifierName);
358365
var handlers = items.Where(item => item.ParentScope == userForm.Scope
359366
&& item.DeclarationType == DeclarationType.Procedure

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ public void Detach()
188188

189189
private void hook_MessageReceived(object sender, HookEventArgs e)
190190
{
191+
var active = User32.GetForegroundWindow();
192+
if (active != _mainWindowHandle)
193+
{
194+
return;
195+
}
196+
191197
var hotkey = sender as IHotkey;
192198
if (hotkey != null)
193199
{
@@ -210,18 +216,9 @@ private IntPtr WindowProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
210216
try
211217
{
212218
var suppress = false;
213-
if (hWnd == _mainWindowHandle)
219+
if (hWnd == _mainWindowHandle && (WM)uMsg == WM.HOTKEY)
214220
{
215-
switch ((WM)uMsg)
216-
{
217-
case WM.HOTKEY:
218-
suppress = HandleHotkeyMessage(wParam);
219-
break;
220-
221-
case WM.ACTIVATEAPP:
222-
HandleActivateAppMessage(wParam);
223-
break;
224-
}
221+
suppress = HandleHotkeyMessage(wParam);
225222
}
226223

227224
return suppress
@@ -257,29 +254,5 @@ private bool HandleHotkeyMessage(IntPtr wParam)
257254
}
258255
return processed;
259256
}
260-
261-
private void HandleActivateAppMessage(IntPtr wParam)
262-
{
263-
const int WA_INACTIVE = 0;
264-
const int WA_ACTIVE = 1;
265-
const int WA_CLICKACTIVE = 2;
266-
267-
switch (LoWord(wParam))
268-
{
269-
case WA_ACTIVE:
270-
case WA_CLICKACTIVE:
271-
Attach();
272-
break;
273-
274-
case WA_INACTIVE:
275-
Detach();
276-
break;
277-
}
278-
}
279-
280-
private static int LoWord(IntPtr dw)
281-
{
282-
return unchecked((short)(uint)dw);
283-
}
284257
}
285258
}

RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3636
}
3737

3838
var matches = BuiltInDeclarations.Where(item =>
39-
Targets.Contains(item.IdentifierName)).ToList();
39+
Targets.Contains(item.IdentifierName) &&
40+
item.ParentScope == "EXCEL.EXE;Excel._Global" &&
41+
item.AsTypeName == "Range").ToList();
4042

4143
var issues = matches.Where(item => item.References.Any())
4244
.SelectMany(declaration => declaration.References);

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Inspector(IGeneralConfigService configService, IEnumerable<IInspection> i
2424
_inspections = inspections;
2525

2626
_configService = configService;
27-
configService.LanguageChanged += ConfigServiceLanguageChanged;
27+
configService.SettingsChanged += ConfigServiceLanguageChanged;
2828
}
2929

3030
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
@@ -121,7 +121,7 @@ public void Dispose()
121121
{
122122
if (_configService != null)
123123
{
124-
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
124+
_configService.SettingsChanged -= ConfigServiceLanguageChanged;
125125
}
126126
}
127127
}

RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4444
.Concat(declarations.FindInterfaceImplementationMembers())
4545
.ToList();
4646

47-
var formEventHandlerScopes = declarations.FindFormEventHandlers()
47+
var formEventHandlerScopes = State.FindFormEventHandlers()
4848
.Select(handler => handler.Scope);
4949

5050
var eventScopes = declarations.Where(item =>

RetailCoder.VBE/Inspections/ProcedureCanBeWrittenAsFunctionInspection.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4040
.Where(c =>
4141
{
4242
var declaration =
43-
UserDeclarations.SingleOrDefault(d => d.DeclarationType == DeclarationType.Procedure &&
44-
d.IdentifierName == c.subroutineName().GetText() &&
45-
d.Context.GetSelection().Equals(c.GetSelection()));
43+
UserDeclarations.SingleOrDefault(d => d.Context == c);
4644

4745
if (UserDeclarations.FindInterfaceMembers().Contains(declaration))
4846
{
@@ -63,9 +61,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
6361
var subStmtsNotImplementingEvents = subStmts
6462
.Where(c =>
6563
{
66-
var declaration = UserDeclarations.SingleOrDefault(d => d.DeclarationType == DeclarationType.Procedure &&
67-
d.IdentifierName == c.subroutineName().GetText() &&
68-
d.Context.GetSelection().Equals(c.GetSelection()));
64+
var declaration = UserDeclarations.SingleOrDefault(d => d.Context == c);
6965

7066
if (declaration == null) { return false; } // rather be safe than sorry
7167

0 commit comments

Comments
 (0)