1

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?

cre8or
  • 387
  • 3
  • 10
  • http://www.hanselman.com/blog/IntroducingWorkspaceReloaderAVisualStudioAddInToSaveYourOpenFilesAcrossProjectReloads.aspx will this help ? – adt May 02 '12 at 11:55
  • You are fretting a bit too much about a corner case? You're otherwise pretty stuck, there's no event for this and no method to invoke the dialog yourself afaik. – Hans Passant May 02 '12 at 12:01
  • It's quite extensive school project, part of my bachelor's thesis - in my experience, corner cases are just the thing one might be penalized for :-) – cre8or May 02 '12 at 16:04
  • I don't know about VS specifically, but other apps I've worked this in the past were detecting this condition when they were activated (i.e. when they receive focus from somewhere else). One thing you might experiment with would be - after having written the changed file to disk - briefly setting the focus to the Windows shell and then back to VS again. That might trigger the dialog. – 500 - Internal Server Error May 07 '12 at 22:35
  • 500 - Internal Server Error: thank you for your answer, but it seems I didn't make it clear - when user opens a file in my editor in VS, it is my responsibility (as the editor provider) to handle outside-VS changes. To be more specific, there is one method (my method) that gets invoked whenever file is changed outside. Inside that method I can do anything (ignore the change, for instance). What I need is method provided by VS that would invoke its own dialog. The thing with focus would just run my own method again. – cre8or May 08 '12 at 07:04

1 Answers1

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;
}
gameweld
  • 1,319
  • 15
  • 21
  • I am sorry, I can't get it to work. How does that cooperate with IVsFileChangeEx? I tried calling the QueryEditFiles() and QuerySaveFile() methods when the file changed outside VS, return code was ok, but no dialog appeared. I am not sure that IVsQueryEditQuerySave2 has the capability of bringing up the popup I want. – cre8or May 20 '12 at 13:05
  • This may only be for files under source control, sorry. – gameweld May 23 '12 at 15:36