Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4268 from mansellan/3949
Fix the leaky event sink for VB6 commandbars
- Loading branch information
Showing
15 changed files
with
205 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Rubberduck.VBEEditor/SafeComWrappers/Abstract/IComIndexedProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract | ||
{ | ||
public interface IComIndexedProperty<out TItem> | ||
{ | ||
TItem this[object index] { get; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Rubberduck.VBEEditor/SafeComWrappers/Abstract/IEventSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract | ||
{ | ||
public interface IEventSource<out TEventSource> | ||
{ | ||
TEventSource EventSource { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/ICommandBarButtonEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract | ||
{ | ||
public interface ICommandBarButtonEvents : ISafeComWrapper, IEquatable<ICommandBarButtonEvents> | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/ICommandBarEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract | ||
{ | ||
public interface ICommandBarEvents : ISafeComWrapper, IComIndexedProperty<ICommandBarButtonEvents>, IEquatable<ICommandBarEvents> | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Rubberduck.VBEditor.VB6/SafeComWrappers/VB/CommandBarButtonEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
using VB = Microsoft.Vbe.Interop.VB6; | ||
|
||
namespace Rubberduck.VBEditor.SafeComWrappers.VB6 | ||
{ | ||
public class CommandBarButtonEvents : SafeComWrapper<VB.CommandBarEvents>, ICommandBarButtonEvents, IEventSource<VB.CommandBarEvents> | ||
{ | ||
public CommandBarButtonEvents(VB.CommandBarEvents target, bool rewrapping = false) | ||
: base(target, rewrapping) | ||
{ | ||
} | ||
|
||
// 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) | ||
{ | ||
return IsEqualIfNull(other) || (other != null && ReferenceEquals(other.Target, Target)); | ||
} | ||
|
||
public bool Equals(ICommandBarButtonEvents other) | ||
{ | ||
return Equals(other as SafeComWrapper<VB.CommandBarEvents>); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return IsWrappingNullReference ? 0 : Target.GetHashCode(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Rubberduck.VBEditor.VB6/SafeComWrappers/VB/CommandBarEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
using VB = Microsoft.Vbe.Interop.VB6; | ||
|
||
// ReSharper disable once CheckNamespace - Special dispensation due to conflicting file vs namespace priorities | ||
namespace Rubberduck.VBEditor.SafeComWrappers.VB6 | ||
{ | ||
public class CommandBarEvents : SafeComWrapper<VB.Events>, ICommandBarEvents | ||
{ | ||
public CommandBarEvents(VB.Events target, bool rewrapping = false) | ||
: base(target, rewrapping) | ||
{ | ||
} | ||
|
||
public ICommandBarButtonEvents this[object button] => new CommandBarButtonEvents(IsWrappingNullReference ? null : Target.CommandBarEvents[button]); | ||
|
||
public override bool Equals(ISafeComWrapper<VB.Events> other) | ||
{ | ||
return IsEqualIfNull(other) || (other != null && ReferenceEquals(other.Target, Target)); | ||
} | ||
|
||
public bool Equals(ICommandBarEvents other) | ||
{ | ||
return Equals(other as SafeComWrapper<VB.Events>); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return IsWrappingNullReference ? 0 : Target.GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
using VB = Microsoft.Vbe.Interop.VB6; | ||
|
||
// ReSharper disable once CheckNamespace - Special dispensation due to conflicting file vs namespace priorities | ||
namespace Rubberduck.VBEditor.SafeComWrappers.VB6 | ||
{ | ||
public class Events : SafeComWrapper<VB.Events>, IEvents | ||
{ | ||
public Events(VB.Events target, bool rewrapping = false) | ||
: base(target, rewrapping) | ||
{ | ||
} | ||
|
||
public ICommandBarEvents CommandBarEvents => new CommandBarEvents(IsWrappingNullReference ? null : Target, true); | ||
|
||
public override bool Equals(ISafeComWrapper<VB.Events> other) | ||
{ | ||
return IsEqualIfNull(other) || (other != null && ReferenceEquals(other.Target, Target)); | ||
} | ||
|
||
public bool Equals(IEvents other) | ||
{ | ||
return Equals(other as SafeComWrapper<VB.Events>); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return IsWrappingNullReference ? 0 : Target.GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters