use of com.intellij.openapi.fileChooser.FileSystemTree in project intellij-community by JetBrains.
the class VirtualFileArrayRule method getData.
@Override
public Object getData(final DataProvider dataProvider) {
// Try to detect multiselection.
Set<VirtualFile> result = null;
FileSystemTree fileSystemTree = FileSystemTree.DATA_KEY.getData(dataProvider);
if (fileSystemTree != null) {
result = addFiles(result, fileSystemTree.getSelectedFiles());
}
Project project = PlatformDataKeys.PROJECT_CONTEXT.getData(dataProvider);
if (project != null && !project.isDisposed()) {
result = addFiles(result, ProjectRootManager.getInstance(project).getContentRoots());
}
Module[] selectedModules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataProvider);
if (selectedModules != null && selectedModules.length > 0) {
for (Module selectedModule : selectedModules) {
result = addFiles(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
}
}
Module selectedModule = LangDataKeys.MODULE_CONTEXT.getData(dataProvider);
if (selectedModule != null && !selectedModule.isDisposed()) {
result = addFiles(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
}
PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataProvider);
if (psiElements != null) {
for (PsiElement element : psiElements) {
result = addFilesFromPsiElement(result, element);
}
}
result = addFile(result, CommonDataKeys.VIRTUAL_FILE.getData(dataProvider));
PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataProvider);
if (psiFile != null) {
result = addFile(result, psiFile.getVirtualFile());
}
if (result != null) {
return VfsUtilCore.toVirtualFileArray(result);
}
PsiElement elem = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
if (elem != null) {
result = addFilesFromPsiElement(result, elem);
}
Usage[] usages = UsageView.USAGES_KEY.getData(dataProvider);
UsageTarget[] usageTargets = UsageView.USAGE_TARGETS_KEY.getData(dataProvider);
if (usages != null || usageTargets != null) {
for (VirtualFile file : UsageDataUtil.provideVirtualFileArray(usages, usageTargets)) {
result = addFile(result, file);
}
}
if (result == null) {
final Object[] objects = (Object[]) dataProvider.getData(PlatformDataKeys.SELECTED_ITEMS.getName());
if (objects != null) {
final VirtualFile[] files = new VirtualFile[objects.length];
for (int i = 0, objectsLength = objects.length; i < objectsLength; i++) {
Object object = objects[i];
if (!(object instanceof VirtualFile))
return null;
files[i] = (VirtualFile) object;
}
return files;
}
return null;
} else {
return VfsUtilCore.toVirtualFileArray(result);
}
}
use of com.intellij.openapi.fileChooser.FileSystemTree in project intellij-community by JetBrains.
the class ShowHiddensAction method update.
@Override
public void update(AnActionEvent e) {
super.update(e);
FileSystemTree tree = e.getData(FileSystemTree.DATA_KEY);
e.getPresentation().setEnabled(tree != null);
}
use of com.intellij.openapi.fileChooser.FileSystemTree in project intellij-community by JetBrains.
the class FileChooserAction method actionPerformed.
public final void actionPerformed(AnActionEvent e) {
FileSystemTree tree = e.getData(FileSystemTree.DATA_KEY);
actionPerformed(tree, e);
}
use of com.intellij.openapi.fileChooser.FileSystemTree in project intellij-community by JetBrains.
the class JdkPopupAction method showPopupMenu.
private static void showPopupMenu(AnActionEvent e, final ArrayList<Pair<File, String>> jdkLocations, boolean showInMiddle, JComponent component) {
ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(e.getPlace(), new ActionGroup() {
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
List<AnAction> result = new ArrayList<>();
for (final Pair<File, String> homes : jdkLocations) {
result.add(new FileChooserAction("", null, null) {
@Override
protected void update(FileSystemTree fileChooser, AnActionEvent e) {
e.getPresentation().setText(homes.getSecond(), false);
boolean selected = false;
VirtualFile selectedFile = fileChooser.getSelectedFile();
if (selectedFile != null) {
selected = homes.getFirst().getAbsolutePath().equals(VfsUtilCore.virtualToIoFile(selectedFile).getAbsolutePath());
}
e.getPresentation().setIcon(selected ? AllIcons.Diff.CurrentLine : null);
}
@Override
protected void actionPerformed(FileSystemTree fileChooser, AnActionEvent e) {
fileChooser.select(VfsUtil.findFileByIoFile(homes.getFirst(), true), null);
}
});
}
return result.toArray(new AnAction[result.size()]);
}
});
JPopupMenu menuComponent = menu.getComponent();
if (showInMiddle) {
menuComponent.show(component, (component.getWidth() - menuComponent.getWidth()) / 2, (component.getHeight() - menuComponent.getHeight()) / 2);
} else {
menuComponent.show(component, 0, component.getHeight());
}
}
use of com.intellij.openapi.fileChooser.FileSystemTree in project intellij-community by JetBrains.
the class JdkPopupAction method update.
@Override
public void update(AnActionEvent e) {
boolean enabled = isEnabledInCurrentOS();
if (enabled) {
FileSystemTree tree = FileSystemTree.DATA_KEY.getData(e.getDataContext());
if (tree == null || Boolean.TRUE != tree.getData(JavaSdkImpl.KEY)) {
enabled = false;
}
}
e.getPresentation().setEnabled(enabled);
e.getPresentation().setVisible(enabled);
}
Aggregations