Invoking standard “File changed outside Visual Studio” dialog

不羁岁月 提交于 2019-12-11 06:48:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!