问题
I have succesfuly created custom single view editor in my VSPackage. One of many things I had to cope with was reacting to situation when edited file was changed outside Visual Studio - "standard" editors in Visual Studio display dialog with options like "yes", "yes to all" (reload content) etc., so if more files had changed, only one dialog is displayed.
However, the only thing I can do in my VSPackage so far is display custom dialog when the file had changed. It is not pretty - when file edited in my editor changed along with some others, there will be two completely different dialogs displayed to the user.
So the question is - is there any way how to invoke "standard" Visual Studio "file changed outside VS" dialog for my file?
回答1:
Sounds like you are using the IVSFileChangeEx interface.
This blog post might be almost what you're looking for. Normally this is used for checking to see if a file can be edited, or reloaded and will provide a file dialog prompt to (check-out or reload).
This uses the IVsQueryEditQuerySave2 interface. You probably want to call DeclareReloadableFile
, which will "States that a file will be reloaded if it changes on disk."
private bool CanEditFile()
{
// --- Check the status of the recursion guard
if (_GettingCheckoutStatus) return false;
try
{
_GettingCheckoutStatus = true;
IVsQueryEditQuerySave2 queryEditQuerySave =
(IVsQueryEditQuerySave2)GetService(typeof(SVsQueryEditQuerySave));
// ---Now call the QueryEdit method to find the edit status of this file
string[] documents = { _FileName };
uint result;
uint outFlags;
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))
{
return true;
}
}
finally
{
_GettingCheckoutStatus = false;
}
return false;
}
来源:https://stackoverflow.com/questions/10413086/invoking-standard-file-changed-outside-visual-studio-dialog