protected virtual bool CanEditFile(string documentMoniker)
{
Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "\t**** CanEditFile called ****"));
// Check the status of the recursion guard
if(this.gettingCheckoutStatus)
{
return false;
}
try
{
// Set the recursion guard
this.gettingCheckoutStatus = true;
// Get the QueryEditQuerySave service
IVsQueryEditQuerySave2 queryEditQuerySave = (IVsQueryEditQuerySave2)this.projectMgr.GetService(typeof(SVsQueryEditQuerySave));
// Now call the QueryEdit method to find the edit status of this file
string[] documents = { documentMoniker };
uint result;
uint outFlags;
// Note that this function can popup a dialog to ask the user to checkout the file.
// When this dialog is visible, it is possible to receive other request to change
// the file and this is the reason for the recursion guard.
int hr = queryEditQuerySave.QueryEditFiles(
0, // Flags
1, // Number of elements in the array
documents, // Files to edit
null, // Input flags
null, // Input array of VSQEQS_FILE_ATTRIBUTE_DATA
out result, // result of the checkout
out outFlags // Additional flags
);
if(ErrorHandler.Succeeded(hr) && (result == (uint)tagVSQueryEditResult.QER_EditOK))
{
// In this case (and only in this case) we can return true from this function.
return true;
}
}
finally
{
this.gettingCheckoutStatus = false;
}
return false;
}