Java 类com.intellij.openapi.vfs.VirtualFileEvent 实例源码

项目:GravSupport    文件:GravLangFileEditor.java   
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
    //process only for files inside the language directory
    if (event.getFile().getParent().isDirectory() && event.getFile().getParent().getNameWithoutExtension().compareTo("languages") == 0) {
        if (GravYamlFiles.getLanguageFileType(event.getFile()) == GravYamlFiles.LangFileEditorType.LANGUAGE_FOLDER) {
            boolean present = false;
            for (VirtualFile each : getFileMap().values()) {
                if (each.getName().compareTo(event.getFile().getName()) == 0) {
                    present = true;
                    break;
                }
            }
            if (!present) {
                getFileMap().put(event.getFile().getNameWithoutExtension(), event.getFile());
                model.addLanguage(event.getFile().getNameWithoutExtension());
                editor.initTabs();
            }
        } else {
            NotificationHelper.showBaloon("Not a valid language resource name", MessageType.WARNING, project);
        }
    }
}
项目:intellij-ce-playground    文件:MovePackageAsDirectoryTest.java   
public void testMultipleClassesInOneFile() throws Exception {
  final boolean [] fileWasDeleted = new boolean[]{false};
  final VirtualFileAdapter fileAdapter = new VirtualFileAdapter() {
    @Override
    public void fileDeleted(@NotNull VirtualFileEvent event) {
      fileWasDeleted[0] = !event.getFile().isDirectory();
    }
  };
  VirtualFileManager.getInstance().addVirtualFileListener(fileAdapter);
  try {
    doTest(createAction("pack1", "target"));
  }
  finally {
    VirtualFileManager.getInstance().removeVirtualFileListener(fileAdapter);
  }
  Assert.assertFalse("Deleted instead of moved", fileWasDeleted[0]);
}
项目:intellij-ce-playground    文件:FileDocumentManagerImplTest.java   
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myReloadFromDisk = Boolean.TRUE;
  myDocumentManager.saveAllDocuments();
  long fileStamp = file.getModificationStamp();

  assertEquals("xxx", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals(file.getModificationStamp(), fileStamp);
  assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
}
项目:intellij-ce-playground    文件:CCFileDeletedListener.java   
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
  if (myProject.isDisposed() || !myProject.isOpen()) {
    return;
  }
  VirtualFile removedFile = event.getFile();
  final TaskFile taskFile = CCProjectService.getInstance(myProject).getTaskFile(removedFile);
  if (taskFile != null) {
    deleteAnswerFile(removedFile, taskFile);
    return;
  }
  Course course = CCProjectService.getInstance(myProject).getCourse();
  if (course == null) {
    return;
  }
  if (removedFile.getName().contains(EduNames.TASK)) {
    deleteTask(course, removedFile, myProject);
  }
  if (removedFile.getName().contains(EduNames.LESSON)) {
    deleteLesson(course, removedFile);
  }
}
项目:intellij-ce-playground    文件:NavigationEditor.java   
private static boolean shouldIgnore(VirtualFileEvent event) {
  String fileName = event.getFileName();
  if (NAVIGATION_FILE_NAME.equals(fileName)) {
    return true;
  }
  String pathName = event.getFile().getCanonicalPath();
  if (pathName == null) {
    return false;
  }
  for (String segment : EXCLUDED_PATH_SEGMENTS) {
    if (pathName.contains(segment)) {
      return true;
    }
  }
  return false;
}
项目:aem-ide-tooling-4-intellij    文件:ContentResourceChangeListener.java   
private void executeMake(final VirtualFileEvent event) {
        if(
            (pluginConfiguration == null || pluginConfiguration.isIncrementalBuilds())
// If no Configuration Selected which can happen when the project is not AEM / Sling based then do nothing
            && serverConnectionManager.isConfigurationSelected()
        ) {
            // Check if the file is a Java Class and if os build it
            VirtualFile file = event.getFile();
            if("java".equalsIgnoreCase(file.getExtension())) {
                //AS TODO: In order to use the Code Snell Detector this needs to be invoked in a Read Only Thread but part of the Dispatcher Thread
                ApplicationManager.getApplication().invokeLater(
                    new Runnable() {
                        @Override
                        public void run() {
                            executeMakeInUIThread(event);
                        }
                    }
                );
            }
        }
    }
项目:tools-idea    文件:MovePackageAsDirectoryTest.java   
public void testMultipleClassesInOneFile() throws Exception {
  final boolean [] fileWasDeleted = new boolean[]{false};
  final VirtualFileAdapter fileAdapter = new VirtualFileAdapter() {
    @Override
    public void fileDeleted(VirtualFileEvent event) {
      fileWasDeleted[0] = !event.getFile().isDirectory();
    }
  };
  VirtualFileManager.getInstance().addVirtualFileListener(fileAdapter);
  try {
    doTest(createAction("pack1", "target"));
  }
  finally {
    VirtualFileManager.getInstance().removeVirtualFileListener(fileAdapter);
  }
  Assert.assertFalse("Deleted instead of moved", fileWasDeleted[0]);
}
项目:tools-idea    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_ignoreEventsFromSelfOnSave() throws Exception {
  final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @NotNull
    @Override
    public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) throws IOException {
      final VirtualFile self = this;
      return new ByteArrayOutputStream() {
        @Override
        public void close() throws IOException {
          super.close();
          long oldStamp = getModificationStamp();
          setModificationStamp(newModificationStamp);
          setText(toString());
          myDocumentManager.contentsChanged(new VirtualFileEvent(requestor, self, null, oldStamp, getModificationStamp()));
        }
      };
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "xxx");
  final long stamp = document.getModificationStamp();

  myDocumentManager.saveAllDocuments();
  assertEquals(stamp, document.getModificationStamp());
}
项目:consulo    文件:FileDocumentManagerImplTest.java   
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myReloadFromDisk = Boolean.TRUE;
  myDocumentManager.saveAllDocuments();
  long fileStamp = file.getModificationStamp();

  assertEquals("xxx", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals(file.getModificationStamp(), fileStamp);
  assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
}
项目:consulo    文件:MemoryDiskConflictResolver.java   
void beforeContentChange(@Nonnull VirtualFileEvent event) {
  if (event.isFromSave()) return;

  VirtualFile file = event.getFile();
  if (!file.isValid() || hasConflict(file)) return;

  Document document = FileDocumentManager.getInstance().getCachedDocument(file);
  if (document == null || !FileDocumentManager.getInstance().isDocumentUnsaved(document)) return;

  long documentStamp = document.getModificationStamp();
  long oldFileStamp = event.getOldModificationStamp();
  if (documentStamp != oldFileStamp) {
    LOG.info("reload " + file.getName() + " from disk?");
    LOG.info("  documentStamp:" + documentStamp);
    LOG.info("  oldFileStamp:" + oldFileStamp);
    if (myConflicts.isEmpty()) {
      ApplicationManager.getApplication().invokeLater(this::processConflicts);
    }
    myConflicts.add(file);
  }
}
项目:consulo-java    文件:MovePackageAsDirectoryTest.java   
public void testMultipleClassesInOneFile() throws Exception {
  final boolean [] fileWasDeleted = new boolean[]{false};
  final VirtualFileAdapter fileAdapter = new VirtualFileAdapter() {
    @Override
    public void fileDeleted(VirtualFileEvent event) {
      fileWasDeleted[0] = !event.getFile().isDirectory();
    }
  };
  VirtualFileManager.getInstance().addVirtualFileListener(fileAdapter);
  try {
    doTest(createAction("pack1", "target"));
  }
  finally {
    VirtualFileManager.getInstance().removeVirtualFileListener(fileAdapter);
  }
  Assert.assertFalse("Deleted instead of moved", fileWasDeleted[0]);
}
项目:educational-plugin    文件:StudyProjectComponent.java   
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
  if (myProject.isDisposed()) return;
  final VirtualFile createdFile = event.getFile();
  final VirtualFile taskDir = StudyUtils.getTaskDir(createdFile);
  final Course course = StudyTaskManager.getInstance(myProject).getCourse();
  if (course == null || !EduNames.STUDY.equals(course.getCourseMode())) {
    return;
  }
  if (taskDir != null && taskDir.getName().contains(EduNames.TASK)) {
    int taskIndex = EduUtils.getIndex(taskDir.getName(), EduNames.TASK);
    final VirtualFile lessonDir = taskDir.getParent();
    if (lessonDir != null && lessonDir.getName().contains(EduNames.LESSON)) {
      int lessonIndex = EduUtils.getIndex(lessonDir.getName(), EduNames.LESSON);
      List<Lesson> lessons = course.getLessons();
      if (StudyUtils.indexIsValid(lessonIndex, lessons)) {
        final Lesson lesson = lessons.get(lessonIndex);
        final List<Task> tasks = lesson.getTaskList();
        if (StudyUtils.indexIsValid(taskIndex, tasks)) {
          final Task task = tasks.get(taskIndex);
          final TaskFile taskFile = new TaskFile();
          taskFile.initTaskFile(task, false);
          taskFile.setUserCreated(true);
          final String name = FileUtil.getRelativePath(taskDir.getPath(), createdFile.getPath(), '/');
          taskFile.name = name;
          //TODO: put to other steps as well
          task.getTaskFiles().put(name, taskFile);
        }
      }
    }
  }
}
项目:educational-plugin    文件:CCVirtualFileListener.java   
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
  VirtualFile removedFile = event.getFile();
  String path = removedFile.getPath();
  if (path.contains(CCUtils.GENERATED_FILES_FOLDER)) {
    return;
  }

  if (myProject == null) {
    return;
  }
  if (myProject.getBasePath() !=null && !FileUtil.isAncestor(myProject.getBasePath(), removedFile.getPath(), true)) {
    return;
  }
  Course course = StudyTaskManager.getInstance(myProject).getCourse();
  if (course == null) {
    return;
  }
  final TaskFile taskFile = StudyUtils.getTaskFile(myProject, removedFile);
  if (taskFile != null) {
    deleteTaskFile(removedFile, taskFile);
    return;
  }
  if (removedFile.getName().contains(EduNames.TASK)) {
    deleteTask(course, removedFile);
  }
  if (removedFile.getName().contains(EduNames.LESSON)) {
    deleteLesson(course, removedFile, myProject);
  }
}
项目:branch-window-title    文件:BranchNameFrameTitleBuilder.java   
/**
 * Maintain watch on gitHeadFile via {@link VirtualFileManager#addVirtualFileListener(VirtualFileListener)}.
 */
private void registerFileChangedListener(final String gitHeadFilePath) {
  if (!gitHeadFileWatchSet.contains(gitHeadFilePath)) {
    gitHeadFileWatchSet.add(gitHeadFilePath);
    VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
      @Override
      public void contentsChanged(@NotNull VirtualFileEvent event) {
        if (gitHeadFilePath.equals(event.getFile().getCanonicalPath())) {
          final String branchName = determineBranchName(event.getFile());
          updateFrameTitle(getProjectForFile(event.getFile()), branchName);
        }
      }
    });
  }
}
项目:GravSupport    文件:GravLangFileEditor.java   
@Override
public void contentsChanged(@NotNull VirtualFileEvent event) {
    if (event.getFile().getParent().isDirectory() && event.getFile().getParent().getNameWithoutExtension().compareTo("languages") == 0) {
        if (GravYamlFiles.getLanguageFileType(event.getFile()) != GravYamlFiles.LangFileEditorType.NONE) {
            for (VirtualFile each : getFileMap().values()) {
                if (each.getName().compareTo(event.getFile().getName()) == 0) {
                    //TODO make changes to model according to file changes
                }
            }
        }
    }
}
项目:GravSupport    文件:GravLangFileEditor.java   
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
    for (VirtualFile each : getFileMap().values()) {
        if (each.getName().compareTo(event.getFile().getName()) == 0) {
            getFileMap().remove(each.getNameWithoutExtension());
            model.removeLanguage(each.getNameWithoutExtension());
            editor.initTabs();
        }
    }
}
项目:intellij-ce-playground    文件:TextEditorComponent.java   
@Override
public void contentsChanged(@NotNull VirtualFileEvent event){
  if (event.isFromSave()){ // commit
    assertThread();
    VirtualFile file = event.getFile();
    LOG.assertTrue(file.isValid());
    if(myFile.equals(file)){
      updateModifiedProperty();
    }
  }
}
项目:intellij-ce-playground    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_ignoreEventsFromSelfOnSave() throws Exception {
  final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @NotNull
    @Override
    public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) throws IOException {
      final VirtualFile self = this;
      return new ByteArrayOutputStream() {
        @Override
        public void close() throws IOException {
          super.close();
          long oldStamp = getModificationStamp();
          setModificationStamp(newModificationStamp);
          setText(toString());
          myDocumentManager.contentsChanged(new VirtualFileEvent(requestor, self, null, oldStamp, getModificationStamp()));
        }
      };
    }
  };
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "xxx");
    }
  });

  final long stamp = document.getModificationStamp();

  myDocumentManager.saveAllDocuments();
  assertEquals(stamp, document.getModificationStamp());
}
项目:intellij-ce-playground    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file =
  new MockVirtualFile("test.txt", "test") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };

  myReloadFromDisk = Boolean.FALSE;
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "old ");
    }
  });

  long documentStamp = document.getModificationStamp();

  file.setContent(null, "xxx", false);

  myDocumentManager.saveAllDocuments();

  assertEquals("old test", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals("old test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
  assertEquals(documentStamp, document.getModificationStamp());
}
项目:intellij-ce-playground    文件:VFSForAnnotationListener.java   
@Override
public void contentsChanged(@NotNull VirtualFileEvent event) {
  if (! Comparing.equal(myFile, event.getFile())) return;
  if (! event.isFromRefresh()) return;
  if (! myFile.isWritable()) {
    myFileAnnotation.close();
  }
}
项目:intellij-ce-playground    文件:StudyProjectComponent.java   
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
  if (myProject.isDisposed()) return;
  final VirtualFile createdFile = event.getFile();
  final VirtualFile taskDir = createdFile.getParent();
  final Course course = StudyTaskManager.getInstance(myProject).getCourse();
  if (taskDir != null && taskDir.getName().contains(EduNames.TASK)) {
    int taskIndex = EduUtils.getIndex(taskDir.getName(), EduNames.TASK);
    final VirtualFile lessonDir = taskDir.getParent();
    if (lessonDir != null && lessonDir.getName().contains(EduNames.LESSON)) {
      int lessonIndex = EduUtils.getIndex(lessonDir.getName(), EduNames.LESSON);
      if (course != null) {
        List<Lesson> lessons = course.getLessons();
        if (StudyUtils.indexIsValid(lessonIndex, lessons)) {
          final Lesson lesson = lessons.get(lessonIndex);
          final List<Task> tasks = lesson.getTaskList();
          if (StudyUtils.indexIsValid(taskIndex, tasks)) {
            final Task task = tasks.get(taskIndex);
            final TaskFile taskFile = new TaskFile();
            taskFile.initTaskFile(task, false);
            taskFile.setUserCreated(true);
            final String name = createdFile.getName();
            taskFile.name = name;
            task.getTaskFiles().put(name, taskFile);
          }
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:UserDeviceManager.java   
public UserDeviceManager() {
  myListener = new VirtualFileAdapter() {
    @Override
    public void contentsChanged(@NotNull VirtualFileEvent event) {
      final VirtualFile file = event.getFile();
      if (myUserDevicesFile != null && SdkConstants.FN_DEVICES_XML.equals(file.getName()) &&
          FileUtil.pathsEqual(FileUtil.toSystemIndependentName(myUserDevicesFile.getPath()),
                              file.getPath())) {
        userDevicesChanged();
      }
    }
  };
  LocalFileSystem.getInstance().addVirtualFileListener(myListener);
}
项目:intellij-ce-playground    文件:SvnEntriesFileListener.java   
public void fileCreated(@NotNull VirtualFileEvent event) {
  if (! event.isFromRefresh()) {
    return;
  }
  final VirtualFile file = event.getFile();

  if (SvnUtil.SVN_ADMIN_DIR_NAME.equals(file.getName())) {
    if (event.getParent() != null) {
      VirtualFile parent = event.getParent();
      fireFileStatusesChanged(parent);
      refreshAnnotationsUnder(parent);
    }
  }
}
项目:intellij-ce-playground    文件:SvnEntriesFileListener.java   
public void fileDeleted(@NotNull VirtualFileEvent event) {
  if (!event.isFromRefresh()) {
    return;
  }
  final VirtualFile file = event.getFile();
  if (SvnUtil.SVN_ADMIN_DIR_NAME.equals(file.getName())) {
    if (event.getParent() != null) {
      VirtualFile parent = event.getParent();
      fireFileStatusesChanged(parent);
      refreshAnnotationsUnder(parent);
    }
    return;
  }
}
项目:intellij-ce-playground    文件:GroovyDslFileIndex.java   
public GroovyDslFileIndex() {
  VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
    @Override
    public void contentsChanged(@NotNull VirtualFileEvent event) {
      final VirtualFile file = event.getFile();
      if (event.isFromRefresh() || !GdslUtil.GDSL_FILTER.value(file) || getStatus(file) != Status.ACTIVE) return;
      disableFile(file, Status.MODIFIED, null);
    }
  });
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLConfigurationProvider.java   
@Override
public void contentsChanged(@NotNull VirtualFileEvent event) {
    final VirtualFile file = event.getFile();
    if(GRAPHQL_CONFIG_JSON.equals(file.getName())) {
        if(myProject.isDisposed()) {
            // the project has been disposed, so this instance isn't needed anymore
            VirtualFileManager.getInstance().removeVirtualFileListener(this);
            return;
        }
        if(file.equals(getGraphQLConfigFile())) {
            final JSGraphQLConfiguration configuration = getConfiguration(file);
            if(configuration != null && configuration.endpoints != null) {
                synchronized (endpointsLock) {
                    if(endpoints == null) {
                        endpoints = configuration.endpoints;
                    } else {
                        for(int i = 0; i < configuration.endpoints.size(); i++) {
                            if(i < endpoints.size()) {
                                // update existing instances since they may already be selected in open editors
                                endpoints.get(i).withPropertiesFrom(configuration.endpoints.get(i));
                            } else {
                                endpoints.add(configuration.endpoints.get(i));
                            }
                        }
                        if(configuration.endpoints.size() < endpoints.size()) {
                            // one or more endpoints deleted
                            endpoints.removeIf(ep -> !configuration.endpoints.contains(ep));
                        }
                    }
                }

                // signal the change
                myProject.getMessageBus().syncPublisher(JSGraphQLConfigurationListener.TOPIC).onEndpointsChanged(endpoints);

            }
            myProject.putUserData(GRAPHQL_CONFIG_ENDPOINT_ENTRY_FILE_URL, null);
        }
    }
}
项目:spoofax-intellij    文件:ConfigurationFileEventListener.java   
@Override
public void contentsChanged(@NotNull final VirtualFileEvent event) {
    final Set<IdeaProject> projects = getProjectsForFile(event.getFile());
    if (projects.isEmpty()) return;

    if (!respondsToFile(event.getFile())) return;

    // TODO: Reload languages?

    this.logger.info("Recognized change in {}!", SpoofaxModuleUtils.METABORG_CONFIG_FILENAME);
}
项目:intellij-fmt    文件:FmtProjectPlugin.java   
Formatter()
{
    LocalFileSystem.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
        @Override
        public void contentsChanged(@NotNull VirtualFileEvent event) {
            super.contentsChanged(event);
        }
    });
}
项目:tools-idea    文件:TextEditorComponent.java   
@Override
public void contentsChanged(VirtualFileEvent event){
  if (event.isFromSave()){ // commit
    assertThread();
    VirtualFile file = event.getFile();
    LOG.assertTrue(file.isValid());
    if(myFile.equals(file)){
      updateModifiedProperty();
    }
  }
}
项目:tools-idea    文件:SchemesManagerImpl.java   
private void onFileContentChanged(final VirtualFileEvent event) {
  VirtualFile file = event.getFile();

  if (event.getRequestor() == null && isFileUnder(file, myVFSBaseDir) && !myInsideSave) {
    File ioFile = new File(file.getPath());
    E scheme = findSchemeFor(ioFile.getName());
    ArrayList<E> read = new ArrayList<E>();
    T oldCurrentScheme = null;
    if (scheme != null) {
      oldCurrentScheme = getCurrentScheme();
      @SuppressWarnings("unchecked") T t = (T)scheme;
      removeScheme(t);
      myProcessor.onSchemeDeleted(scheme);
    }

    readSchemeFromFile(read, file, true);
    if (!read.isEmpty()) {
      E readScheme = read.get(0);
      myProcessor.initScheme(readScheme);

      myProcessor.onSchemeAdded(readScheme);

      T newCurrentScheme = getCurrentScheme();

      if (oldCurrentScheme != null && newCurrentScheme == null) {
        setCurrentSchemeName(readScheme.getName());
        newCurrentScheme = getCurrentScheme();
      }

      if (oldCurrentScheme != newCurrentScheme) {
        myProcessor.onCurrentSchemeChanged(oldCurrentScheme);
      }
    }
  }
}
项目:tools-idea    文件:FileDocumentManagerImplTest.java   
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myDocumentManager.myReloadFromDisk = Boolean.TRUE;
  try {
    myDocumentManager.saveAllDocuments();
    long fileStamp = file.getModificationStamp();

    assertEquals("xxx", document.getText());
    assertEquals(file.getModificationStamp(), document.getModificationStamp());
    assertEquals(file.getModificationStamp(), fileStamp);
    assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
  }
  finally {
    myDocumentManager.myReloadFromDisk = null;
  }
}
项目:tools-idea    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };

  myDocumentManager.myReloadFromDisk = Boolean.FALSE;
  try {
    Document document = myDocumentManager.getDocument(file);
    assertNotNull(file.toString(), document);
    document.insertString(0, "old ");
    long documentStamp = document.getModificationStamp();

    file.setContent(null, "xxx", false);

    myDocumentManager.saveAllDocuments();

    assertEquals("old test", document.getText());
    assertEquals(file.getModificationStamp(), document.getModificationStamp());
    assertTrue(Arrays.equals("old test".getBytes("UTF-8"), file.contentsToByteArray()));
    assertEquals(documentStamp, document.getModificationStamp());
  }
  finally {
    myDocumentManager.myReloadFromDisk = null;
  }
}
项目:tools-idea    文件:FileDocumentManagerImplTest.java   
public void testExternalReplaceWithTheSameText() throws Exception {
  final long[] modificationStamp = new long[1];
  modificationStamp[0] = 1;

  final VirtualFile file = new MockVirtualFile("test.txt", "test") {
    @NotNull
    @Override
    public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
      fail();
      throw new IOException();
    }

    @Override
    public long getModificationStamp() {
      return modificationStamp[0];
    }

    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, 1, 2));
    }
  };

  DocumentEx document = (DocumentEx)myDocumentManager.getDocument(file);
  modificationStamp[0] = 2;
  file.refresh(false, false);
  assertNotNull(file.toString(), document);
  assertEquals(2, document.getModificationStamp());
}
项目:tools-idea    文件:VFSForAnnotationListener.java   
public void contentsChanged(VirtualFileEvent event) {
  if (! Comparing.equal(myFile, event.getFile())) return;
  if (! event.isFromRefresh()) return;
  if (! myFile.isWritable()) {
    myFileAnnotation.close();
  }
}
项目:tools-idea    文件:SvnEntriesFileListener.java   
public void fileCreated(VirtualFileEvent event) {
  if (! event.isFromRefresh()) {
    return;
  }
  final VirtualFile file = event.getFile();

  if (SvnUtil.SVN_ADMIN_DIR_NAME.equals(file.getName())) {
    if (event.getParent() != null) {
      VirtualFile parent = event.getParent();
      fireFileStatusesChanged(parent);
      refreshAnnotationsUnder(parent);
    }
  }
}
项目:tools-idea    文件:SvnEntriesFileListener.java   
public void fileDeleted(VirtualFileEvent event) {
  if (!event.isFromRefresh()) {
    return;
  }
  final VirtualFile file = event.getFile();
  if (SvnUtil.SVN_ADMIN_DIR_NAME.equals(file.getName())) {
    if (event.getParent() != null) {
      VirtualFile parent = event.getParent();
      fireFileStatusesChanged(parent);
      refreshAnnotationsUnder(parent);
    }
    return;
  }
}
项目:tools-idea    文件:GroovyDslFileIndex.java   
public GroovyDslFileIndex() {
  VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {

    @Override
    public void contentsChanged(VirtualFileEvent event) {
      if (event.getFileName().endsWith(".gdsl")) {
        disableFile(event.getFile(), MODIFIED);
      }
    }

  });
}
项目:WebStormRequireJsPlugin    文件:RequirejsProjectComponent.java   
public void contentsChanged(@NotNull VirtualFileEvent event) {
            VirtualFile confFile = findPathInWebDir(settings.configFilePath);
            if (confFile == null || !confFile.exists() || !event.getFile().equals(confFile)) {
                return;
            }
            LOG.debug("RequireConfigVfsListener contentsChanged");
//            RequirejsProjectComponent.this.project.getComponent(RequirejsProjectComponent.class).parseRequirejsConfig();
            RequirejsProjectComponent.this.parseRequirejsConfig();
        }
项目:consulo-javaee    文件:Tomcat40PositionManager.java   
public void fileCreated(@NotNull VirtualFileEvent event) {
  VirtualFile file = event.getFile();
  if (isGenerated(file)) {
    if (file.isDirectory()) {
      checkCreatedDir(file);
    }
    else {
      if (isGeneratedServlet(file)) {
        parseGeneratedServlet(file);
      }
    }
  }
}
项目:consulo    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_ignoreEventsFromSelfOnSave() throws Exception {
  final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Nonnull
    @Override
    public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) throws IOException {
      final VirtualFile self = this;
      return new ByteArrayOutputStream() {
        @Override
        public void close() throws IOException {
          super.close();
          long oldStamp = getModificationStamp();
          setModificationStamp(newModificationStamp);
          setText(toString());
          myDocumentManager.contentsChanged(new VirtualFileEvent(requestor, self, null, oldStamp, getModificationStamp()));
        }
      };
    }
  };
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "xxx");
    }
  });

  final long stamp = document.getModificationStamp();

  myDocumentManager.saveAllDocuments();
  assertEquals(stamp, document.getModificationStamp());
}