Java Code Examples for com.intellij.openapi.vfs.VirtualFileAdapter

The following examples show how to use com.intellij.openapi.vfs.VirtualFileAdapter. These examples are extracted from open source projects. 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 Project: floobits-intellij   Source File: Listener.java    License: 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 Project: consulo   Source File: NewFileTracker.java    License: 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());
    }
  });
}