locked
DocumentOpening RRS feed

  • Question

  • Hello,

    I created macro in Visual Studio 2008 (VC++) in EnvironmentEvents module, which handles DocumentEvents.DocumentOpening event. In some cases I would like to suppress the default behaviour of the Visual Studio, which is opening the document. Is it possible? Something like:

    Public Sub DocumentEvents_DocumentOpening(ByVal documentPath As String, ByVal isReadOnly As Boolean) Handles DocumentEvents.DocumentOpening
        If SomeFunction(documentPath) Then
            ' This is my wish:
            DTE.Document.CancelEvent()
        EndIf
    End Sub


    Monday, February 13, 2012 11:22 AM

Answers

  • Hi Jaroslav,

    Unfortunately, this isn't possible. The VC++ project system handles the dblclick (UIHWNDCMDID_DoubleClick) and enter key (UIHWNDCMDID_EnterKey) by directly calling into the IVsUIShellOpenDocument::OpenStandardEditor, and when this fails the hresult bubbles up to the solution explorer toolwindow and handled. There aren't any generic hooks into the error dialog itself, and we don't have a mechanism to intercept these particular commands.

    In some instances a priority command target, or even the CommandEvents.BeforeExecute even can be used to intercept commands, but these are typically issued via menu item. And even then, if the context menu in question is the solution explorer (or the underlying project systems), the underlying project system is going to get first crack at these commands.

    In order to avoid the error dialog in question in this scenario, you would need to either implement your own custom project type, or try and aggregate/subtype the C++ project system. And unfortunately, the C++ project system doesn't support subtyping like VB and C# do.

    Not exactly the answer you were probably looking for, but that's pretty much the answer :-(

    Sincerely,


    Ed Dore

    Tuesday, February 28, 2012 11:47 PM

All replies

  • yes , you can do this. you can also refer to this link:http://64.4.10.31/en-us/library/envdte.documenteventsclass.documentopening(v=vs.100).aspx
    Wednesday, February 15, 2012 3:30 AM
  • Hi Jaroslav,

    I don't think you can override the native fuction of Opening document. The workaround you can try is to handle the Document Opened event and close the document using DTE automation.

    Regards,

    yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, February 20, 2012 8:06 AM
  • The problem is when document on "documentPath" does not exist, so the Visual Studio shows annoying "file not found" message. It is possible when file mentioned in *.vcproj file is missing on the filesystem, so it is possible to double-click it in "Solution Explorer". I would like to check in DocumentOpening event its exitency and if it does not exists to cancel opening event. Simply: to stop Visual Studio trying opening the document.
    Monday, February 20, 2012 3:41 PM
  • Hi Jaroslav

    Thank you for your update,

    I'm doing some research on this issue and I will get it back to you asap.

    Thank you for your understanding.

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 21, 2012 3:28 AM
  • Hi Jaroslav,

    Unfortunately, this isn't possible. The VC++ project system handles the dblclick (UIHWNDCMDID_DoubleClick) and enter key (UIHWNDCMDID_EnterKey) by directly calling into the IVsUIShellOpenDocument::OpenStandardEditor, and when this fails the hresult bubbles up to the solution explorer toolwindow and handled. There aren't any generic hooks into the error dialog itself, and we don't have a mechanism to intercept these particular commands.

    In some instances a priority command target, or even the CommandEvents.BeforeExecute even can be used to intercept commands, but these are typically issued via menu item. And even then, if the context menu in question is the solution explorer (or the underlying project systems), the underlying project system is going to get first crack at these commands.

    In order to avoid the error dialog in question in this scenario, you would need to either implement your own custom project type, or try and aggregate/subtype the C++ project system. And unfortunately, the C++ project system doesn't support subtyping like VB and C# do.

    Not exactly the answer you were probably looking for, but that's pretty much the answer :-(

    Sincerely,


    Ed Dore

    Tuesday, February 28, 2012 11:47 PM
  • Dear Ed,

    I suspected this, thanks for your answer. 

    Regards,

    Jaroslav

    Wednesday, March 21, 2012 3:22 PM