com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent Java Examples

The following examples show how to use com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BulkSymbolTableBuildingChangeListener.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void after(List<? extends VFileEvent> events) {
  if (!enabled) {
    return;
  }
  for (VFileEvent event : events) {
    VirtualFile modifiedFile = null;
    // Skip delete events.
    if (event instanceof VFileContentChangeEvent || event instanceof VFileCreateEvent) {
      modifiedFile = event.getFile();
    } else if (event instanceof VFileCopyEvent) {
      VFileCopyEvent copyEvent = (VFileCopyEvent) event;
      modifiedFile = copyEvent.getNewParent();
    } else if (event instanceof VFileMoveEvent) {
      VFileMoveEvent moveEvent = (VFileMoveEvent) event;
      modifiedFile = moveEvent.getNewParent();
    } else if (event instanceof VFilePropertyChangeEvent) {
      VFilePropertyChangeEvent propEvent = (VFilePropertyChangeEvent) event;
      // Check for file renames (sometimes we get property change events without the name
      // actually changing though)
      if (propEvent.getPropertyName().equals(VirtualFile.PROP_NAME)
          && !propEvent.getOldValue().equals(propEvent.getNewValue())) {
        modifiedFile = propEvent.getFile();
      }
    }
    if (SymbolTableProvider.isSourceFile(project, modifiedFile)) {
      queueChange(modifiedFile);
    }
  }
}
 
Example #2
Source File: ScratchTreeStructureProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static VirtualFile getNewParent(@Nonnull VFileEvent e) {
  if (e instanceof VFileMoveEvent) {
    return ((VFileMoveEvent)e).getNewParent();
  }
  else if (e instanceof VFileCopyEvent) {
    return ((VFileCopyEvent)e).getNewParent();
  }
  else if (e instanceof VFileCreateEvent) {
    return ((VFileCreateEvent)e).getParent();
  }
  else {
    return Objects.requireNonNull(e.getFile()).getParent();
  }
}
 
Example #3
Source File: VfsImplUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void checkSubscription() {
  if (ourSubscribed.getAndSet(true)) return;

  Application app = ApplicationManager.getApplication();
  app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@Nonnull List<? extends VFileEvent> events) {
      InvalidationState state = null;

      synchronized (ourLock) {
        for (VFileEvent event : events) {
          if (!(event.getFileSystem() instanceof LocalFileSystem)) continue;

          if (event instanceof VFileCreateEvent) continue; // created file should not invalidate + getFile is costly

          if (event instanceof VFilePropertyChangeEvent && !VirtualFile.PROP_NAME.equals(((VFilePropertyChangeEvent)event).getPropertyName())) {
            continue;
          }

          String path = event.getPath();
          if (event instanceof VFilePropertyChangeEvent) {
            path = ((VFilePropertyChangeEvent)event).getOldPath();
          }
          else if (event instanceof VFileMoveEvent) {
            path = ((VFileMoveEvent)event).getOldPath();
          }

          VirtualFile file = event.getFile();
          if (file == null || !file.isDirectory()) {
            state = InvalidationState.invalidate(state, path);
          }
          else {
            Collection<String> affectedPaths = ourDominatorsMap.get(path);
            if (affectedPaths != null) {
              affectedPaths = ContainerUtil.newArrayList(affectedPaths);  // defensive copying; original may be updated on invalidation
              for (String affectedPath : affectedPaths) {
                state = InvalidationState.invalidate(state, affectedPath);
              }
            }
          }
        }
      }

      if (state != null) state.scheduleRefresh();
    }
  });
}
 
Example #4
Source File: VcsDirtyScopeVfsListener.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ChangeApplier prepareChange(@Nonnull List<? extends VFileEvent> events) {
  if (myForbid || !myVcsManager.hasAnyMappings()) return null;
  final FilesAndDirs dirtyFilesAndDirs = new FilesAndDirs();
  // collect files and directories - sources of events
  for (VFileEvent event : events) {
    ProgressManager.checkCanceled();

    final boolean isDirectory;
    if (event instanceof VFileCreateEvent) {
      if (!((VFileCreateEvent)event).getParent().isInLocalFileSystem()) {
        continue;
      }
      isDirectory = ((VFileCreateEvent)event).isDirectory();
    }
    else {
      final VirtualFile file = Objects.requireNonNull(event.getFile(), "All events but VFileCreateEvent have @NotNull getFile()");
      if (!file.isInLocalFileSystem()) {
        continue;
      }
      isDirectory = file.isDirectory();
    }

    if (event instanceof VFileMoveEvent) {
      add(myVcsManager, dirtyFilesAndDirs, VcsUtil.getFilePath(((VFileMoveEvent)event).getOldPath(), isDirectory));
      add(myVcsManager, dirtyFilesAndDirs, VcsUtil.getFilePath(((VFileMoveEvent)event).getNewPath(), isDirectory));
    }
    else if (event instanceof VFilePropertyChangeEvent && ((VFilePropertyChangeEvent)event).isRename()) {
      // if a file was renamed, then the file is dirty and its parent directory is dirty too;
      // if a directory was renamed, all its children are recursively dirty, the parent dir is also dirty but not recursively.
      FilePath oldPath = VcsUtil.getFilePath(((VFilePropertyChangeEvent)event).getOldPath(), isDirectory);
      FilePath newPath = VcsUtil.getFilePath(((VFilePropertyChangeEvent)event).getNewPath(), isDirectory);
      // the file is dirty recursively
      add(myVcsManager, dirtyFilesAndDirs, oldPath);
      add(myVcsManager, dirtyFilesAndDirs, newPath);
      FilePath parentPath = oldPath.getParentPath();
      if (parentPath != null) {
        addAsFiles(myVcsManager, dirtyFilesAndDirs, parentPath); // directory is dirty alone
      }
    }
    else {
      add(myVcsManager, dirtyFilesAndDirs, VcsUtil.getFilePath(event.getPath(), isDirectory));
    }
  }

  return new ChangeApplier() {
    @Override
    public void afterVfsChange() {
      markDirtyOnPooled(dirtyFilesAndDirs);
    }
  };
}