Skip to content

833: Added Open In Find Tool Window action to the Navigate to plugins linemarker #933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.linemarker;

import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator;
import com.intellij.ide.util.DefaultPsiElementCellRenderer;
import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import java.awt.event.MouseEvent;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;

public class SearchGutterIconNavigationHandler<T extends PsiElement>
implements GutterIconNavigationHandler<T> {

private final Collection<? extends NavigatablePsiElement> myReferences;
private final @NotNull String popupTitle;

/**
* Search gutter icon navigation handler constructor.
*
* @param references Collection
* @param popupTitle String
*/
public SearchGutterIconNavigationHandler(
final Collection<? extends NavigatablePsiElement> references,
final @NotNull String popupTitle
) {
this.popupTitle = popupTitle;
myReferences = references;
}

@Override
public void navigate(final MouseEvent event, final T elt) {
PsiElementListNavigator.openTargets(
event,
myReferences.toArray(NavigatablePsiElement.EMPTY_NAVIGATABLE_ELEMENT_ARRAY),
popupTitle,
"Open in Find Tool Window",// Ignored
new DefaultPsiElementCellRenderer()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@

package com.magento.idea.magento2plugin.linemarker.php;

import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.icons.AllIcons;
import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.indexing.FileBasedIndex;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.magento.idea.magento2plugin.linemarker.SearchGutterIconNavigationHandler;
import com.magento.idea.magento2plugin.project.Settings;
import com.magento.idea.magento2plugin.stubs.indexes.PluginIndex;
import java.util.ArrayList;
Expand All @@ -39,6 +42,7 @@ public class PluginLineMarkerProvider implements LineMarkerProvider {
}

@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void collectSlowLineMarkers(
final @NotNull List<? extends PsiElement> psiElements,
final @NotNull Collection<? super LineMarkerInfo<?>> collection
Expand Down Expand Up @@ -69,12 +73,21 @@ public void collectSlowLineMarkers(
}

if (!results.isEmpty()) {
final GutterIconNavigationHandler<PsiElement> navigationHandler =
new SearchGutterIconNavigationHandler<>(
(Collection<? extends NavigatablePsiElement>) results,
TOOLTIP_TEXT
);

collection.add(
NavigationGutterIconBuilder
.create(AllIcons.Nodes.Plugin)
.setTargets(results)
.setTooltipText(TOOLTIP_TEXT)
.createLineMarkerInfo(PsiTreeUtil.getDeepestFirst(psiElement))
.createLineMarkerInfo(
PsiTreeUtil.getDeepestFirst(psiElement),
navigationHandler
)
);
}
}
Expand Down