Search in sources :

Example 1 with ConfigurableUsageTarget

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;
    }
}
Also used : ConfigurableUsageTarget(com.intellij.usages.ConfigurableUsageTarget) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ConfigurableUsageTarget

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()]);
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurableUsageTarget(com.intellij.usages.ConfigurableUsageTarget) ArrayList(java.util.ArrayList) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ConfigurableUsageTarget

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);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) ItemPresentation(com.intellij.navigation.ItemPresentation) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) UsageView(com.intellij.usages.UsageView) Project(com.intellij.openapi.project.Project) ConfigurableUsageTarget(com.intellij.usages.ConfigurableUsageTarget) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager)

Aggregations

ConfigurableUsageTarget (com.intellij.usages.ConfigurableUsageTarget)3 FindUsagesManager (com.intellij.find.findUsages.FindUsagesManager)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 ItemPresentation (com.intellij.navigation.ItemPresentation)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 UsageView (com.intellij.usages.UsageView)1 MouseEvent (java.awt.event.MouseEvent)1