Search in sources :

Example 56 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testMoveSrcDirUnderNewRootShouldGenerateRootsChanged.

public void testMoveSrcDirUnderNewRootShouldGenerateRootsChanged() throws Exception {
    File tempDirectory = createTempDirectory();
    final File moveTarget = new File(tempDirectory, "moveTarget");
    assertTrue(moveTarget.mkdir());
    final File dirToMove = new File(tempDirectory, "dirToMove");
    assertTrue(dirToMove.mkdir());
    final LoggingListener listener = new LoggingListener();
    final VirtualFilePointer dirToMovePointer = createPointerByFile(dirToMove, listener);
    assertTrue(dirToMovePointer.isValid());
    ApplicationManager.getApplication().runWriteAction(() -> {
        final VirtualFile virtualFile = getVirtualFile(dirToMove);
        assertTrue(virtualFile.isValid());
        final VirtualFile target = getVirtualFile(moveTarget);
        assertTrue(target.isValid());
        try {
            virtualFile.move(null, target);
        } catch (IOException e) {
            fail();
        }
    });
    assertTrue(dirToMovePointer.isValid());
    assertEquals("[before:true, after:true]", listener.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 57 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method addAssociation.

public void addAssociation(PsiFile file, VirtualFile assoc) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
        LOG.warn("No VirtualFile for " + file.getName());
        return;
    }
    for (VirtualFilePointer pointer : myAssociations.keySet()) {
        if (pointer.getUrl().equals(virtualFile.getUrl())) {
            VirtualFilePointerContainer container = myAssociations.get(pointer);
            if (container == null) {
                container = myFilePointerManager.createContainer(myProject);
                myAssociations.put(pointer, container);
            }
            if (container.findByUrl(assoc.getUrl()) == null) {
                container.add(assoc);
                touch();
            }
            return;
        }
    }
    final VirtualFilePointerContainer container = myFilePointerManager.createContainer(myProject);
    container.add(assoc);
    myAssociations.put(myFilePointerManager.create(virtualFile, myProject, null), container);
    touch();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

Example 58 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method clear.

private void clear() {
    final Set<VirtualFilePointer> virtualFilePointers = myAssociations.keySet();
    for (VirtualFilePointer pointer : virtualFilePointers) {
        myAssociations.get(pointer).killAll();
    }
    myAssociations.clear();
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 59 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method removeAssociation.

public void removeAssociation(PsiFile file, PsiFile assoc) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return;
    if (assoc.getVirtualFile() == null)
        return;
    for (VirtualFilePointer pointer : myAssociations.keySet()) {
        if (pointer.getUrl().equals(virtualFile.getUrl())) {
            VirtualFilePointerContainer container = myAssociations.get(pointer);
            if (container != null) {
                //noinspection ConstantConditions
                final VirtualFilePointer p = container.findByUrl(assoc.getVirtualFile().getUrl());
                if (p != null) {
                    container.remove(p);
                    if (container.size() == 0) {
                        myAssociations.remove(pointer);
                    }
                    touch();
                }
            }
            return;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

Example 60 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method copy.

private static HashMap<VirtualFilePointer, VirtualFilePointerContainer> copy(FileAssociationsManagerImpl other) {
    final HashMap<VirtualFilePointer, VirtualFilePointerContainer> hashMap = new LinkedHashMap<>();
    final Set<VirtualFilePointer> virtualFilePointers = other.myAssociations.keySet();
    for (VirtualFilePointer pointer : virtualFilePointers) {
        final VirtualFilePointerContainer container = other.myFilePointerManager.createContainer(other.myProject);
        container.addAll(other.myAssociations.get(pointer));
        hashMap.put(other.myFilePointerManager.duplicate(pointer, other.myProject, null), container);
    }
    return hashMap;
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

Aggregations

VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)66 MockVirtualFile (com.intellij.mock.MockVirtualFile)23 File (java.io.File)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)11 IOException (java.io.IOException)8 Disposable (com.intellij.openapi.Disposable)7 VirtualFilePointerListener (com.intellij.openapi.vfs.pointers.VirtualFilePointerListener)6 ArrayList (java.util.ArrayList)5 Element (org.jdom.Element)5 Nullable (org.jetbrains.annotations.Nullable)4 Job (com.intellij.concurrency.Job)3 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)3 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)3 VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)3 JobLauncher (com.intellij.concurrency.JobLauncher)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2