in vsintegration/src/FSharp.ProjectSystem.PropertyPages/DesignFramework/SourceCodeControlManager.vb [152:260]
Public Shared Function QueryEditableFiles(ByVal sp As IServiceProvider, ByVal files As Collections.Generic.List(Of String), ByVal throwOnFailure As Boolean, ByVal checkOnly As Boolean, ByRef fileReloaded As Boolean, Optional ByVal allowInMemoryEdits As Boolean = True, Optional ByVal allowFileReload As Boolean = True) As Boolean
If sp Is Nothing Then
Throw New ArgumentNullException("sp")
End If
If files Is Nothing Then
Throw New ArgumentNullException("files")
End If
If files.Count = 0 Then
Return True
End If
fileReloaded = False
Dim qEdit2 As IVsQueryEditQuerySave2
qEdit2 = TryCast(sp.GetService(GetType(SVsQueryEditQuerySave)), IVsQueryEditQuerySave2)
If qEdit2 IsNot Nothing Then
Dim filesToCheckOut(files.Count - 1) As String
files.CopyTo(filesToCheckOut, 0)
Dim editVerdict As UInteger
Dim result As UInteger
Dim rgrf(files.Count - 1) As UInteger
Dim flags As UInteger = 0
If checkOnly Then flags = flags Or CUInt(Microsoft.VisualStudio.Shell.Interop.tagVSQueryEditFlags.QEF_ReportOnly)
If Not allowInMemoryEdits Then flags = flags Or CUInt(Microsoft.VisualStudio.Shell.Interop.tagVSQueryEditFlags.QEF_DisallowInMemoryEdits)
Dim hr As Integer = qEdit2.QueryEditFiles(flags, filesToCheckOut.Length, filesToCheckOut, rgrf, Nothing, editVerdict, result)
VSErrorHandler.ThrowOnFailure(hr)
Dim success As Boolean = (editVerdict = CUInt(tagVSQueryEditResult.QER_EditOK))
If (result And tagVSQueryEditResultFlags2.QER_Reloaded) = tagVSQueryEditResultFlags2.QER_Reloaded Then
fileReloaded = True
End If
If success AndAlso (allowFileReload OrElse Not fileReloaded) Then
Return True
Else
If throwOnFailure Then
If Not allowFileReload AndAlso fileReloaded Then
Throw New System.ComponentModel.Design.CheckoutException(SR.GetString(SR.DFX_OneOrMoreFilesReloaded))
ElseIf ((result And CUInt(tagVSQueryEditResultFlags.QER_CheckoutCanceledOrFailed)) <> 0) Then
Throw System.ComponentModel.Design.CheckoutException.Canceled
Else
Throw New System.ComponentModel.Design.CheckoutException(SR.GetString(SR.DFX_UnableToCheckout))
End If
Else
Return False
End If
End If
Else
Dim result As Integer
Dim success As Integer
Dim txtManager As Microsoft.VisualStudio.TextManager.Interop.IVsTextManager = _
TryCast(sp.GetService(GetType(Microsoft.VisualStudio.TextManager.Interop.VsTextManagerClass)), Microsoft.VisualStudio.TextManager.Interop.IVsTextManager)
If txtManager IsNot Nothing Then
For Each fileName As String In files
If checkOnly Then
Dim nonEditable As Integer
VSErrorHandler.ThrowOnFailure(txtManager.GetBufferSccStatus2(fileName, nonEditable, result))
If nonEditable <> 0 Then
success = 1
Else
success = 0
End If
Else
VSErrorHandler.ThrowOnFailure(txtManager.AttemptToCheckOutBufferFromScc2(fileName, success, result))
End If
If (result And tagVSQueryEditResultFlags2.QER_Reloaded) = tagVSQueryEditResultFlags2.QER_Reloaded Then
fileReloaded = True
End If
If success = 0 Then
If throwOnFailure Then
If (result And CUInt(tagVSQueryEditResultFlags.QER_CheckoutCanceledOrFailed)) <> 0 Then
Throw System.ComponentModel.Design.CheckoutException.Canceled
Else
Throw New System.ComponentModel.Design.CheckoutException(SR.GetString(SR.DFX_UnableToCheckout))
End If
Else
Return False
End If
End If
Next
Return True
Else
Debug.Fail("Failed to get both IVsQueryEditQuerySave2 and IVsTextManager services - can't check out file!")
End If
End If
Return True
End Function