com.intellij.openapi.vfs.VirtualFileEvent Java Examples

The following examples show how to use com.intellij.openapi.vfs.VirtualFileEvent. 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: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates and dispatches a deletion activity for the deleted resource.
 *
 * @param virtualFileEvent the event to react to
 * @see VirtualFileListener#beforeFileDeletion(VirtualFileEvent)
 * @see #generateFileDeletionActivity(VirtualFile)
 * @see #generateFolderDeletionActivity(VirtualFile)
 */
private void generateResourceDeletionActivity(@NotNull VirtualFileEvent virtualFileEvent) {

  assert enabled : "the before file deletion listener was triggered while it was disabled";

  VirtualFile deletedVirtualFile = virtualFileEvent.getFile();

  if (log.isTraceEnabled()) {
    log.trace("Reacting before resource deletion: " + deletedVirtualFile);
  }

  if (deletedVirtualFile.isDirectory()) {
    generateFolderDeletionActivity(deletedVirtualFile);
  } else {
    generateFileDeletionActivity(deletedVirtualFile);
  }
}
 
Example #2
Source File: MockVirtualFileSystem.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile vDir, @NotNull String dirName)
        throws IOException {
    if (vDir instanceof MockVirtualFile) {
        MockVirtualFile mvd = (MockVirtualFile) vDir;
        if (registeredFiles.containsKey(mvd.getPath())) {
            if (mvd.getChild(dirName) != null) {
                throw new FileAlreadyExistsException(mvd.getPath() + "/" + dirName);
            }
            MockVirtualFile child = new MockVirtualFile(this, dirName, mvd);
            mvd.markChild(child);
            registeredFiles.put(child.getPath(), child);
            VirtualFileEvent event = new VirtualFileEvent(requestor, child, dirName, vDir);
            for (VirtualFileListener listener : listeners) {
                listener.fileCreated(event);
            }
            return child;
        }
    }
    throw new NoSuchFileException(vDir.getCanonicalPath());
}
 
Example #3
Source File: MockVirtualFileSystem.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected VirtualFile createChildFile(Object requestor, @NotNull VirtualFile vDir, @NotNull String fileName)
        throws IOException {
    if (vDir instanceof MockVirtualFile) {
        MockVirtualFile mvd = (MockVirtualFile) vDir;
        if (registeredFiles.containsKey(mvd.getPath())) {
            if (mvd.getChild(fileName) != null) {
                throw new FileAlreadyExistsException(mvd.getPath() + "/" + fileName);
            }
            MockVirtualFile child = new MockVirtualFile(this, fileName, mvd, "", getDefaultCharset());
            mvd.markChild(child);
            VirtualFileEvent event = new VirtualFileEvent(requestor, child, fileName, vDir);
            for (VirtualFileListener listener : listeners) {
                listener.fileCreated(event);
            }
            return child;
        }
    } else if (vDir instanceof IOVirtualFile) {
        return new IOVirtualFile(new File(((IOVirtualFile) vDir).getIOFile(), fileName), false);
    }
    throw new NoSuchFileException(vDir.getCanonicalPath());
}
 
Example #4
Source File: ContentResourceChangeListener.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
private void executeMake(final VirtualFileEvent event) {
        if(
            (pluginConfiguration == null || pluginConfiguration.isIncrementalBuilds())
// If no Configuration Selected which can happen when the project is not AEM / Sling based then do nothing
            && serverConnectionManager.isConfigurationSelected()
        ) {
            // Check if the file is a Java Class and if os build it
            VirtualFile file = event.getFile();
            if("java".equalsIgnoreCase(file.getExtension())) {
                //AS TODO: In order to use the Code Snell Detector this needs to be invoked in a Read Only Thread but part of the Dispatcher Thread
                invokeAndWait(
                    new InvokableRunner() {
                        @Override
                        public void run() {
                            executeMakeInUIThread(event);
                        }
                    }
                );
            }
        }
    }
 
Example #5
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());
    }
  });
}
 
Example #6
Source File: BackgroundTaskByVfsChangeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public BackgroundTaskByVfsChangeManagerImpl(@Nonnull Project project) {
  myProject = project;

  VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileListener() {
    @Override
    public void contentsChanged(@Nonnull VirtualFileEvent event) {
      runTasks(event.getFile());
    }
  }, this);
}
 
Example #7
Source File: VFSForAnnotationListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void contentsChanged(@Nonnull VirtualFileEvent event) {
  if (! Comparing.equal(myFile, event.getFile())) return;
  if (! event.isFromRefresh()) return;
  if (! myFile.isWritable()) {
    myFileAnnotation.close();
  }
}
 
Example #8
Source File: TextEditorComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void contentsChanged(@Nonnull VirtualFileEvent event) {
  if (event.isFromSave()) { // commit
    assertThread();
    VirtualFile file = event.getFile();
    LOG.assertTrue(file.isValid());
    if (myFile.equals(file)) {
      updateModifiedProperty();
    }
  }
}
 
Example #9
Source File: RequirejsProjectComponent.java    From WebStormRequireJsPlugin with MIT License 5 votes vote down vote up
public void contentsChanged(@NotNull VirtualFileEvent event) {
            VirtualFile confFile = findPathInWebDir(settings.configFilePath);
            if (confFile == null || !confFile.exists() || !event.getFile().equals(confFile)) {
                return;
            }
            LOG.debug("RequireConfigVfsListener contentsChanged");
//            RequirejsProjectComponent.this.project.getComponent(RequirejsProjectComponent.class).parseRequirejsConfig();
            RequirejsProjectComponent.this.parseRequirejsConfig();
        }
 
Example #10
Source File: AutoSyncHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
private void handleFileEvent(VirtualFileEvent event) {
  if (event.getRequestor() == null) {
    // ignore events originating externally -- these are usually covered by
    // VcsAutoSyncProvider, and we don't want to trigger endless auto-syncs from VCS syncs
    return;
  }
  handleFileChange(event.getFile());
}
 
Example #11
Source File: ParametersPanel.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
private void setupFileSpecificEditor(Project project, VirtualFile cypherFile) {
    if (project == null || cypherFile == null) {
        return;
    }
    try {
        String params = FileUtil.getParams(cypherFile);
        LightVirtualFile lightVirtualFile = new LightVirtualFile("", JsonFileType.INSTANCE, params);
        Document document = FileDocumentManager.getInstance().getDocument(lightVirtualFile);
        fileSpecificParamEditor = createEditor(project, document);
        VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileListener() {
            @Override
            public void contentsChanged(@NotNull VirtualFileEvent event) {
                if (event.getFile().equals(cypherFile) && document != null) {
                    FileUtil.setParams(cypherFile, document.getText());
                }
            }
        });
        JLabel jLabel = new JLabel("<html>Parameters for data source <b>" +
                getTabTitle(cypherFile) + "</b>:</html>");
        jLabel.setIcon(ICON_HELP);
        jLabel.setToolTipText("Enter parameters in JSON format. Will be applied to <b>" + getTabTitle(cypherFile) +
                "</b> data source when executed");
        fileSpecificParamEditor.setHeaderComponent(jLabel);
        if (document != null) {
            setInitialContent(document);
        }
        graphConsoleView.getFileSpecificParametersTab().add(fileSpecificParamEditor.getComponent(), BorderLayout.CENTER);
    } catch (Throwable e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example #12
Source File: AutoSyncHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void fileCreated(VirtualFileEvent event) {
  handleFileEvent(event);
}
 
Example #13
Source File: ProjectManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void projectStorageFileChanged(@Nonnull VirtualFileEvent event, @Nonnull StateStorage storage, @Nonnull Project project) {
  VirtualFile file = event.getFile();
  if (!StorageUtil.isChangedByStorageOrSaveSession(event) && !(event.getRequestor() instanceof ProjectManagerImpl)) {
    registerProjectToReload(project, file, storage);
  }
}
 
Example #14
Source File: ANTLRv4PluginController.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void contentsChanged(VirtualFileEvent event) {
	final VirtualFile vfile = event.getFile();
	if ( !vfile.getName().endsWith(".g4") ) return;
	if ( !projectIsClosed ) grammarFileSavedEvent(vfile);
}
 
Example #15
Source File: FileMonitor.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
@Override
public void fileCreated(VirtualFileEvent event) {
	check();
}
 
Example #16
Source File: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generates and dispatches a creation activity for the new resource.
 *
 * @param virtualFileEvent the event to react to
 * @see VirtualFileListener#fileCreated(VirtualFileEvent)
 */
private void generateResourceCreationActivity(@NotNull VirtualFileEvent virtualFileEvent) {

  assert enabled : "the file created listener was triggered while it was disabled";

  VirtualFile createdVirtualFile = virtualFileEvent.getFile();

  if (log.isTraceEnabled()) {
    log.trace("Reacting to resource creation: " + createdVirtualFile);
  }

  Set<IReferencePoint> sharedReferencePoints = session.getReferencePoints();

  IResource resource =
      VirtualFileConverter.convertToResource(sharedReferencePoints, createdVirtualFile);

  if (resource == null || !session.isShared(resource)) {
    if (log.isTraceEnabled()) {
      log.trace("Ignoring non-shared resource creation: " + createdVirtualFile);
    }

    return;
  }

  User user = session.getLocalUser();

  IActivity activity;

  if (createdVirtualFile.isDirectory()) {
    activity = new FolderCreatedActivity(user, (IFolder) resource);

  } else {
    String charset = createdVirtualFile.getCharset().name();

    byte[] content = getContent(createdVirtualFile);

    activity =
        new FileActivity(
            user,
            Type.CREATED,
            FileActivity.Purpose.ACTIVITY,
            (IFile) resource,
            null,
            content,
            charset);
  }

  dispatchActivity(activity);

  if (!createdVirtualFile.isDirectory() && ProjectAPI.isOpen(project, createdVirtualFile)) {
    setUpCreatedFileState((IFile) resource);
  }
}
 
Example #17
Source File: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Notifies the other session participants of the local save of the given file.
 *
 * @param virtualFileEvent the event to react to
 * @see LocalDocumentModificationHandler
 * @see VirtualFileListener#beforeContentsChange(VirtualFileEvent)
 */
private void generateEditorSavedActivity(@NotNull VirtualFileEvent virtualFileEvent) {

  assert enabled : "the before contents change listener was triggered while it was disabled";

  VirtualFile virtualFile = virtualFileEvent.getFile();

  if (log.isTraceEnabled()) {
    log.trace("Reacting before resource contents changed: " + virtualFile);
  }

  Set<IReferencePoint> sharedReferencePoints = session.getReferencePoints();

  IFile file = (IFile) VirtualFileConverter.convertToResource(sharedReferencePoints, virtualFile);

  if (file == null || !session.isShared(file)) {
    if (log.isTraceEnabled()) {
      log.trace("Ignoring non-shared resource's contents change: " + virtualFile);
    }

    return;
  }

  if (virtualFileEvent.isFromSave()) {
    if (log.isTraceEnabled()) {
      log.trace(
          "Ignoring contents change for "
              + virtualFile
              + " as they were caused by a document save.");
    }

    localEditorHandler.generateEditorSaved(file);

    return;
  }

  if (virtualFileEvent.isFromRefresh()) {
    if (log.isTraceEnabled()) {
      log.trace(
          "Ignoring contents change for "
              + virtualFile
              + " as they were caused by a filesystem snapshot refresh. "
              + "This is already handled by the document listener.");
    }

    return;
  }

  if (!virtualFile.getFileType().isBinary()) {
    // modification already handled by document modification handler
    log.debug(
        "Ignoring content change on the virtual file level for text resource "
            + virtualFile
            + ", requested by: "
            + virtualFileEvent.getRequestor());

  } else {
    // TODO handle content changes for non-text resources; see #996
    log.warn(
        "Detected unhandled content change on the virtual file level for non-text resource "
            + virtualFile
            + ", requested by: "
            + virtualFileEvent.getRequestor());
  }
}
 
Example #18
Source File: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void beforeFileDeletion(@NotNull VirtualFileEvent event) {
  generateResourceDeletionActivity(event);
}
 
Example #19
Source File: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
  generateResourceCreationActivity(event);
}
 
Example #20
Source File: FileMonitor.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(VirtualFileEvent event) {
	check();
}
 
Example #21
Source File: ContentResourceChangeListener.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
private void executeMakeInUIThread(final VirtualFileEvent event) {
    if(project.isInitialized() && !project.isDisposed() && project.isOpen()) {
        final CompilerManager compilerManager = CompilerManager.getInstance(project);
        if(!compilerManager.isCompilationActive() &&
            !compilerManager.isExcludedFromCompilation(event.getFile()) // &&
        ) {
            // Check first if there are no errors in the code
            CodeSmellDetector codeSmellDetector = CodeSmellDetector.getInstance(project);
            boolean isOk = true;
            if(codeSmellDetector != null) {
                List<CodeSmellInfo> codeSmellInfoList = codeSmellDetector.findCodeSmells(Arrays.asList(event.getFile()));
                for(CodeSmellInfo codeSmellInfo: codeSmellInfoList) {
                    if(codeSmellInfo.getSeverity() == HighlightSeverity.ERROR) {
                        isOk = false;
                        break;
                    }
                }
            }
            if(isOk) {
                // Changed file found in module. Make it.
                final ToolWindow tw = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
                final boolean isShown = tw != null && tw.isVisible();
                compilerManager.compile(
                    new VirtualFile[]{event.getFile()},
                    new CompileStatusNotification() {
                        @Override
                        public void finished(boolean b, int i, int i1, CompileContext compileContext) {
                            if (tw != null && tw.isVisible()) {
                                // Close / Hide the Build Message Window after we did the build if it wasn't shown
                                if(!isShown) {
                                    tw.hide(null);
                                }
                            }
                        }
                    }
                );
            } else {
                MessageManager messageManager = ComponentProvider.getComponent(project, MessageManager.class);
                if(messageManager != null) {
                    messageManager.sendErrorNotification(
                        "server.update.file.change.with.error",
                        event.getFile()
                    );
                }
            }
        }
    }
}
 
Example #22
Source File: AutoSyncHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void contentsChanged(VirtualFileEvent event) {
  handleFileEvent(event);
}
 
Example #23
Source File: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Works for all files in the application scope, including meta-files like Intellij
 * configuration files.
 *
 * <p>File changes done though an Intellij editor are processed in the {@link
 * LocalDocumentModificationHandler} instead.
 *
 * @param event
 */
@Override
public void beforeContentsChange(@NotNull VirtualFileEvent event) {
  generateEditorSavedActivity(event);
}
 
Example #24
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired before the deletion of a file is processed.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void beforeFileDeletion(@NotNull VirtualFileEvent event) {
}
 
Example #25
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired before the change of contents of a file is processed.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void beforeContentsChange(@NotNull VirtualFileEvent event) {
}
 
Example #26
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired when a virtual file is created. This event is not fired for files discovered during initial VFS initialization.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
    LSPFileEventManager.fileCreated(event.getFile());
}
 
Example #27
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired when a virtual file is deleted.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
    LSPFileEventManager.fileDeleted(event.getFile());
}
 
Example #28
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired when the contents of a virtual file is changed.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void contentsChanged(@NotNull VirtualFileEvent event) {
    LSPFileEventManager.fileChanged(event.getFile());
}
 
Example #29
Source File: StateStorage.java    From consulo with Apache License 2.0 votes vote down vote up
void storageFileChanged(@Nonnull VirtualFileEvent event, @Nonnull StateStorage storage);