Search in sources :

Example 1 with FileSystemTree

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Usage(com.intellij.usages.Usage) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 2 with FileSystemTree

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);
}
Also used : FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree)

Example 3 with FileSystemTree

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);
}
Also used : FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree)

Example 4 with FileSystemTree

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserAction(com.intellij.openapi.fileChooser.actions.FileChooserAction) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) List(java.util.List) FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree) Pair(com.intellij.openapi.util.Pair)

Example 5 with FileSystemTree

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);
}
Also used : FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree)

Aggregations

FileSystemTree (com.intellij.openapi.fileChooser.FileSystemTree)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Presentation (com.intellij.openapi.actionSystem.Presentation)1 FileChooserAction (com.intellij.openapi.fileChooser.actions.FileChooserAction)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 Usage (com.intellij.usages.Usage)1 UsageTarget (com.intellij.usages.UsageTarget)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1