mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support lazy calculation of tooltip for breadcrumbs
This commit is contained in:
@@ -55,11 +55,6 @@ public class JsonBreadcrumbsProvider implements BreadcrumbsProvider {
|
||||
return JsonSchemaDocumentationProvider.findSchemaAndGenerateDoc(e, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeferredTooltipEvaluation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends Action> getContextActions(@NotNull PsiElement element) {
|
||||
|
||||
@@ -55,13 +55,6 @@ public interface BreadcrumbsProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return should return true in case when tooltip evaluation is slow
|
||||
*/
|
||||
default boolean isDeferredTooltipEvaluation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element that represents a single crumb
|
||||
* @return an element that represents a parent crumb, or {@code null}
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface Crumb {
|
||||
public Impl(@NotNull BreadcrumbsProvider provider, @NotNull PsiElement element) {
|
||||
this(provider.getElementIcon(element),
|
||||
provider.getElementInfo(element),
|
||||
provider.isDeferredTooltipEvaluation() ? null : provider.getElementTooltip(element),
|
||||
provider.getElementTooltip(element),
|
||||
provider.getContextActions(element));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,31 +7,29 @@ import com.intellij.ui.breadcrumbs.BreadcrumbsProvider;
|
||||
import com.intellij.ui.components.breadcrumbs.Crumb;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author Sergey.Malenkov
|
||||
*/
|
||||
final class PsiCrumb extends Crumb.Impl {
|
||||
private final PsiAnchor anchor;
|
||||
private final Function<PsiElement, String> tooltipEvaluator;
|
||||
private BreadcrumbsProvider provider;
|
||||
private String tooltip;
|
||||
CrumbPresentation presentation;
|
||||
|
||||
PsiCrumb(PsiElement element, BreadcrumbsProvider provider) {
|
||||
super(provider, element);
|
||||
super(provider.getElementIcon(element), provider.getElementInfo(element), null, provider.getContextActions(element));
|
||||
anchor = PsiAnchor.create(element);
|
||||
tooltipEvaluator = provider.isDeferredTooltipEvaluation() ? e -> provider.getElementTooltip(e) : null;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
if (tooltipEvaluator != null) {
|
||||
if (tooltip == null && provider != null) {
|
||||
PsiElement element = getElement(this);
|
||||
if (element != null) {
|
||||
return tooltipEvaluator.apply(element);
|
||||
}
|
||||
if (element != null) tooltip = provider.getElementTooltip(element);
|
||||
provider = null; // do not try recalculate tooltip
|
||||
}
|
||||
return super.getTooltip();
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user