Skip to content

Commit

Permalink
Changes following PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mansellan committed Aug 12, 2018
1 parent a0cfa89 commit 5c763f4
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 18 deletions.
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
{
public interface IEventSource<out TEventSource>
{
Expand Down
2 changes: 2 additions & 0 deletions Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IEvents.cs
Expand Up @@ -2,6 +2,8 @@

namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
{
// This interface is not included on IVBE, as it is only safe in VB6
// https://stackoverflow.com/questions/41055765/whats-the-difference-between-commandbarevents-click-and-commandbarbutton-click/41066408#41066408
public interface IEvents : ISafeComWrapper, IEquatable<IEvents>
{
ICommandBarEvents CommandBarEvents { get; }
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IVBE.cs
Expand Up @@ -19,7 +19,6 @@ public interface IVBE : ISafeComWrapper, IEquatable<IVBE>
ICodePanes CodePanes { get; }
ICommandBars CommandBars { get; }
IWindows Windows { get; }
IEvents Events { get; }
IHostApplication HostApplication();
IWindow ActiveMDIChild();
QualifiedSelection? GetActiveSelection();
Expand Down
Expand Up @@ -295,9 +295,10 @@ protected override void Dispose(bool disposing)

public override void AttachEvents()
{
using (var events = _vbe.Events)
// Cast to VB6 VBE SafeComWrapper as events are not exposed on IVBE as they are only safe to use in VB6
using (var events = ((VB6.VBE)_vbe).Events)
{
// Note - disposal of buttonEvents is handled by the base class
// Disposal of buttonEvents is handled by the base class
var buttonEvents = events.CommandBarEvents[Target] as IEventSource<VB.CommandBarEvents>;
AttachEvents(buttonEvents, this);
}
Expand Down
@@ -1,5 +1,4 @@
using System;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using VB = Microsoft.Vbe.Interop.VB6;

namespace Rubberduck.VBEditor.SafeComWrappers.VB6
Expand All @@ -11,7 +10,8 @@ public CommandBarButtonEvents(VB.CommandBarEvents target, bool rewrapping = fals
{
}

public VB.CommandBarEvents EventSource => Target;
// Explicit implementation as usage should only be from within a SafeComWrapper
VB.CommandBarEvents IEventSource<VB.CommandBarEvents>.EventSource => Target;

public override bool Equals(ISafeComWrapper<VB.CommandBarEvents> other)
{
Expand Down
Expand Up @@ -11,7 +11,7 @@ public CommandBarEvents(VB.Events target, bool rewrapping = false)
{
}

public ICommandBarButtonEvents this[object button] => IsWrappingNullReference ? new CommandBarButtonEvents(null) : new CommandBarButtonEvents(Target.CommandBarEvents[button]);
public ICommandBarButtonEvents this[object button] => new CommandBarButtonEvents(IsWrappingNullReference ? null : Target.CommandBarEvents[button]);

public override bool Equals(ISafeComWrapper<VB.Events> other)
{
Expand Down
2 changes: 1 addition & 1 deletion Rubberduck.VBEditor.VB6/SafeComWrappers/VB/Events.cs
Expand Up @@ -11,7 +11,7 @@ public Events(VB.Events target, bool rewrapping = false)
{
}

public ICommandBarEvents CommandBarEvents => new CommandBarEvents(Target);
public ICommandBarEvents CommandBarEvents => new CommandBarEvents(IsWrappingNullReference ? null : Target);

public override bool Equals(ISafeComWrapper<VB.Events> other)
{
Expand Down
4 changes: 1 addition & 3 deletions Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs
Expand Up @@ -80,9 +80,7 @@ public IWindow MainWindow
public IVBProjects VBProjects => new VBProjects(IsWrappingNullReference ? null : Target.VBProjects);

public IWindows Windows => new Windows(IsWrappingNullReference ? null : Target.Windows);

public IEvents Events => throw new NotSupportedException("Accessing the VBE.Events collection is not supported for VBA");


public override bool Equals(ISafeComWrapper<VB.VBE> other)
{
return IsEqualIfNull(other) || (other != null && other.Target.Version == Version);
Expand Down

0 comments on commit 5c763f4

Please sign in to comment.