private void doSaveDocument(@NotNull final Document document)
      throws IOException, SaveVetoException {
    VirtualFile file = getFile(document);

    if (file == null
        || file instanceof LightVirtualFile
        || file.isValid() && !isFileModified(file)) {
      removeFromUnsaved(document);
      return;
    }

    if (file.isValid() && needsRefresh(file)) {
      file.refresh(false, false);
      if (!myUnsavedDocuments.contains(document)) return;
    }

    for (FileDocumentSynchronizationVetoer vetoer :
        Extensions.getExtensions(FileDocumentSynchronizationVetoer.EP_NAME)) {
      if (!vetoer.maySaveDocument(document)) {
        throw new SaveVetoException();
      }
    }

    final AccessToken token =
        ApplicationManager.getApplication().acquireWriteActionLock(getClass());
    try {
      doSaveDocumentInWriteAction(document, file);
    } finally {
      token.finish();
    }
  }
Exemplo n.º 2
0
 public static void refreshFiles(Project project, HashSet<FilePath> paths) {
   for (FilePath path : paths) {
     VirtualFile vFile = path.getVirtualFile();
     if (vFile != null) {
       if (vFile.isDirectory()) {
         markFileAsDirty(project, vFile);
       } else {
         vFile.refresh(true, vFile.isDirectory());
       }
     }
   }
 }