@@ -36,11 +36,25 @@ internal DocumentEvents()
3636 /// <summary>
3737 /// Fires after the document was opened in the editor.
3838 /// </summary>
39+ /// <remarks>
40+ /// The event is called for documents in the document well but also
41+ /// for project files and may also be called for solution files.<br/>
42+ /// The document name may also be a special (generated name) in the form of
43+ /// RDT_PROJ_MK::{A2FE74E1-B743-11d0-AE1A-00A0C90FFFC3} that is used by
44+ /// Visual Studio for the 'miscellaneous files' project
45+ /// </remarks>
3946 public event Action < string > ? Opened ;
4047
4148 /// <summary>
42- /// Fires after the document was closed.s
49+ /// Fires after the document was closed.
4350 /// </summary>
51+ /// <remarks>
52+ /// The event is called for documents in the document well but also
53+ /// for project files and may also be called for solution files. <br/>
54+ /// The document name may also be a special (generated name) in the form of
55+ /// RDT_PROJ_MK::{A2FE74E1-B743-11d0-AE1A-00A0C90FFFC3} that is used by
56+ /// Visual Studio for the 'miscellaneous files' project
57+ /// </remarks>
4458 public event Action < string > ? Closed ;
4559
4660 /// <summary>
@@ -55,24 +69,37 @@ internal DocumentEvents()
5569
5670 int IVsRunningDocTableEvents . OnAfterFirstDocumentLock ( uint docCookie , uint dwRDTLockType , uint dwReadLocksRemaining , uint dwEditLocksRemaining )
5771 {
58- if ( Opened != null )
72+ // Please note that this event is called multiple times when a document
73+ // is opened for editing.
74+ // This code tries to only call the Open Event once
75+ //
76+ if ( dwEditLocksRemaining == 1 && dwReadLocksRemaining == 0 )
5977 {
60- string file = _rdt . GetDocumentInfo ( docCookie ) . Moniker ;
61- Opened . Invoke ( file ) ;
78+ if ( Opened != null )
79+ {
80+ string file = _rdt . GetDocumentInfo ( docCookie ) . Moniker ;
81+ Opened . Invoke ( file ) ;
82+ }
6283 }
6384
6485 return VSConstants . S_OK ;
6586 }
6687
6788 int IVsRunningDocTableEvents . OnBeforeLastDocumentUnlock ( uint docCookie , uint dwRDTLockType , uint dwReadLocksRemaining , uint dwEditLocksRemaining )
6889 {
69- if ( Closed != null )
90+ // Please note that this event is called multiple times when a document
91+ // is opened for editing.
92+ // This code tries to only call the Close Event once
93+ if ( dwReadLocksRemaining == 0 && dwEditLocksRemaining == 0 )
7094 {
71- string file = _rdt . GetDocumentInfo ( docCookie ) . Moniker ;
72-
73- if ( ! string . IsNullOrEmpty ( file ) )
95+ if ( Closed != null )
7496 {
75- Closed . Invoke ( file ) ;
97+ string file = _rdt . GetDocumentInfo ( docCookie ) . Moniker ;
98+
99+ if ( ! string . IsNullOrEmpty ( file ) )
100+ {
101+ Closed . Invoke ( file ) ;
102+ }
76103 }
77104 }
78105
@@ -97,7 +124,7 @@ int IVsRunningDocTableEvents.OnAfterAttributeChange(uint docCookie, uint grfAttr
97124
98125 int IVsRunningDocTableEvents . OnBeforeDocumentWindowShow ( uint docCookie , int fFirstShow , IVsWindowFrame pFrame )
99126 {
100- if ( BeforeDocumentWindowShow != null )
127+ if ( BeforeDocumentWindowShow != null && fFirstShow == 1 )
101128 {
102129 DocumentView docView = new ( pFrame ) ;
103130 BeforeDocumentWindowShow . Invoke ( docView ) ;
0 commit comments