Search in sources :

Example 21 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class GotoFileAction method gotoActionPerformed.

@Override
public void gotoActionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null)
        return;
    FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
    final GotoFileModel gotoFileModel = new GotoFileModel(project);
    GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() {

        @Override
        protected ChooseByNameFilter<FileType> createFilter(@NotNull ChooseByNamePopup popup) {
            return new GotoFileFilter(popup, gotoFileModel, project);
        }

        @Override
        public void elementChosen(final ChooseByNamePopup popup, final Object element) {
            if (element == null)
                return;
            ApplicationManager.getApplication().assertIsDispatchThread();
            Navigatable n = (Navigatable) element;
            //this is for better cursor position
            if (element instanceof PsiFile) {
                VirtualFile file = ((PsiFile) element).getVirtualFile();
                if (file == null)
                    return;
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
                n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
            }
            if (n.canNavigate()) {
                n.navigate(true);
            }
        }
    };
    GotoFileItemProvider provider = new GotoFileItemProvider(project, getPsiContext(e), gotoFileModel);
    showNavigationPopup(e, gotoFileModel, callback, IdeBundle.message("go.to.file.toolwindow.title"), true, true, provider);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) Navigatable(com.intellij.pom.Navigatable) Project(com.intellij.openapi.project.Project) FileType(com.intellij.openapi.fileTypes.FileType) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) GotoFileModel(com.intellij.ide.util.gotoByName.GotoFileModel) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 22 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class StructureViewComponent method getData.

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        TreePath path = getSelectedUniquePath();
        if (path == null)
            return null;
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object element = getNodeValue(node);
        if (element instanceof StructureViewTreeElement) {
            element = ((StructureViewTreeElement) element).getValue();
        }
        if (!(element instanceof PsiElement))
            return null;
        if (!((PsiElement) element).isValid())
            return null;
        return element;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return convertToPsiElementsArray(getSelectedElements());
    }
    if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
        return myFileEditor;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCutProvider();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCopyProvider();
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getPasteProvider();
    }
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        Object[] selectedElements = getSelectedTreeElements();
        if (selectedElements == null || selectedElements.length == 0)
            return null;
        if (selectedElements[0] instanceof Navigatable) {
            return selectedElements[0];
        }
    }
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return getHelpID();
    }
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
    }
    return super.getData(dataId);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsiElement(com.intellij.psi.PsiElement) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) Navigatable(com.intellij.pom.Navigatable)

Example 23 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class SlicePanel method getNavigatables.

@NotNull
private List<Navigatable> getNavigatables() {
    TreePath[] paths = myTree.getSelectionPaths();
    if (paths == null)
        return Collections.emptyList();
    final ArrayList<Navigatable> navigatables = new ArrayList<>();
    for (TreePath path : paths) {
        Object lastPathComponent = path.getLastPathComponent();
        if (lastPathComponent instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastPathComponent;
            Object userObject = node.getUserObject();
            if (userObject instanceof Navigatable) {
                navigatables.add((Navigatable) userObject);
            } else if (node instanceof Navigatable) {
                navigatables.add((Navigatable) node);
            }
        }
    }
    return navigatables;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) Navigatable(com.intellij.pom.Navigatable) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class RunConfigurationNode method getNavigatable.

@Nullable
@Override
public Navigatable getNavigatable() {
    return new Navigatable() {

        @Override
        public void navigate(boolean requestFocus) {
            RunManager.getInstance(myProject).setSelectedConfiguration(mySettings);
            EditConfigurationsDialog dialog = new EditConfigurationsDialog(myProject);
            dialog.show();
        }

        @Override
        public boolean canNavigate() {
            return true;
        }

        @Override
        public boolean canNavigateToSource() {
            return false;
        }
    };
}
Also used : EditConfigurationsDialog(com.intellij.execution.impl.EditConfigurationsDialog) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 25 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class GotoTargetHandler method show.

private void show(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull final GotoData gotoData) {
    final PsiElement[] targets = gotoData.targets;
    final List<AdditionalAction> additionalActions = gotoData.additionalActions;
    if (targets.length == 0 && additionalActions.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
        return;
    }
    boolean finished = gotoData.listUpdaterTask == null || gotoData.listUpdaterTask.isFinished();
    if (targets.length == 1 && additionalActions.isEmpty() && finished) {
        navigateToElement(targets[0]);
        return;
    }
    for (PsiElement eachTarget : targets) {
        gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
    }
    final String name = ((PsiNamedElement) gotoData.source).getName();
    final String title = getChooserTitle(gotoData.source, name, targets.length, finished);
    if (shouldSortTargets()) {
        Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
    }
    List<Object> allElements = new ArrayList<>(targets.length + additionalActions.size());
    Collections.addAll(allElements, targets);
    allElements.addAll(additionalActions);
    final JBList list = new JBList(new CollectionListModel<>(allElements));
    HintUpdateSupply.installSimpleHintUpdateSupply(list);
    list.setFont(EditorUtil.getEditorFont());
    list.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value == null)
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof AdditionalAction) {
                return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            }
            PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
            return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    final Runnable runnable = () -> {
        int[] ids = list.getSelectedIndices();
        if (ids == null || ids.length == 0)
            return;
        Object[] selectedElements = list.getSelectedValues();
        for (Object element : selectedElements) {
            if (element instanceof AdditionalAction) {
                ((AdditionalAction) element).execute();
            } else {
                Navigatable nav = element instanceof Navigatable ? (Navigatable) element : EditSourceUtil.getDescriptor((PsiElement) element);
                try {
                    if (nav != null && nav.canNavigate()) {
                        navigateToElement(nav);
                    }
                } catch (IndexNotReadyException e) {
                    DumbService.getInstance(project).showDumbModeNotification("Navigation is not available while indexing");
                }
            }
        }
    };
    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setFilteringEnabled(o -> {
        if (o instanceof AdditionalAction) {
            return ((AdditionalAction) o).getText();
        }
        return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
    });
    final Ref<UsageView> usageView = new Ref<>();
    final JBPopup popup = builder.setTitle(title).setItemChoosenCallback(runnable).setMovable(true).setCancelCallback(() -> {
        HintUpdateSupply.hideHint(list);
        final ListBackgroundUpdaterTask task = gotoData.listUpdaterTask;
        if (task != null) {
            task.cancelTask();
        }
        return true;
    }).setCouldPin(popup1 -> {
        usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), gotoData.source.getProject()));
        popup1.cancel();
        return false;
    }).setAdText(getAdText(gotoData.source, targets.length)).createPopup();
    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);
    if (gotoData.listUpdaterTask != null) {
        Alarm alarm = new Alarm(popup);
        alarm.addRequest(() -> popup.showInBestPositionFor(editor), 300);
        gotoData.listUpdaterTask.init((AbstractPopup) popup, list, usageView);
        ProgressManager.getInstance().run(gotoData.listUpdaterTask);
    } else {
        popup.showInBestPositionFor(editor);
    }
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) Navigatable(com.intellij.pom.Navigatable) UsageView(com.intellij.usages.UsageView) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) Ref(com.intellij.openapi.util.Ref) Alarm(com.intellij.util.Alarm) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer)

Aggregations

Navigatable (com.intellij.pom.Navigatable)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)19 Project (com.intellij.openapi.project.Project)14 Nullable (org.jetbrains.annotations.Nullable)14 PsiElement (com.intellij.psi.PsiElement)11 ArrayList (java.util.ArrayList)9 PsiFile (com.intellij.psi.PsiFile)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 TreePath (javax.swing.tree.TreePath)7 NotNull (org.jetbrains.annotations.NotNull)6 Editor (com.intellij.openapi.editor.Editor)4 List (java.util.List)4 TextRange (com.intellij.openapi.util.TextRange)3 XmlTag (com.intellij.psi.xml.XmlTag)3 BlazeConsoleView (com.google.idea.blaze.base.console.BlazeConsoleView)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2