Search in sources :

Example 11 with Navigatable

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

the class OpenInEditorAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    if (!ActionPlaces.isToolbarPlace(e.getPlace())) {
        e.getPresentation().setEnabledAndVisible(true);
        return;
    }
    DiffRequest request = e.getData(DiffDataKeys.DIFF_REQUEST);
    DiffContext context = e.getData(DiffDataKeys.DIFF_CONTEXT);
    if (DiffUtil.isUserDataFlagSet(DiffUserDataKeys.GO_TO_SOURCE_DISABLE, request, context)) {
        e.getPresentation().setVisible(false);
        e.getPresentation().setEnabled(false);
    }
    if (e.getProject() == null) {
        e.getPresentation().setVisible(true);
        e.getPresentation().setEnabled(false);
        return;
    }
    Navigatable[] navigatables = e.getData(DiffDataKeys.NAVIGATABLE_ARRAY);
    if (navigatables == null || !ContainerUtil.exists(navigatables, (it) -> it.canNavigate())) {
        e.getPresentation().setVisible(true);
        e.getPresentation().setEnabled(false);
        return;
    }
    e.getPresentation().setEnabledAndVisible(true);
}
Also used : DiffContext(com.intellij.diff.DiffContext) DiffRequest(com.intellij.diff.requests.DiffRequest) Navigatable(com.intellij.pom.Navigatable)

Example 12 with Navigatable

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

the class SMTRunnerConsoleProperties method getErrorNavigatable.

@Nullable
@Override
public Navigatable getErrorNavigatable(@NotNull final Project project, @NotNull final String stacktrace) {
    if (myCustomFilter.isEmpty()) {
        return null;
    }
    // iterate stacktrace lines find first navigatable line using
    // stacktrace filters
    final int stacktraceLength = stacktrace.length();
    final String[] lines = StringUtil.splitByLines(stacktrace);
    for (String line : lines) {
        Filter.Result result;
        try {
            result = myCustomFilter.applyFilter(line, stacktraceLength);
        } catch (Throwable t) {
            throw new RuntimeException("Error while applying " + myCustomFilter + " to '" + line + "'", t);
        }
        final HyperlinkInfo info = result != null ? result.getFirstHyperlinkInfo() : null;
        if (info != null) {
            // covers 99% use existing cases
            if (info instanceof FileHyperlinkInfo) {
                return ((FileHyperlinkInfo) info).getDescriptor();
            }
            // otherwise
            return new Navigatable() {

                @Override
                public void navigate(boolean requestFocus) {
                    info.navigate(project);
                }

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

                @Override
                public boolean canNavigateToSource() {
                    return true;
                }
            };
        }
    }
    return null;
}
Also used : CompositeFilter(com.intellij.execution.filters.CompositeFilter) Filter(com.intellij.execution.filters.Filter) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with Navigatable

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

the class OpenRepositoryVersionAction method openRepositoryVersion.

private static void openRepositoryVersion(@NotNull Project project, @NotNull Change[] changes) {
    for (Change change : changes) {
        ContentRevision revision = change.getAfterRevision();
        if (revision == null || revision.getFile().isDirectory())
            continue;
        VirtualFile vFile = ContentRevisionVirtualFile.create(revision);
        Navigatable navigatable = new OpenFileDescriptor(project, vFile);
        navigatable.navigate(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentRevisionVirtualFile(com.intellij.openapi.vcs.vfs.ContentRevisionVirtualFile) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Change(com.intellij.openapi.vcs.changes.Change) Navigatable(com.intellij.pom.Navigatable)

Example 14 with Navigatable

use of com.intellij.pom.Navigatable in project android by JetBrains.

the class EditMultipleSourcesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final Navigatable[] files = e.getData(CommonDataKeys.NAVIGATABLE_ARRAY);
    assert files != null && files.length > 0;
    if (files.length > 1) {
        DefaultListModel listModel = new DefaultListModel();
        for (int i = 0; i < files.length; ++i) {
            assert files[i] instanceof PsiClassNavigation;
            //noinspection unchecked
            listModel.add(i, ((PsiClassNavigation) files[i]).getPsiFile());
        }
        final JBList list = new JBList(listModel);
        int width = WindowManager.getInstance().getFrame(project).getSize().width;
        list.setCellRenderer(new GotoFileCellRenderer(width));
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(new Runnable() {

            @Override
            public void run() {
                Object selectedValue = list.getSelectedValue();
                PsiClassNavigation navigationWrapper = null;
                for (Navigatable file : files) {
                    if (selectedValue == ((PsiClassNavigation) file).getPsiFile()) {
                        navigationWrapper = (PsiClassNavigation) file;
                        break;
                    }
                }
                assert navigationWrapper != null;
                if (navigationWrapper.canNavigate()) {
                    navigationWrapper.navigate(true);
                }
            }
        }).createPopup();
        if (e.getInputEvent().getSource() instanceof ActionButton) {
            popup.showUnderneathOf((ActionButton) e.getInputEvent().getSource());
        } else {
            popup.showInBestPositionFor(e.getDataContext());
        }
    } else {
        assert files[0] instanceof PsiClassNavigation;
        PsiClassNavigation file = (PsiClassNavigation) files[0];
        if (file.canNavigate()) {
            file.navigate(true);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GotoFileCellRenderer(com.intellij.ide.util.gotoByName.GotoFileCellRenderer) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Navigatable(com.intellij.pom.Navigatable)

Example 15 with Navigatable

use of com.intellij.pom.Navigatable in project android by JetBrains.

the class SyncMessages method report.

public void report(@NotNull SyncMessage message) {
    String title = message.getGroup();
    String text = join(message.getText(), "\n");
    NotificationCategory category = message.getType().convertToCategory();
    PositionInFile position = message.getPosition();
    NotificationData notification = createNotification(title, text, category, position);
    Navigatable navigatable = message.getNavigatable();
    notification.setNavigatable(navigatable);
    List<NotificationHyperlink> quickFixes = message.getQuickFixes();
    if (!quickFixes.isEmpty()) {
        updateNotification(notification, text, quickFixes);
    }
    report(notification);
}
Also used : PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) Navigatable(com.intellij.pom.Navigatable) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

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