@Override
 public void propertyChanged(final VirtualFilePropertyEvent e) {
   if (VirtualFile.PROP_NAME.equals(e.getPropertyName())) {
     // File can be invalidated after file changes name (extension also
     // can changes). The editor should be removed if it's invalid.
     updateValidProperty();
     updateHighlighters();
   }
 }
 @Override
 public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
   if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) {
     FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
     VirtualFile file = event.getFile();
     if (fileEditorManager.isFileOpen(file)) {
       reinitBreadcrumbsComponent(fileEditorManager, file);
     }
   }
 }
Пример #3
0
 private VirtualFileSystemEntry applyEvent(@NotNull VFileEvent event) {
   try {
     if (event instanceof VFileCreateEvent) {
       final VFileCreateEvent createEvent = (VFileCreateEvent) event;
       return executeCreateChild(createEvent.getParent(), createEvent.getChildName());
     } else if (event instanceof VFileDeleteEvent) {
       final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
       executeDelete(deleteEvent.getFile());
     } else if (event instanceof VFileContentChangeEvent) {
       final VFileContentChangeEvent contentUpdateEvent = (VFileContentChangeEvent) event;
       executeTouch(
           contentUpdateEvent.getFile(),
           contentUpdateEvent.isFromRefresh(),
           contentUpdateEvent.getModificationStamp());
     } else if (event instanceof VFileCopyEvent) {
       final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
       return executeCreateChild(copyEvent.getNewParent(), copyEvent.getNewChildName());
     } else if (event instanceof VFileMoveEvent) {
       final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
       executeMove(moveEvent.getFile(), moveEvent.getNewParent());
     } else if (event instanceof VFilePropertyChangeEvent) {
       final VFilePropertyChangeEvent propertyChangeEvent = (VFilePropertyChangeEvent) event;
       if (VirtualFile.PROP_NAME.equals(propertyChangeEvent.getPropertyName())) {
         executeRename(propertyChangeEvent.getFile(), (String) propertyChangeEvent.getNewValue());
       } else if (VirtualFile.PROP_WRITABLE.equals(propertyChangeEvent.getPropertyName())) {
         executeSetWritable(
             propertyChangeEvent.getFile(),
             ((Boolean) propertyChangeEvent.getNewValue()).booleanValue());
       } else if (VirtualFile.PROP_HIDDEN.equals(propertyChangeEvent.getPropertyName())) {
         executeSetHidden(
             propertyChangeEvent.getFile(),
             ((Boolean) propertyChangeEvent.getNewValue()).booleanValue());
       } else if (VirtualFile.PROP_SYMLINK_TARGET.equals(propertyChangeEvent.getPropertyName())) {
         executeSetTarget(
             propertyChangeEvent.getFile(), (String) propertyChangeEvent.getNewValue());
       }
     }
   } catch (Exception e) {
     // Exception applying single event should not prevent other events from applying.
     LOG.error(e);
   }
   return null;
 }
Пример #4
0
    @Override
    public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
      if (!isModuleAdded
          || event.getRequestor() instanceof StateStorage
          || !VirtualFile.PROP_NAME.equals(event.getPropertyName())) {
        return;
      }

      VirtualFile parent = event.getParent();
      if (parent != null) {
        String parentPath = parent.getPath();
        String ancestorPath = parentPath + "/" + event.getOldValue();
        String moduleFilePath = getModuleFilePath();
        if (VfsUtilCore.isAncestor(new File(ancestorPath), new File(moduleFilePath), true)) {
          setModuleFilePath(
              parentPath
                  + "/"
                  + event.getNewValue()
                  + "/"
                  + FileUtil.getRelativePath(ancestorPath, moduleFilePath, '/'));
        }
      }
    }
    @Override
    public void before(@NotNull final List<? extends VFileEvent> events) {
      cleanContainerCaches();
      List<VirtualFilePointer> toFireEvents = new ArrayList<VirtualFilePointer>();
      List<String> toUpdateUrl = new ArrayList<String>();

      synchronized (VirtualFilePointerManagerImpl.this) {
        for (VFileEvent event : events) {
          if (event instanceof VFileDeleteEvent) {
            final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
            String url = deleteEvent.getFile().getPath();
            addPointersUnder(url, true, toFireEvents);
          } else if (event instanceof VFileCreateEvent) {
            final VFileCreateEvent createEvent = (VFileCreateEvent) event;
            String url = createEvent.getPath();
            addPointersUnder(url, false, toFireEvents);
          } else if (event instanceof VFileCopyEvent) {
            final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
            String url = copyEvent.getNewParent().getPath() + "/" + copyEvent.getFile().getName();
            addPointersUnder(url, false, toFireEvents);
          } else if (event instanceof VFileMoveEvent) {
            final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
            List<VirtualFilePointer> pointers = new ArrayList<VirtualFilePointer>();
            addPointersUnder(moveEvent.getFile().getPath(), false, pointers);
            for (VirtualFilePointer pointer : pointers) {
              VirtualFile file = pointer.getFile();
              if (file != null) {
                toUpdateUrl.add(file.getPath());
              }
            }
          } else if (event instanceof VFilePropertyChangeEvent) {
            final VFilePropertyChangeEvent change = (VFilePropertyChangeEvent) event;
            if (VirtualFile.PROP_NAME.equals(change.getPropertyName())) {
              List<VirtualFilePointer> pointers = new ArrayList<VirtualFilePointer>();
              addPointersUnder(change.getFile().getPath(), false, pointers);
              for (VirtualFilePointer pointer : pointers) {
                VirtualFile file = pointer.getFile();
                if (file != null) {
                  toUpdateUrl.add(file.getPath());
                }
              }
            }
          }
        }

        myEvents = new ArrayList<EventDescriptor>();
        for (VirtualFilePointerListener listener : myUrlToPointerMaps.keySet()) {
          if (listener == null) continue;
          EventDescriptor event = new EventDescriptor(listener, toFireEvents);
          myEvents.add(event);
        }
      }

      for (EventDescriptor event : myEvents) {
        event.fireBefore();
      }

      if (!toFireEvents.isEmpty()) {
        VirtualFilePointer[] arr =
            toFireEvents.toArray(new VirtualFilePointer[toFireEvents.size()]);
        myBus.syncPublisher(VirtualFilePointerListener.TOPIC).beforeValidityChanged(arr);
      }

      myPointersToUpdate = toFireEvents;
      myUrlsToUpdate = toUpdateUrl;
    }
  @Override
  public void propertyChanged(@NotNull final VirtualFilePropertyEvent event) {
    final String propertyName = event.getPropertyName();
    final VirtualFile vFile = event.getFile();

    final FileViewProvider oldFileViewProvider = myFileManager.findCachedViewProvider(vFile);
    final PsiFile oldPsiFile;
    if (oldFileViewProvider instanceof SingleRootFileViewProvider) {
      oldPsiFile =
          ((SingleRootFileViewProvider) oldFileViewProvider)
              .getCachedPsi(oldFileViewProvider.getBaseLanguage());
    } else {
      oldPsiFile = null;
    }

    VirtualFile parent = vFile.getParent();
    final PsiDirectory parentDir =
        oldPsiFile != null && parent != null
            ? myFileManager.findDirectory(parent)
            : getCachedDirectory(parent);

    if (oldFileViewProvider
            != null // there is no need to rebuild if there were no PSI in the first place
        && FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(event.getRequestor())) {
      myFileManager.forceReload(vFile);
      return;
    }

    // do not suppress reparse request for light files
    if (parentDir == null) {
      boolean fire = VirtualFile.PROP_NAME.equals(propertyName) && vFile.isDirectory();
      if (fire) {
        PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile);
        fire = psiDir != null;
      }
      if (!fire && !VirtualFile.PROP_WRITABLE.equals(propertyName)) {
        handleVfsChangeWithoutPsi(vFile);
        return;
      }
    }

    ((SmartPointerManagerImpl) SmartPointerManager.getInstance(myManager.getProject()))
        .fastenBelts(vFile, 0, null);
    ApplicationManager.getApplication()
        .runWriteAction(
            new ExternalChangeAction() {
              @Override
              public void run() {
                PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                treeEvent.setParent(parentDir);

                if (VirtualFile.PROP_NAME.equals(propertyName)) {
                  if (vFile.isDirectory()) {
                    PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile);
                    if (psiDir != null) {
                      if (myFileTypeManager.isFileIgnored(vFile)) {
                        myFileManager.removeFilesAndDirsRecursively(vFile);

                        treeEvent.setChild(psiDir);
                        myManager.childRemoved(treeEvent);
                      } else {
                        treeEvent.setElement(psiDir);
                        treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_DIRECTORY_NAME);
                        treeEvent.setOldValue(event.getOldValue());
                        treeEvent.setNewValue(event.getNewValue());
                        myManager.propertyChanged(treeEvent);
                      }
                    } else {
                      PsiDirectory psiDir1 = myFileManager.findDirectory(vFile);
                      if (psiDir1 != null) {
                        treeEvent.setChild(psiDir1);
                        myManager.childAdded(treeEvent);
                      }
                    }
                  } else {
                    final FileViewProvider fileViewProvider =
                        myFileManager.createFileViewProvider(vFile, true);
                    final PsiFile newPsiFile =
                        fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
                    if (oldPsiFile != null) {
                      if (newPsiFile == null) {
                        myFileManager.setViewProvider(vFile, null);

                        treeEvent.setChild(oldPsiFile);
                        myManager.childRemoved(treeEvent);
                      } else if (!FileManagerImpl.areViewProvidersEquivalent(
                          fileViewProvider, oldFileViewProvider)) {
                        myFileManager.setViewProvider(vFile, fileViewProvider);

                        treeEvent.setOldChild(oldPsiFile);
                        treeEvent.setNewChild(newPsiFile);
                        myManager.childReplaced(treeEvent);
                      } else {
                        if (oldPsiFile instanceof PsiFileImpl) {
                          ((PsiFileImpl) oldPsiFile).clearCaches();
                        }
                        treeEvent.setElement(oldPsiFile);
                        treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_FILE_NAME);
                        treeEvent.setOldValue(event.getOldValue());
                        treeEvent.setNewValue(event.getNewValue());
                        myManager.propertyChanged(treeEvent);
                      }
                    } else if (newPsiFile != null) {
                      myFileManager.setViewProvider(vFile, fileViewProvider);
                      if (parentDir != null) {
                        treeEvent.setChild(newPsiFile);
                        myManager.childAdded(treeEvent);
                      }
                    }
                  }
                } else if (VirtualFile.PROP_WRITABLE.equals(propertyName)) {
                  if (oldPsiFile == null) return;

                  treeEvent.setElement(oldPsiFile);
                  treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_WRITABLE);
                  treeEvent.setOldValue(event.getOldValue());
                  treeEvent.setNewValue(event.getNewValue());
                  myManager.propertyChanged(treeEvent);
                } else if (VirtualFile.PROP_ENCODING.equals(propertyName)) {
                  if (oldPsiFile == null) return;

                  treeEvent.setElement(oldPsiFile);
                  treeEvent.setPropertyName(VirtualFile.PROP_ENCODING);
                  treeEvent.setOldValue(event.getOldValue());
                  treeEvent.setNewValue(event.getNewValue());
                  myManager.propertyChanged(treeEvent);
                }
              }
            });
  }
  @Override
  public void before(@NotNull final List<? extends VFileEvent> events) {
    List<FilePointerPartNode> toFireEvents = new ArrayList<FilePointerPartNode>();
    List<FilePointerPartNode> toUpdateUrl = new ArrayList<FilePointerPartNode>();
    VirtualFilePointer[] toFirePointers;

    synchronized (this) {
      incModificationCount();
      for (VFileEvent event : events) {
        if (event instanceof VFileDeleteEvent) {
          final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
          addPointersUnder(deleteEvent.getFile(), false, "", toFireEvents);

        } else if (event instanceof VFileCreateEvent) {
          final VFileCreateEvent createEvent = (VFileCreateEvent) event;
          addPointersUnder(createEvent.getParent(), true, createEvent.getChildName(), toFireEvents);
        } else if (event instanceof VFileCopyEvent) {
          final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
          addPointersUnder(
              copyEvent.getNewParent(), true, copyEvent.getFile().getName(), toFireEvents);
        } else if (event instanceof VFileMoveEvent) {
          final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
          VirtualFile eventFile = moveEvent.getFile();
          addPointersUnder(moveEvent.getNewParent(), true, eventFile.getName(), toFireEvents);

          List<FilePointerPartNode> nodes = new ArrayList<FilePointerPartNode>();
          addPointersUnder(eventFile, false, "", nodes);
          for (FilePointerPartNode pair : nodes) {
            VirtualFile file = pair.leaf.getFile();
            if (file != null) {
              toUpdateUrl.add(pair);
            }
          }
        } else if (event instanceof VFilePropertyChangeEvent) {
          final VFilePropertyChangeEvent change = (VFilePropertyChangeEvent) event;
          if (VirtualFile.PROP_NAME.equals(change.getPropertyName())) {
            VirtualFile eventFile = change.getFile();
            VirtualFile parent = eventFile.getParent(); // e.g. for LightVirtualFiles
            addPointersUnder(parent, true, change.getNewValue().toString(), toFireEvents);

            List<FilePointerPartNode> nodes = new ArrayList<FilePointerPartNode>();
            addPointersUnder(eventFile, false, "", nodes);
            for (FilePointerPartNode pair : nodes) {
              VirtualFile file = pair.leaf.getFile();
              if (file != null) {
                toUpdateUrl.add(pair);
              }
            }
          }
        }
      }

      myEvents = new ArrayList<EventDescriptor>();
      toFirePointers = toPointers(toFireEvents);
      for (final VirtualFilePointerListener listener : myPointers.keySet()) {
        if (listener == null) continue;
        List<VirtualFilePointer> filtered =
            ContainerUtil.filter(
                toFirePointers,
                new Condition<VirtualFilePointer>() {
                  @Override
                  public boolean value(VirtualFilePointer pointer) {
                    return ((VirtualFilePointerImpl) pointer).getListener() == listener;
                  }
                });
        if (!filtered.isEmpty()) {
          EventDescriptor event =
              new EventDescriptor(
                  listener, filtered.toArray(new VirtualFilePointer[filtered.size()]));
          myEvents.add(event);
        }
      }
    }

    for (EventDescriptor descriptor : myEvents) {
      descriptor.fireBefore();
    }

    if (!toFireEvents.isEmpty()) {
      myBus.syncPublisher(VirtualFilePointerListener.TOPIC).beforeValidityChanged(toFirePointers);
    }

    myPointersToFire = toFireEvents;
    myPointersToUpdateUrl = toUpdateUrl;
  }
 @Override
 public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
   if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) {
     fileChanged(myProject, event.getFile());
   }
 }