use of com.intellij.usages.ConfigurableUsageTarget in project intellij-community by JetBrains.
the class UsageHistory method getAll.
@NotNull
public List<ConfigurableUsageTarget> getAll() {
synchronized (myHistory) {
List<ConfigurableUsageTarget> result = ContainerUtil.newArrayList();
final Set<ConfigurableUsageTarget> entries = myHistory.keySet();
for (Iterator<ConfigurableUsageTarget> iterator = entries.iterator(); iterator.hasNext(); ) {
final ConfigurableUsageTarget target = iterator.next();
if (!target.isValid()) {
iterator.remove();
} else {
result.add(target);
}
}
return result;
}
}
use of com.intellij.usages.ConfigurableUsageTarget in project intellij-community by JetBrains.
the class ShowRecentFindUsagesGroup method getChildren.
@Override
@NotNull
public AnAction[] getChildren(@Nullable final AnActionEvent e) {
if (e == null)
return EMPTY_ARRAY;
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null || DumbService.isDumb(project))
return EMPTY_ARRAY;
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
List<ConfigurableUsageTarget> history = new ArrayList<>(findUsagesManager.getHistory().getAll());
Collections.reverse(history);
String description = ActionManager.getInstance().getAction(UsageViewImpl.SHOW_RECENT_FIND_USAGES_ACTION_ID).getTemplatePresentation().getDescription();
List<AnAction> children = new ArrayList<>(history.size());
for (final ConfigurableUsageTarget usageTarget : history) {
if (!usageTarget.isValid()) {
continue;
}
String text = usageTarget.getLongDescriptiveName();
AnAction action = new AnAction(text, description, null) {
@Override
public void actionPerformed(final AnActionEvent e) {
findUsagesManager.rerunAndRecallFromHistory(usageTarget);
}
};
children.add(action);
}
return children.toArray(new AnAction[children.size()]);
}
use of com.intellij.usages.ConfigurableUsageTarget 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);
}
Aggregations