com.intellij.openapi.vfs.VirtualFileMoveEvent Java Examples

The following examples show how to use com.intellij.openapi.vfs.VirtualFileMoveEvent. 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 activities handling resources moves.
 *
 * @param virtualFileMoveEvent the event to react to
 * @see #generateFileMoveActivity(VirtualFile, VirtualFile, VirtualFile, String, String)
 * @see #generateFolderMoveActivity(VirtualFile, VirtualFile, VirtualFile, String)
 * @see #generateResourceCreationActivity(VirtualFileEvent) (VirtualFileEvent)
 * @see #generateResourceDeletionActivity(VirtualFileEvent) (VirtualFileEvent)
 */
private void generateResourceMoveActivity(@NotNull VirtualFileMoveEvent virtualFileMoveEvent) {

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

  VirtualFile oldFile = virtualFileMoveEvent.getFile();
  VirtualFile oldParent = virtualFileMoveEvent.getOldParent();
  VirtualFile newParent = virtualFileMoveEvent.getNewParent();

  if (log.isTraceEnabled()) {
    log.trace(
        "Reacting before resource move - resource: "
            + oldFile
            + ", old parent: "
            + oldParent
            + ", new Parent: "
            + newParent);
  }

  if (oldFile.isDirectory()) {
    generateFolderMoveActivity(oldFile, oldParent, newParent, null);

  } else {
    generateFileMoveActivity(oldFile, oldParent, newParent, null, null);
  }
}
 
Example #2
Source File: LSPFileEventManager.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a file is moved. Notifies the server if this file was watched.
 *
 * @param event The file move event
 */
static void fileMoved(VirtualFileMoveEvent event) {
    try {
        VirtualFile file = event.getFile();
        if (!FileUtils.isFileSupported(file)) {
            return;
        }

        String newFileUri = FileUtils.VFSToURI(file);
        String oldParentUri = FileUtils.VFSToURI(event.getOldParent());
        if (newFileUri == null || oldParentUri == null) {
            return;
        }
        String oldFileUri = String.format("%s/%s", oldParentUri, event.getFileName());

        ApplicationUtils.invokeAfterPsiEvents(() -> {
            // Notifies the language server.
            FileUtils.findProjectsFor(file).forEach(p -> changedConfiguration(oldFileUri,
                FileUtils.projectToUri(p), FileChangeType.Deleted));
            FileUtils.findProjectsFor(file).forEach(p -> changedConfiguration(newFileUri,
                FileUtils.projectToUri(p), FileChangeType.Created));

            FileUtils.findProjectsFor(file).forEach(p -> {
                // Detaches old file from the wrappers.
                Set<LanguageServerWrapper> wrappers = IntellijLanguageClient.getAllServerWrappersFor(FileUtils.projectToUri(p));
                if (wrappers != null) {
                    wrappers.forEach(wrapper -> wrapper.disconnect(oldFileUri, FileUtils.projectToUri(p)));
                }
                // Re-open file to so that the new editor will be connected to the language server.
                FileEditorManager fileEditorManager = FileEditorManager.getInstance(p);
                ApplicationUtils.invokeLater(() -> {
                    fileEditorManager.closeFile(file);
                    fileEditorManager.openFile(file, true);
                });
            });
        });
    } catch (Exception e) {
        LOG.warn("LSP file move event failed due to :", e);
    }
}
 
Example #3
Source File: FileMonitor.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
@Override
public void fileMoved(VirtualFileMoveEvent event) {
	check();
}
 
Example #4
Source File: AutoSyncHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void fileMoved(VirtualFileMoveEvent event) {
  handleFileEvent(event);
}
 
Example #5
Source File: ArtifactVirtualFileListener.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void fileMoved(@Nonnull VirtualFileMoveEvent event) {
  final String oldPath = event.getOldParent().getPath() + "/" + event.getFileName();
  filePathChanged(oldPath, event.getNewParent().getPath() + "/" + event.getFileName());
}
 
Example #6
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired when a virtual file is moved from within IDEA.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void fileMoved(@NotNull VirtualFileMoveEvent event) {
    LSPFileEventManager.fileMoved(event);
}
 
Example #7
Source File: VFSListener.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Fired before the movement of a file is processed.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void beforeFileMovement(@NotNull VirtualFileMoveEvent event) {
}
 
Example #8
Source File: LocalFilesystemModificationHandler.java    From saros with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Intellij offers multiple ways of moving resources through the UI that are handled in
 * different ways internally:
 * <li><i>Move file to other package:</i>
 *
 *     <p>Triggers the move listener for the file.
 * <li><i>Move package to other package</i> and <i>Move package to other source root:</i>
 *
 *     <p>Just triggers the move listener for the package directory, does not trigger a
 *     listener event for the contained files or folders. This means the listener has to
 *     iterate the contained resources and create matching actions in the right order.
 * <li><i>Move package to other directory:</i>
 *
 *     <p>Triggers the create listener for the new path of the contained directories in
 *     right order. Then triggers the move listener for the contained files. Then triggers
 *     the delete listener for the old path of the contained directories.
 */
@Override
public void beforeFileMovement(@NotNull VirtualFileMoveEvent event) {
  generateResourceMoveActivity(event);
}