File tree Expand file tree Collapse file tree 3 files changed +72
-6
lines changed
Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract
Rubberduck.VBEditor.VB6/SafeComWrappers/VB
Rubberduck.VBEditor.VBA/SafeComWrappers/VB Expand file tree Collapse file tree 3 files changed +72
-6
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ public interface ICodeModule : ISafeComWrapper, IEquatable<ICodeModule>
6
6
{
7
7
IVBE VBE { get ; }
8
8
IVBComponent Parent { get ; }
9
+ /// <summary>
10
+ /// Returns the code pane associated with the cod module.
11
+ /// Accessing this property will open the code pane if it is not open already.
12
+ /// </summary>
9
13
ICodePane CodePane { get ; }
10
14
int CountOfDeclarationLines { get ; }
11
15
int CountOfLines { get ; }
Original file line number Diff line number Diff line change @@ -29,11 +29,42 @@ public VBE(VB.VBE target, bool rewrapping = false)
29
29
public ICodePane ActiveCodePane
30
30
{
31
31
get => new CodePane ( IsWrappingNullReference ? null : Target . ActiveCodePane ) ;
32
- set
32
+ set => SetActiveCodePane ( value ) ;
33
+ }
34
+
35
+ private void SetActiveCodePane ( ICodePane codePane )
36
+ {
37
+ if ( IsWrappingNullReference || ! ( codePane is CodePane pane ) )
33
38
{
34
- if ( ! IsWrappingNullReference )
39
+ return ;
40
+ }
41
+
42
+ Target . ActiveCodePane = pane . Target ;
43
+ ForceFocus ( codePane ) ;
44
+ }
45
+
46
+ private void ForceFocus ( ICodePane codePane )
47
+ {
48
+ if ( codePane . IsWrappingNullReference )
49
+ {
50
+ return ;
51
+ }
52
+
53
+ codePane . Show ( ) ;
54
+
55
+ using ( var mainWindow = MainWindow )
56
+ using ( var window = codePane . Window )
57
+ {
58
+ var mainWindowHandle = mainWindow . Handle ( ) ;
59
+ var handle = mainWindow . Handle ( ) . FindChildWindow ( window . Caption ) ;
60
+
61
+ if ( handle != IntPtr . Zero )
62
+ {
63
+ NativeMethods . ActivateWindow ( handle , mainWindowHandle ) ;
64
+ }
65
+ else
35
66
{
36
- Target . ActiveCodePane = ( VB . CodePane ) value . Target ;
67
+ _logger . Debug ( "VBE.ForceFocus() failed to get a handle on the MainWindow." ) ;
37
68
}
38
69
}
39
70
}
Original file line number Diff line number Diff line change @@ -31,11 +31,42 @@ public VBE(VB.VBE target, bool rewrapping = false)
31
31
public ICodePane ActiveCodePane
32
32
{
33
33
get => new CodePane ( IsWrappingNullReference ? null : Target . ActiveCodePane ) ;
34
- set
34
+ set => SetActiveCodePane ( value ) ;
35
+ }
36
+
37
+ private void SetActiveCodePane ( ICodePane codePane )
38
+ {
39
+ if ( IsWrappingNullReference || ! ( codePane is CodePane pane ) )
35
40
{
36
- if ( ! IsWrappingNullReference )
41
+ return ;
42
+ }
43
+
44
+ Target . ActiveCodePane = pane . Target ;
45
+ ForceFocus ( codePane ) ;
46
+ }
47
+
48
+ private void ForceFocus ( ICodePane codePane )
49
+ {
50
+ if ( codePane . IsWrappingNullReference )
51
+ {
52
+ return ;
53
+ }
54
+
55
+ codePane . Show ( ) ;
56
+
57
+ using ( var mainWindow = MainWindow )
58
+ using ( var window = codePane . Window )
59
+ {
60
+ var mainWindowHandle = mainWindow . Handle ( ) ;
61
+ var handle = mainWindow . Handle ( ) . FindChildWindow ( window . Caption ) ;
62
+
63
+ if ( handle != IntPtr . Zero )
64
+ {
65
+ NativeMethods . ActivateWindow ( handle , mainWindowHandle ) ;
66
+ }
67
+ else
37
68
{
38
- Target . ActiveCodePane = ( VB . CodePane ) value . Target ;
69
+ _logger . Debug ( "VBE.ForceFocus() failed to get a handle on the MainWindow." ) ;
39
70
}
40
71
}
41
72
}
You can’t perform that action at this time.
0 commit comments