Search in sources :

Example 1 with OptionsTopHitProvider

use of com.intellij.ide.ui.OptionsTopHitProvider in project intellij-community by JetBrains.

the class GotoActionItemProvider method processTopHits.

private static boolean processTopHits(String pattern, Processor<MatchedValue> consumer, DataContext dataContext) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final CollectConsumer<Object> collector = new CollectConsumer<>();
    for (SearchTopHitProvider provider : SearchTopHitProvider.EP_NAME.getExtensions()) {
        if (provider instanceof OptionsTopHitProvider.CoveredByToggleActions)
            continue;
        if (provider instanceof OptionsTopHitProvider && !((OptionsTopHitProvider) provider).isEnabled(project))
            continue;
        if (provider instanceof OptionsTopHitProvider && !StringUtil.startsWith(pattern, "#")) {
            String prefix = "#" + ((OptionsTopHitProvider) provider).getId() + " ";
            provider.consumeTopHits(prefix + pattern, collector, project);
        }
        provider.consumeTopHits(pattern, collector, project);
    }
    Collection<Object> result = collector.getResult();
    return processItems(pattern, JBIterable.from(result).filter(Comparable.class), consumer);
}
Also used : Project(com.intellij.openapi.project.Project) CollectConsumer(com.intellij.util.CollectConsumer) OptionsTopHitProvider(com.intellij.ide.ui.OptionsTopHitProvider) SearchTopHitProvider(com.intellij.ide.SearchTopHitProvider)

Example 2 with OptionsTopHitProvider

use of com.intellij.ide.ui.OptionsTopHitProvider in project intellij-community by JetBrains.

the class SearchEverywhereAction method doNavigate.

private void doNavigate(final int index) {
    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null)
        return;
    final Project project = CommonDataKeys.PROJECT.getData(dataManager.getDataContext(getField().getTextEditor()));
    assert project != null;
    final SearchListModel model = getModel();
    if (isMoreItem(index)) {
        final String pattern = myPopupField.getText();
        WidgetID wid = null;
        if (index == model.moreIndex.classes)
            wid = WidgetID.CLASSES;
        else if (index == model.moreIndex.files)
            wid = WidgetID.FILES;
        else if (index == model.moreIndex.settings)
            wid = WidgetID.SETTINGS;
        else if (index == model.moreIndex.actions)
            wid = WidgetID.ACTIONS;
        else if (index == model.moreIndex.symbols)
            wid = WidgetID.SYMBOLS;
        else if (index == model.moreIndex.runConfigurations)
            wid = WidgetID.RUN_CONFIGURATIONS;
        if (wid != null) {
            final WidgetID widgetID = wid;
            myCurrentWorker.doWhenProcessed(() -> {
                myCalcThread = new CalcThread(project, pattern, true);
                myPopupActualWidth = 0;
                myCurrentWorker = myCalcThread.insert(index, widgetID);
            });
            return;
        }
    }
    final String pattern = getField().getText();
    final Object value = myList.getSelectedValue();
    saveHistory(project, pattern, value);
    IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(getField().getTextEditor());
    if (myPopup != null && myPopup.isVisible()) {
        myPopup.cancel();
    }
    if (value instanceof BooleanOptionDescription) {
        final BooleanOptionDescription option = (BooleanOptionDescription) value;
        option.setOptionState(!option.isOptionEnabled());
        myList.revalidate();
        myList.repaint();
        getGlobalInstance().doWhenFocusSettlesDown(() -> {
            getGlobalInstance().requestFocus(getField(), true);
        });
        return;
    }
    if (value instanceof OptionsTopHitProvider) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> getField().setText("#" + ((OptionsTopHitProvider) value).getId() + " "));
        return;
    }
    Runnable onDone = null;
    AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        if (value instanceof PsiElement) {
            onDone = () -> NavigationUtil.activateFileWithPsiElement((PsiElement) value, true);
            return;
        } else if (isVirtualFile(value)) {
            onDone = () -> OpenSourceUtil.navigate(true, new OpenFileDescriptor(project, (VirtualFile) value));
            return;
        } else if (isActionValue(value) || isSetting(value) || isRunConfiguration(value)) {
            focusManager.requestDefaultFocus(true);
            final Component comp = myContextComponent;
            final AnActionEvent event = myActionEvent;
            IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> {
                Component c = comp;
                if (c == null) {
                    c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
                }
                if (isRunConfiguration(value)) {
                    ChooseRunConfigurationPopup.ItemWrapper itemWrapper = (ChooseRunConfigurationPopup.ItemWrapper) value;
                    RunnerAndConfigurationSettings settings = ObjectUtils.tryCast(itemWrapper.getValue(), RunnerAndConfigurationSettings.class);
                    if (settings != null) {
                        Executor executor = findExecutor(settings);
                        if (executor != null) {
                            itemWrapper.perform(project, executor, dataManager.getDataContext(c));
                        }
                    }
                } else {
                    GotoActionAction.openOptionOrPerformAction(value, pattern, project, c, event);
                    if (isToolWindowAction(value))
                        return;
                }
            });
            return;
        } else if (value instanceof Navigatable) {
            onDone = () -> OpenSourceUtil.navigate(true, (Navigatable) value);
            return;
        }
    } finally {
        token.finish();
        final ActionCallback callback = onFocusLost();
        if (onDone != null) {
            callback.doWhenDone(onDone);
        }
    }
    focusManager.requestDefaultFocus(true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataManager(com.intellij.ide.DataManager) Navigatable(com.intellij.pom.Navigatable) Project(com.intellij.openapi.project.Project) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) AccessToken(com.intellij.openapi.application.AccessToken) BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) ChooseRunConfigurationPopup(com.intellij.execution.actions.ChooseRunConfigurationPopup) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) OptionsTopHitProvider(com.intellij.ide.ui.OptionsTopHitProvider) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Aggregations

OptionsTopHitProvider (com.intellij.ide.ui.OptionsTopHitProvider)2 Project (com.intellij.openapi.project.Project)2 Executor (com.intellij.execution.Executor)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ChooseRunConfigurationPopup (com.intellij.execution.actions.ChooseRunConfigurationPopup)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 DataManager (com.intellij.ide.DataManager)1 SearchTopHitProvider (com.intellij.ide.SearchTopHitProvider)1 BooleanOptionDescription (com.intellij.ide.ui.search.BooleanOptionDescription)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 AccessToken (com.intellij.openapi.application.AccessToken)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Navigatable (com.intellij.pom.Navigatable)1 CollectConsumer (com.intellij.util.CollectConsumer)1