Skip to content

Commit 65c8e1b

Browse files
committed
Merge pull request #1358 from retailcoder/next
last-minute changes
2 parents 7ef8231 + f958960 commit 65c8e1b

File tree

11 files changed

+551
-522
lines changed

11 files changed

+551
-522
lines changed

RetailCoder.VBE/App.cs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public class App : IDisposable
4444
private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
4545
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
4646

47-
private readonly IDictionary<Type, Action> _hookActions;
48-
4947
public App(VBE vbe, IMessageBox messageBox,
5048
IRubberduckParser parser,
5149
IGeneralConfigService configService,
@@ -84,13 +82,6 @@ public App(VBE vbe, IMessageBox messageBox,
8482

8583
_projectsEventsConnectionPoint.Advise(sink, out _projectsEventsCookie);
8684

87-
_hookActions = new Dictionary<Type, Action>
88-
{
89-
{ typeof(MouseHook), HandleMouseMessage },
90-
{ typeof(KeyboardHook), HandleKeyboardMessage },
91-
};
92-
93-
9485
UiDispatcher.Initialize();
9586
}
9687

@@ -107,29 +98,22 @@ private void State_StatusMessageUpdate(object sender, RubberduckStatusMessageEve
10798
}
10899

109100
private void _hooks_MessageReceived(object sender, HookEventArgs e)
110-
{
111-
var hookType = sender.GetType();
112-
Action action;
113-
if (_hookActions.TryGetValue(hookType, out action))
114-
{
115-
action.Invoke();
116-
}
117-
}
118-
119-
private void HandleMouseMessage()
120-
{
121-
RefreshSelection();
122-
}
123-
124-
private void HandleKeyboardMessage()
125101
{
126102
RefreshSelection();
127103
}
128104

105+
private ParserState _lastStatus;
129106
private void RefreshSelection()
130107
{
131108
_stateBar.SetSelectionText(_parser.State.FindSelectedDeclaration(_vbe.ActiveCodePane));
132-
_appMenus.EvaluateCanExecute(_parser.State);
109+
110+
var currentStatus = _parser.State.Status;
111+
if (_lastStatus != currentStatus)
112+
{
113+
_appMenus.EvaluateCanExecute(_parser.State);
114+
}
115+
116+
_lastStatus = currentStatus;
133117
}
134118

135119
private void _configService_SettingsChanged(object sender, EventArgs e)

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Reflection;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Diagnostics.CodeAnalysis;
@@ -449,12 +450,16 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
449450
foreach (var reference in declaration.References)
450451
{
451452
var proc = (dynamic)reference.Context.Parent;
452-
VBAParser.ArgsCallContext paramList;
453+
var paramList = proc ;
453454

454455
// This is to prevent throws when this statement fails:
455456
// (VBAParser.ArgsCallContext)proc.argsCall();
456-
try { paramList = (VBAParser.ArgsCallContext)proc.argsCall(); }
457-
catch { continue; }
457+
var method = ((Type) proc.GetType()).GetMethod("argsCall");
458+
if (method != null)
459+
{
460+
try { paramList = method.Invoke(proc, null); }
461+
catch { continue; }
462+
}
458463

459464
if (paramList == null) { continue; }
460465

RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.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
{
4545
var declarations = BuiltInDeclarations
4646
// note: these *should* be functions, but somehow they're not defined as such
47-
.Where(item => _tokens.Any(token => item.References.Any() && (item.IdentifierName == token || item.IdentifierName == "_B_var_" + token)));
47+
.Where(item => _tokens.Any(token => (item.IdentifierName == token || item.IdentifierName == "_B_var_" + token)) && item.References.Any());
4848

4949
return declarations.SelectMany(declaration => declaration.References
5050
.Select(item => new UntypedFunctionUsageInspectionResult(this, string.Format(Description, declaration.IdentifierName), item.QualifiedModuleName, item.Context)));

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2121
var issues = from item in UserDeclarations
2222
where (item.DeclarationType == DeclarationType.Variable
2323
|| item.DeclarationType == DeclarationType.Constant
24-
|| item.DeclarationType == DeclarationType.Parameter)
24+
|| (item.DeclarationType == DeclarationType.Parameter && !item.IsArray()))
2525
&& !item.IsTypeSpecified()
2626
select new VariableTypeNotDeclaredInspectionResult(this, item);
2727

RetailCoder.VBE/UI/Command/MenuItems/RubberduckCommandBar.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private void _statusButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
4141

4242
public void SetStatusText(string value = null)
4343
{
44+
Debug.WriteLine(string.Format("RubberduckCommandBar status text changes to '{0}'.", value));
4445
UiDispatcher.Invoke(() => _statusButton.Caption = value ?? RubberduckUI.ResourceManager.GetString("ParserState_" + _state.Status));
4546
}
4647

@@ -50,6 +51,7 @@ public void SetSelectionText(Declaration declaration)
5051
{
5152
var selection = _vbe.ActiveCodePane.GetSelection();
5253
SetSelectionText(selection);
54+
_selectionButton.TooltipText = _selectionButton.Caption;
5355
}
5456
else if (declaration != null && !declaration.IsBuiltIn && declaration.DeclarationType != DeclarationType.Class && declaration.DeclarationType != DeclarationType.Module)
5557
{
@@ -58,6 +60,9 @@ public void SetSelectionText(Declaration declaration)
5860
declaration.QualifiedSelection.Selection,
5961
declaration.IdentifierName,
6062
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType));
63+
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
64+
? _selectionButton.Caption
65+
: declaration.DescriptionString;
6166
}
6267
else if (declaration != null)
6368
{
@@ -67,6 +72,9 @@ public void SetSelectionText(Declaration declaration)
6772
declaration.IdentifierName,
6873
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType),
6974
selection.Selection);
75+
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
76+
? _selectionButton.Caption
77+
: declaration.DescriptionString;
7078
}
7179
}
7280

RetailCoder.VBE/UI/Command/Refactorings/FormDesignerRefactorRenameCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ private Declaration GetTarget()
5959
}
6060

6161
return _state.AllUserDeclarations
62-
.FirstOrDefault(item => item.IdentifierName == control.Name &&
63-
item.ComponentName == Vbe.SelectedVBComponent.Name &&
64-
Vbe.ActiveVBProject.HelpFile == item.ProjectId);
62+
.FirstOrDefault(item => item.DeclarationType == DeclarationType.Control
63+
&& Vbe.ActiveVBProject.HelpFile == item.ProjectId
64+
&& item.ComponentName == Vbe.SelectedVBComponent.Name
65+
&& item.IdentifierName == control.Name);
6566
}
6667
}
6768

0 commit comments

Comments
 (0)