light edit: support LightEditGotoOpenedFileAction in new file chooser

GitOrigin-RevId: 4c8941ba45e432a9eb80c4b25e60d7841e3256e2
This commit is contained in:
Sergey Simonchik
2022-11-14 22:17:51 +00:00
committed by intellij-monorepo-bot
parent f0f9a73e9b
commit 03ce9e3099
@@ -4,6 +4,7 @@ package com.intellij.ide.lightEdit.actions;
import com.intellij.ide.lightEdit.LightEdit;
import com.intellij.ide.lightEdit.LightEditCompatible;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileChooserPanel;
import com.intellij.openapi.fileChooser.FileSystemTree;
import com.intellij.openapi.fileChooser.actions.FileChooserAction;
import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -13,8 +14,19 @@ import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
public final class LightEditGotoOpenedFileAction extends FileChooserAction implements LightEditCompatible {
@Override
protected void actionPerformed(@NotNull FileChooserPanel panel, @NotNull AnActionEvent e) {
Path file = getSelectedNioPath(e.getProject());
Path parent = file != null ? file.getParent() : null;
if (parent != null) {
panel.load(parent);
}
}
@Override
protected void actionPerformed(@NotNull FileSystemTree fileSystemTree, @NotNull AnActionEvent e) {
Project project = e.getProject();
@@ -24,21 +36,29 @@ public final class LightEditGotoOpenedFileAction extends FileChooserAction imple
}
}
@Override
protected void update(@NotNull FileChooserPanel panel, @NotNull AnActionEvent e) {
e.getPresentation().setEnabled(getSelectedNioPath(e.getProject()) != null);
}
@Override
protected void update(@NotNull FileSystemTree fileSystemTree, @NotNull AnActionEvent e) {
Project project = e.getProject();
if (LightEdit.owns(project)) {
e.getPresentation().setEnabled(getSelectedFile(fileSystemTree, project) != null);
}
else {
e.getPresentation().setEnabledAndVisible(false);
}
e.getPresentation().setEnabled(getSelectedFile(fileSystemTree, e.getProject()) != null);
}
private static @Nullable Path getSelectedNioPath(@Nullable Project project) {
VirtualFile file = getSelectedFile(project);
return file != null ? file.toNioPath() : null;
}
private static @Nullable VirtualFile getSelectedFile(@NotNull FileSystemTree fileSystemTree, @Nullable Project project) {
VirtualFile file = getSelectedFile(project);
return file != null && file.getParent() != null && fileSystemTree.isUnderRoots(file) ? file : null;
}
private static @Nullable VirtualFile getSelectedFile(@Nullable Project project) {
if (LightEdit.owns(project)) {
VirtualFile file = ArrayUtil.getFirstElement(FileEditorManager.getInstance(project).getSelectedFiles());
return file != null && file.getParent() != null && fileSystemTree.isUnderRoots(file) ? file : null;
return ArrayUtil.getFirstElement(FileEditorManager.getInstance(project).getSelectedFiles());
}
return null;
}