Skip to content

Commit 6dd9e37

Browse files
committed
Merge pull request #1144 from rubberduck-vba/CodeExplorer
merge latest changes
2 parents f204a23 + 151bfad commit 6dd9e37

26 files changed

+379
-369
lines changed

RetailCoder.VBE/App.cs

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.Globalization;
35
using System.Linq;
6+
using System.Runtime.InteropServices.ComTypes;
47
using System.Threading.Tasks;
58
using System.Windows.Forms;
69
using Microsoft.Vbe.Interop;
710
using NLog;
8-
using Rubberduck.AutoSave;
911
using Rubberduck.Common;
10-
using Rubberduck.Inspections;
1112
using Rubberduck.Parsing;
1213
using Rubberduck.Parsing.VBA;
1314
using Rubberduck.Settings;
1415
using Rubberduck.SmartIndenter;
1516
using Rubberduck.UI;
1617
using Rubberduck.UI.Command.MenuItems;
17-
using Rubberduck.UI.ParserErrors;
1818
using Rubberduck.VBEditor.Extensions;
1919
using Infralution.Localization.Wpf;
20+
using Rubberduck.Common.Dispatch;
2021

2122
namespace Rubberduck
2223
{
@@ -36,6 +37,12 @@ public class App : IDisposable
3637

3738
private Configuration _config;
3839

40+
private readonly IConnectionPoint _projectsEventsConnectionPoint;
41+
private readonly int _projectsEventsCookie;
42+
43+
private readonly IDictionary<VBComponents, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
44+
new Dictionary<VBComponents, Tuple<IConnectionPoint, int>>();
45+
3946
public App(VBE vbe, IMessageBox messageBox,
4047
IRubberduckParser parser,
4148
IGeneralConfigService configService,
@@ -60,9 +67,99 @@ public App(VBE vbe, IMessageBox messageBox,
6067
_parser.State.StateChanged += Parser_StateChanged;
6168
_stateBar.Refresh += _stateBar_Refresh;
6269

70+
var sink = new VBProjectsEventsSink();
71+
var connectionPointContainer = (IConnectionPointContainer)_vbe.VBProjects;
72+
Guid interfaceId = typeof (_dispVBProjectsEvents).GUID;
73+
connectionPointContainer.FindConnectionPoint(ref interfaceId, out _projectsEventsConnectionPoint);
74+
75+
sink.ProjectAdded += sink_ProjectAdded;
76+
sink.ProjectRemoved += sink_ProjectRemoved;
77+
sink.ProjectActivated += sink_ProjectActivated;
78+
sink.ProjectRenamed += sink_ProjectRenamed;
79+
80+
_projectsEventsConnectionPoint.Advise(sink, out _projectsEventsCookie);
81+
6382
UiDispatcher.Initialize();
6483
}
6584

85+
void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
86+
{
87+
Tuple<IConnectionPoint, int> value;
88+
if (_componentsEventsConnectionPoints.TryGetValue(e.Item.VBComponents, out value))
89+
{
90+
value.Item1.Unadvise(value.Item2);
91+
_componentsEventsConnectionPoints.Remove(e.Item.VBComponents);
92+
93+
_parser.State.ClearDeclarations(e.Item);
94+
}
95+
}
96+
97+
void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
98+
{
99+
var connectionPointContainer = (IConnectionPointContainer)e.Item.VBComponents;
100+
Guid interfaceId = typeof(_dispVBComponentsEvents).GUID;
101+
102+
IConnectionPoint connectionPoint;
103+
connectionPointContainer.FindConnectionPoint(ref interfaceId, out connectionPoint);
104+
105+
var sink = new VBComponentsEventsSink();
106+
sink.ComponentActivated += sink_ComponentActivated;
107+
sink.ComponentAdded += sink_ComponentAdded;
108+
sink.ComponentReloaded += sink_ComponentReloaded;
109+
sink.ComponentRemoved += sink_ComponentRemoved;
110+
sink.ComponentRenamed += sink_ComponentRenamed;
111+
sink.ComponentSelected += sink_ComponentSelected;
112+
113+
int cookie;
114+
connectionPoint.Advise(sink, out cookie);
115+
116+
_componentsEventsConnectionPoints.Add(e.Item.VBComponents, Tuple.Create(connectionPoint, cookie));
117+
_parser.State.OnParseRequested();
118+
}
119+
120+
void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
121+
{
122+
// do something?
123+
}
124+
125+
void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBComponent> e)
126+
{
127+
_parser.State.ClearDeclarations(e.Item);
128+
_parser.State.OnParseRequested(e.Item);
129+
}
130+
131+
void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent> e)
132+
{
133+
_parser.State.ClearDeclarations(e.Item);
134+
}
135+
136+
void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent> e)
137+
{
138+
_parser.State.ClearDeclarations(e.Item);
139+
_parser.State.OnParseRequested(e.Item);
140+
}
141+
142+
void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e)
143+
{
144+
_parser.State.OnParseRequested(e.Item);
145+
}
146+
147+
void sink_ComponentActivated(object sender, DispatcherEventArgs<VBComponent> e)
148+
{
149+
// do something?
150+
}
151+
152+
void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProject> e)
153+
{
154+
_parser.State.ClearDeclarations(e.Item);
155+
_parser.State.OnParseRequested();
156+
}
157+
158+
void sink_ProjectActivated(object sender, DispatcherEventArgs<VBProject> e)
159+
{
160+
// do something?
161+
}
162+
66163
private Keys _firstStepHotKey;
67164
private bool _isAwaitingTwoStepKey;
68165
private bool _skipKeyUp;
@@ -156,7 +253,7 @@ public void Startup()
156253
Task.Delay(1000).ContinueWith(t =>
157254
{
158255
_parser.State.AddBuiltInDeclarations(_vbe.HostApplication());
159-
_parser.State.OnParseRequested();
256+
//_parser.State.OnParseRequested();
160257
});
161258

162259
//_hooks.AddHook(new LowLevelKeyboardHook(_vbe));
@@ -197,11 +294,17 @@ private void LoadConfig()
197294

198295
public void Dispose()
199296
{
200-
//_hooks.MessageReceived -= hooks_MessageReceived;
201297
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
202298
_parser.State.StateChanged -= Parser_StateChanged;
203299
_autoSave.Dispose();
204300

301+
_projectsEventsConnectionPoint.Unadvise(_projectsEventsCookie);
302+
foreach (var item in _componentsEventsConnectionPoints)
303+
{
304+
item.Value.Item1.Unadvise(item.Value.Item2);
305+
}
306+
307+
//_hooks.MessageReceived -= hooks_MessageReceived;
205308
//_hooks.Dispose();
206309
}
207310
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Rubberduck.Common.Dispatch
4+
{
5+
public class DispatcherEventArgs<T> : EventArgs
6+
where T : class
7+
{
8+
private readonly T _item;
9+
10+
public DispatcherEventArgs(T item)
11+
{
12+
_item = item;
13+
}
14+
15+
public T Item { get { return _item; } }
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Rubberduck.Common.Dispatch
2+
{
3+
public class DispatcherRenamedEventArgs<T> : DispatcherEventArgs<T>
4+
where T : class
5+
{
6+
private readonly string _oldName;
7+
8+
public DispatcherRenamedEventArgs(T item, string oldName)
9+
: base(item)
10+
{
11+
_oldName = oldName;
12+
}
13+
14+
public string OldName { get { return _oldName; } }
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Microsoft.Vbe.Interop;
3+
4+
namespace Rubberduck.Common.Dispatch
5+
{
6+
public class ReferencesEventsSink : _dispReferencesEvents
7+
{
8+
public event EventHandler<DispatcherEventArgs<Reference>> ReferenceAdded;
9+
public void ItemAdded(Reference Reference)
10+
{
11+
OnDispatch(ReferenceAdded, Reference);
12+
}
13+
14+
public event EventHandler<DispatcherEventArgs<Reference>> ReferenceRemoved;
15+
public void ItemRemoved(Reference Reference)
16+
{
17+
OnDispatch(ReferenceRemoved, Reference);
18+
}
19+
20+
private void OnDispatch(EventHandler<DispatcherEventArgs<Reference>> dispatched, Reference reference)
21+
{
22+
var handler = dispatched;
23+
if (handler != null)
24+
{
25+
handler.Invoke(this, new DispatcherEventArgs<Reference>(reference));
26+
}
27+
}
28+
}
29+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using Microsoft.Vbe.Interop;
3+
4+
namespace Rubberduck.Common.Dispatch
5+
{
6+
public class VBComponentsEventsSink : _dispVBComponentsEvents
7+
{
8+
public event EventHandler<DispatcherEventArgs<VBComponent>> ComponentAdded;
9+
public void ItemAdded(VBComponent VBComponent)
10+
{
11+
OnDispatch(ComponentAdded, VBComponent);
12+
}
13+
14+
public event EventHandler<DispatcherEventArgs<VBComponent>> ComponentRemoved;
15+
public void ItemRemoved(VBComponent VBComponent)
16+
{
17+
OnDispatch(ComponentRemoved, VBComponent);
18+
}
19+
20+
public event EventHandler<DispatcherRenamedEventArgs<VBComponent>> ComponentRenamed;
21+
public void ItemRenamed(VBComponent VBComponent, string OldName)
22+
{
23+
var handler = ComponentRenamed;
24+
if (handler != null)
25+
{
26+
handler.Invoke(this, new DispatcherRenamedEventArgs<VBComponent>(VBComponent, OldName));
27+
}
28+
}
29+
30+
public event EventHandler<DispatcherEventArgs<VBComponent>> ComponentSelected;
31+
public void ItemSelected(VBComponent VBComponent)
32+
{
33+
OnDispatch(ComponentSelected, VBComponent);
34+
}
35+
36+
public event EventHandler<DispatcherEventArgs<VBComponent>> ComponentActivated;
37+
public void ItemActivated(VBComponent VBComponent)
38+
{
39+
OnDispatch(ComponentActivated, VBComponent);
40+
}
41+
42+
public event EventHandler<DispatcherEventArgs<VBComponent>> ComponentReloaded;
43+
public void ItemReloaded(VBComponent VBComponent)
44+
{
45+
OnDispatch(ComponentReloaded, VBComponent);
46+
}
47+
48+
private void OnDispatch(EventHandler<DispatcherEventArgs<VBComponent>> dispatched, VBComponent component)
49+
{
50+
var handler = dispatched;
51+
if (handler != null)
52+
{
53+
handler.Invoke(this, new DispatcherEventArgs<VBComponent>(component));
54+
}
55+
}
56+
}
57+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using Microsoft.Vbe.Interop;
3+
4+
namespace Rubberduck.Common.Dispatch
5+
{
6+
public class VBProjectsEventsSink : _dispVBProjectsEvents
7+
{
8+
public event EventHandler<DispatcherEventArgs<VBProject>> ProjectAdded;
9+
public void ItemAdded(VBProject VBProject)
10+
{
11+
OnDispatch(ProjectAdded, VBProject);
12+
}
13+
14+
public event EventHandler<DispatcherEventArgs<VBProject>> ProjectRemoved;
15+
public void ItemRemoved(VBProject VBProject)
16+
{
17+
OnDispatch(ProjectRemoved, VBProject);
18+
}
19+
20+
public event EventHandler<DispatcherRenamedEventArgs<VBProject>> ProjectRenamed;
21+
public void ItemRenamed(VBProject VBProject, string OldName)
22+
{
23+
var handler = ProjectRenamed;
24+
if (handler != null)
25+
{
26+
handler.Invoke(this, new DispatcherRenamedEventArgs<VBProject>(VBProject, OldName));
27+
}
28+
}
29+
30+
public event EventHandler<DispatcherEventArgs<VBProject>> ProjectActivated;
31+
public void ItemActivated(VBProject VBProject)
32+
{
33+
OnDispatch(ProjectActivated, VBProject);
34+
}
35+
36+
private void OnDispatch(EventHandler<DispatcherEventArgs<VBProject>> dispatched, VBProject project)
37+
{
38+
var handler = dispatched;
39+
if (handler != null)
40+
{
41+
handler.Invoke(this, new DispatcherEventArgs<VBProject>(project));
42+
}
43+
}
44+
}
45+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Rubberduck.Common.Dispatch
8+
{
9+
public class VBProjectsEventsWrapper
10+
{
11+
12+
}
13+
}

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3131
where !item.IsInspectionDisabled(AnnotationName)
3232
&& ProcedureTypes.Contains(item.DeclarationType)
3333
&& !item.IsTypeSpecified()
34-
let issue = new {Declaration = item, QualifiedContext = new QualifiedContext<ParserRuleContext>(item.QualifiedName, item.Context)}
35-
select new ImplicitVariantReturnTypeInspectionResult(this, string.Format(Description, issue.Declaration.IdentifierName), issue.QualifiedContext);
34+
select new ImplicitVariantReturnTypeInspectionResult(this, item);
3635
return issues;
3736
}
3837
}

0 commit comments

Comments
 (0)