use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class YAMLKeyValueImpl method getPresentation.
@Override
public ItemPresentation getPresentation() {
final YAMLFile yamlFile = (YAMLFile) getContainingFile();
final PsiElement value = getValue();
return new ItemPresentation() {
public String getPresentableText() {
if (value instanceof YAMLScalar) {
return getValueText();
}
return getName();
}
public String getLocationString() {
return "[" + yamlFile.getName() + "]";
}
public Icon getIcon(boolean open) {
return YAMLKeyValueImpl.this.getIcon(0);
}
};
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class Bookmark method getQualifiedName.
public String getQualifiedName() {
String presentableUrl = myFile.getPresentableUrl();
if (myFile.isDirectory())
return presentableUrl;
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
if (psiFile == null)
return presentableUrl;
StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile);
if (builder instanceof TreeBasedStructureViewBuilder) {
StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(null);
Object element;
try {
element = model.getCurrentEditorElement();
} finally {
model.dispose();
}
if (element instanceof NavigationItem) {
ItemPresentation presentation = ((NavigationItem) element).getPresentation();
if (presentation != null) {
presentableUrl = ((NavigationItem) element).getName() + " " + presentation.getLocationString();
}
}
}
return IdeBundle.message("bookmark.file.X.line.Y", presentableUrl, getLine() + 1);
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class ShowRecentFindUsagesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
Project project = e.getData(CommonDataKeys.PROJECT);
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
List<ConfigurableUsageTarget> history = new ArrayList<>(findUsagesManager.getHistory().getAll());
if (!history.isEmpty()) {
// skip most recent find usage, it's under your nose
history.remove(history.size() - 1);
Collections.reverse(history);
}
if (history.isEmpty()) {
// to fill the popup
history.add(null);
}
BaseListPopupStep<ConfigurableUsageTarget> step = new BaseListPopupStep<ConfigurableUsageTarget>(FindBundle.message("recent.find.usages.action.title"), history) {
@Override
public Icon getIconFor(final ConfigurableUsageTarget data) {
ItemPresentation presentation = data == null ? null : data.getPresentation();
return presentation == null ? null : presentation.getIcon(false);
}
@Override
@NotNull
public String getTextFor(final ConfigurableUsageTarget data) {
if (data == null) {
return FindBundle.message("recent.find.usages.action.nothing");
}
return data.getLongDescriptiveName();
}
@Override
public PopupStep onChosen(final ConfigurableUsageTarget selectedValue, final boolean finalChoice) {
return doFinalStep(() -> {
if (selectedValue != null) {
TransactionGuard.getInstance().submitTransactionAndWait(() -> findUsagesManager.rerunAndRecallFromHistory(selectedValue));
}
});
}
};
RelativePoint point;
if (e.getInputEvent() instanceof MouseEvent) {
point = new RelativePoint((MouseEvent) e.getInputEvent());
} else {
point = new RelativePoint(usageView.getComponent(), new Point(4, 4));
}
JBPopupFactory.getInstance().createListPopup(step).show(point);
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class HighlightOverridingMethodsHandler method computeUsages.
@Override
public void computeUsages(final List<PsiClass> classes) {
for (PsiMethod method : myClass.getMethods()) {
List<HierarchicalMethodSignature> superSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
for (HierarchicalMethodSignature superSignature : superSignatures) {
PsiClass containingClass = superSignature.getMethod().getContainingClass();
if (containingClass == null)
continue;
for (PsiClass classToAnalyze : classes) {
if (InheritanceUtil.isInheritorOrSelf(classToAnalyze, containingClass, true)) {
PsiIdentifier identifier = method.getNameIdentifier();
if (identifier != null) {
addOccurrence(identifier);
break;
}
}
}
}
}
if (myReadUsages.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode())
return;
String name;
if (classes.size() == 1) {
final ItemPresentation presentation = classes.get(0).getPresentation();
name = presentation != null ? presentation.getPresentableText() : "";
} else {
name = "";
}
myHintText = CodeInsightBundle.message("no.methods.overriding.0.are.found", classes.size(), name);
} else {
addOccurrence(myTarget);
// exclude 'target' keyword
final int methodCount = myReadUsages.size() - 1;
myStatusText = CodeInsightBundle.message("status.bar.overridden.methods.highlighted.message", methodCount, HighlightUsagesHandler.getShortcutText());
}
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class PyStructureViewTest method testInvalidatedElement.
// EA-83566
public void testInvalidatedElement() {
myFixture.configureByText("a.py", "def f():\n" + " pass");
final PyFunction function = myFixture.findElementByText("f", PyFunction.class);
final PyStructureViewElement node = new PyStructureViewElement(function);
WriteCommandAction.runWriteCommandAction(myFixture.getProject(), function::delete);
assertNull(node.getValue());
final ItemPresentation presentation = node.getPresentation();
assertNotNull(presentation);
final Icon icon = presentation.getIcon(false);
assertNull(icon);
}
Aggregations