com.intellij.openapi.vfs.VirtualFileAdapter Java Examples

The following examples show how to use com.intellij.openapi.vfs.VirtualFileAdapter. 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: Listener.java    From floobits-intellij with Apache License 2.0 5 votes vote down vote up
public synchronized void start(final EditorEventHandler editorManager) {
    this.editorManager = editorManager;
    connection.subscribe(VirtualFileManager.VFS_CHANGES, this);
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, this);
    em.addDocumentListener(this);
    em.addSelectionListener(this);
    em.addCaretListener(this);
    em.addVisibleAreaListener(this);


    virtualFileAdapter = new VirtualFileAdapter() {
        public void beforePropertyChange(@NotNull final VirtualFilePropertyEvent event) {
            if (!event.getPropertyName().equals(VirtualFile.PROP_NAME)) {
                return;
            }
            VirtualFile parent = event.getParent();
            if (parent == null) {
                return;
            }
            String parentPath = parent.getPath();
            // XXX: pretty sure is this wrong.
            String newValue = parentPath + "/" + event.getNewValue().toString();
            String oldValue = parentPath + "/" + event.getOldValue().toString();
            editorManager.rename(oldValue, newValue);
        }
    };
    VirtualFileManager.getInstance().addVirtualFileListener(virtualFileAdapter);
}
 
Example #2
Source File: NewFileTracker.java    From consulo with Apache License 2.0 5 votes vote down vote up
private NewFileTracker() {
  final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
  virtualFileManager.addVirtualFileListener(new VirtualFileAdapter() {
    @Override
    public void fileCreated(@Nonnull VirtualFileEvent event) {
      if (event.isFromRefresh()) return;
      newFiles.add(event.getFile());
    }
  });
}