Search in sources :

Example 1 with OptionDescription

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

the class GotoActionAction method openOptionOrPerformAction.

public static void openOptionOrPerformAction(@NotNull Object element, final String enteredText, @Nullable final Project project, Component component, @Nullable AnActionEvent e) {
    if (element instanceof OptionDescription) {
        OptionDescription optionDescription = (OptionDescription) element;
        final String configurableId = optionDescription.getConfigurableId();
        Disposable disposable = project != null ? project : ApplicationManager.getApplication();
        TransactionGuard guard = TransactionGuard.getInstance();
        if (optionDescription.hasExternalEditor()) {
            guard.submitTransactionLater(disposable, () -> optionDescription.invokeInternalEditor());
        } else {
            guard.submitTransactionLater(disposable, () -> ShowSettingsUtilImpl.showSettingsDialog(project, configurableId, enteredText));
        }
    } else {
        ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> performAction(element, component, e)));
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) OptionDescription(com.intellij.ide.ui.search.OptionDescription) TransactionGuard(com.intellij.openapi.application.TransactionGuard)

Example 2 with OptionDescription

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

the class PluginOptionsTopHitProvider method getOptions.

@NotNull
@Override
public Collection<OptionDescription> getOptions(@Nullable Project project) {
    ArrayList<OptionDescription> options = new ArrayList<>();
    ApplicationInfoEx applicationInfo = ApplicationInfoEx.getInstanceEx();
    for (IdeaPluginDescriptor pluginDescriptor : PluginManagerCore.getPlugins()) {
        if (applicationInfo.isEssentialPlugin(pluginDescriptor.getPluginId().getIdString())) {
            continue;
        }
        options.add(new PluginBooleanOptionDescriptor(pluginDescriptor.getPluginId()));
    }
    return options;
}
Also used : OptionDescription(com.intellij.ide.ui.search.OptionDescription) ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) ArrayList(java.util.ArrayList) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with OptionDescription

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

the class InspectionsTopHitProvider method getOptions.

@NotNull
@Override
public Collection<OptionDescription> getOptions(@Nullable Project project) {
    if (project == null)
        return ContainerUtil.emptyList();
    List<OptionDescription> result = ContainerUtil.newArrayList();
    List<Tools> tools = InspectionProjectProfileManager.getInstance(project).getCurrentProfile().getAllEnabledInspectionTools(project);
    for (Tools tool : tools) {
        result.add(new ToolOptionDescription(tool, project));
    }
    return result;
}
Also used : OptionDescription(com.intellij.ide.ui.search.OptionDescription) Tools(com.intellij.codeInspection.ex.Tools) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with OptionDescription

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

the class OptionsTopHitProvider method consumeTopHits.

@Override
public final void consumeTopHits(@NonNls String pattern, Consumer<Object> collector, Project project) {
    if (!pattern.startsWith("#"))
        return;
    pattern = pattern.substring(1);
    final List<String> parts = StringUtil.split(pattern, " ");
    if (parts.size() == 0) {
        return;
    }
    String id = parts.get(0);
    if (getId().startsWith(id) || pattern.startsWith(" ")) {
        if (pattern.startsWith(" ")) {
            pattern = pattern.trim();
        } else {
            pattern = pattern.substring(id.length()).trim().toLowerCase();
        }
        final MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
        for (OptionDescription option : getOptions(project)) {
            if (matcher.matches(option.getOption())) {
                collector.consume(option);
            }
        }
    }
}
Also used : OptionDescription(com.intellij.ide.ui.search.OptionDescription) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 5 with OptionDescription

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

the class GotoActionItemProvider method processOptions.

private boolean processOptions(String pattern, Processor<MatchedValue> consumer, DataContext dataContext) {
    Map<String, String> map = myModel.getConfigurablesNames();
    SearchableOptionsRegistrarImpl registrar = (SearchableOptionsRegistrarImpl) SearchableOptionsRegistrar.getInstance();
    List<Comparable> options = ContainerUtil.newArrayList();
    final Set<String> words = registrar.getProcessedWords(pattern);
    Set<OptionDescription> optionDescriptions = null;
    final String actionManagerName = myActionManager.getComponentName();
    for (String word : words) {
        final Set<OptionDescription> descriptions = registrar.getAcceptableDescriptions(word);
        if (descriptions != null) {
            for (Iterator<OptionDescription> iterator = descriptions.iterator(); iterator.hasNext(); ) {
                OptionDescription description = iterator.next();
                if (actionManagerName.equals(description.getPath())) {
                    iterator.remove();
                }
            }
            if (!descriptions.isEmpty()) {
                if (optionDescriptions == null) {
                    optionDescriptions = descriptions;
                } else {
                    optionDescriptions.retainAll(descriptions);
                }
            }
        } else {
            optionDescriptions = null;
            break;
        }
    }
    if (!StringUtil.isEmptyOrSpaces(pattern)) {
        Matcher matcher = NameUtil.buildMatcher("*" + pattern).build();
        if (optionDescriptions == null)
            optionDescriptions = ContainerUtil.newTroveSet();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (matcher.matches(entry.getValue())) {
                optionDescriptions.add(new OptionDescription(null, entry.getKey(), entry.getValue(), null, entry.getValue()));
            }
        }
    }
    if (optionDescriptions != null && !optionDescriptions.isEmpty()) {
        Set<String> currentHits = new HashSet<>();
        for (Iterator<OptionDescription> iterator = optionDescriptions.iterator(); iterator.hasNext(); ) {
            OptionDescription description = iterator.next();
            final String hit = description.getHit();
            if (hit == null || !currentHits.add(hit.trim())) {
                iterator.remove();
            }
        }
        for (OptionDescription description : optionDescriptions) {
            for (ActionFromOptionDescriptorProvider converter : ActionFromOptionDescriptorProvider.EP.getExtensions()) {
                AnAction action = converter.provide(description);
                if (action != null)
                    options.add(new ActionWrapper(action, null, MatchMode.NAME, dataContext));
                options.add(description);
            }
        }
    }
    return processItems(pattern, JBIterable.from(options), consumer);
}
Also used : OptionDescription(com.intellij.ide.ui.search.OptionDescription) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) Matcher(com.intellij.util.text.Matcher) SearchableOptionsRegistrarImpl(com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl) ActionFromOptionDescriptorProvider(com.intellij.ide.ui.search.ActionFromOptionDescriptorProvider)

Aggregations

OptionDescription (com.intellij.ide.ui.search.OptionDescription)5 MinusculeMatcher (com.intellij.psi.codeStyle.MinusculeMatcher)2 NotNull (org.jetbrains.annotations.NotNull)2 Tools (com.intellij.codeInspection.ex.Tools)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 ActionFromOptionDescriptorProvider (com.intellij.ide.ui.search.ActionFromOptionDescriptorProvider)1 BooleanOptionDescription (com.intellij.ide.ui.search.BooleanOptionDescription)1 SearchableOptionsRegistrarImpl (com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl)1 Disposable (com.intellij.openapi.Disposable)1 TransactionGuard (com.intellij.openapi.application.TransactionGuard)1 ApplicationInfoEx (com.intellij.openapi.application.ex.ApplicationInfoEx)1 Matcher (com.intellij.util.text.Matcher)1 ArrayList (java.util.ArrayList)1