Search in sources :

Example 6 with Matcher

use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.

the class GotoActionItemProvider method processActions.

private boolean processActions(String pattern, boolean everywhere, Processor<MatchedValue> consumer, DataContext dataContext) {
    JBIterable<AnAction> actions;
    if (everywhere) {
        Set<String> ids = ((ActionManagerImpl) myActionManager).getActionIds();
        actions = JBIterable.from(ids).transform(myActionManager::getAction).filter(Condition.NOT_NULL);
    } else {
        actions = JBIterable.from(myModel.myActionGroups.keySet());
    }
    MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
    JBIterable<ActionWrapper> actionWrappers = actions.transform(action -> {
        MatchMode mode = myModel.actionMatches(pattern, matcher, action);
        if (mode == MatchMode.NONE)
            return null;
        return new ActionWrapper(action, myModel.myActionGroups.get(action), mode, dataContext);
    }).filter(Condition.NOT_NULL);
    return processItems(pattern, actionWrappers, consumer);
}
Also used : CollectConsumer(com.intellij.util.CollectConsumer) java.util(java.util) JBIterable(com.intellij.util.containers.JBIterable) ApplyIntentionAction(com.intellij.ide.actions.ApplyIntentionAction) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) ContainerUtil(com.intellij.util.containers.ContainerUtil) ActionFromOptionDescriptorProvider(com.intellij.ide.ui.search.ActionFromOptionDescriptorProvider) NameUtil(com.intellij.psi.codeStyle.NameUtil) SearchableOptionsRegistrarImpl(com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl) Project(com.intellij.openapi.project.Project) SearchableOptionsRegistrar(com.intellij.ide.ui.search.SearchableOptionsRegistrar) Matcher(com.intellij.util.text.Matcher) DataManager(com.intellij.ide.DataManager) ProgressManager(com.intellij.openapi.progress.ProgressManager) StringUtil(com.intellij.openapi.util.text.StringUtil) NotNullLazyValue(com.intellij.openapi.util.NotNullLazyValue) ActionManagerImpl(com.intellij.openapi.actionSystem.impl.ActionManagerImpl) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GotoActionModel(com.intellij.ide.util.gotoByName.GotoActionModel) OptionDescription(com.intellij.ide.ui.search.OptionDescription) Processor(com.intellij.util.Processor) OptionsTopHitProvider(com.intellij.ide.ui.OptionsTopHitProvider) NotNull(org.jetbrains.annotations.NotNull) SearchTopHitProvider(com.intellij.ide.SearchTopHitProvider) Condition(com.intellij.openapi.util.Condition) ActionManagerImpl(com.intellij.openapi.actionSystem.impl.ActionManagerImpl) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 7 with Matcher

use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.

the class PluginsTableRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (myPluginDescriptor != null) {
        Couple<Color> colors = UIUtil.getCellColors(table, isSelected, row, column);
        Color fg = colors.getFirst();
        final Color background = colors.getSecond();
        Color grayedFg = isSelected ? fg : new JBColor(Gray._130, Gray._120);
        myPanel.setBackground(background);
        myName.setForeground(fg);
        myCategory.setForeground(grayedFg);
        myStatus.setForeground(grayedFg);
        myLastUpdated.setForeground(grayedFg);
        myDownloads.setForeground(grayedFg);
        myName.clear();
        myName.setOpaque(false);
        myCategory.clear();
        myCategory.setOpaque(false);
        String pluginName = myPluginDescriptor.getName() + "  ";
        Object query = table.getClientProperty(SpeedSearchSupply.SEARCH_QUERY_KEY);
        SimpleTextAttributes attr = new SimpleTextAttributes(UIUtil.getListBackground(isSelected), UIUtil.getListForeground(isSelected), JBColor.RED, SimpleTextAttributes.STYLE_PLAIN);
        Matcher matcher = NameUtil.buildMatcher("*" + query, NameUtil.MatchingCaseSensitivity.NONE);
        if (query instanceof String) {
            SpeedSearchUtil.appendColoredFragmentForMatcher(pluginName, myName, attr, matcher, UIUtil.getTableBackground(isSelected), true);
        } else {
            myName.append(pluginName);
        }
        String category = myPluginDescriptor.getCategory() == null ? null : StringUtil.toUpperCase(myPluginDescriptor.getCategory());
        if (category != null) {
            if (query instanceof String) {
                SpeedSearchUtil.appendColoredFragmentForMatcher(category, myCategory, attr, matcher, UIUtil.getTableBackground(isSelected), true);
            } else {
                myCategory.append(category);
            }
        } else if (!myPluginsView) {
            myCategory.append(AvailablePluginsManagerMain.N_A);
        }
        myStatus.setIcon(AllIcons.Nodes.Plugin);
        if (myPluginDescriptor.isBundled()) {
            myCategory.append(" [Bundled]");
            myStatus.setIcon(AllIcons.Nodes.PluginJB);
        }
        String vendor = myPluginDescriptor.getVendor();
        if (vendor != null && StringUtil.containsIgnoreCase(vendor, "jetbrains")) {
            myStatus.setIcon(AllIcons.Nodes.PluginJB);
        }
        String downloads = myPluginDescriptor.getDownloads();
        if (downloads != null && myPluginDescriptor instanceof PluginNode) {
            if (downloads.length() > 3) {
                downloads = new DecimalFormat("#,###").format(Integer.parseInt(downloads));
            }
            myDownloads.setText(downloads);
            myRating.setRate(((PluginNode) myPluginDescriptor).getRating());
            myLastUpdated.setText(DateFormatUtil.formatBetweenDates(((PluginNode) myPluginDescriptor).getDate(), System.currentTimeMillis()));
        }
        // plugin state-dependent rendering
        PluginId pluginId = myPluginDescriptor.getPluginId();
        IdeaPluginDescriptor installed = PluginManager.getPlugin(pluginId);
        if (installed != null && ((IdeaPluginDescriptorImpl) installed).isDeleted()) {
            // existing plugin uninstalled (both views)
            myStatus.setIcon(AllIcons.Nodes.PluginRestart);
            if (!isSelected)
                myName.setForeground(FileStatus.DELETED.getColor());
            myPanel.setToolTipText(IdeBundle.message("plugin.manager.uninstalled.tooltip"));
        } else if (ourState.wasInstalled(pluginId)) {
            // new plugin installed (both views)
            myStatus.setIcon(AllIcons.Nodes.PluginRestart);
            if (!isSelected)
                myName.setForeground(FileStatus.ADDED.getColor());
            myPanel.setToolTipText(IdeBundle.message("plugin.manager.installed.tooltip"));
        } else if (ourState.wasUpdated(pluginId)) {
            // existing plugin updated (both views)
            myStatus.setIcon(AllIcons.Nodes.PluginRestart);
            if (!isSelected)
                myName.setForeground(FileStatus.ADDED.getColor());
            myPanel.setToolTipText(IdeBundle.message("plugin.manager.updated.tooltip"));
        } else if (ourState.hasNewerVersion(pluginId)) {
            // existing plugin has a newer version (both views)
            myStatus.setIcon(AllIcons.Nodes.Pluginobsolete);
            if (!isSelected)
                myName.setForeground(FileStatus.MODIFIED.getColor());
            if (!myPluginsView && installed != null) {
                myPanel.setToolTipText(IdeBundle.message("plugin.manager.new.version.tooltip", installed.getVersion()));
            } else {
                myPanel.setToolTipText(IdeBundle.message("plugin.manager.update.available.tooltip"));
            }
        } else if (isIncompatible(myPluginDescriptor, table.getModel())) {
            // a plugin is incompatible with current installation (both views)
            if (!isSelected)
                myName.setForeground(JBColor.RED);
            myPanel.setToolTipText(whyIncompatible(myPluginDescriptor, table.getModel()));
        } else if (!myPluginDescriptor.isEnabled() && myPluginsView) {
            // a plugin is disabled (plugins view only)
            myStatus.setIcon(IconLoader.getDisabledIcon(myStatus.getIcon()));
        }
    }
    return myPanel;
}
Also used : Matcher(com.intellij.util.text.Matcher) JBColor(com.intellij.ui.JBColor) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) DecimalFormat(java.text.DecimalFormat) JBColor(com.intellij.ui.JBColor) PluginId(com.intellij.openapi.extensions.PluginId)

Example 8 with Matcher

use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.

the class ChooseByNameBase method rebuildList.

protected void rebuildList(final int pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (!myInitialized) {
        return;
    }
    myAlarm.cancelAllRequests();
    if (delay > 0) {
        myAlarm.addRequest(() -> rebuildList(pos, 0, modalityState, postRunnable), delay, ModalityState.stateForComponent(myTextField));
        return;
    }
    myListUpdater.cancelAll();
    final CalcElementsThread calcElementsThread = myCalcElementsThread;
    if (calcElementsThread != null) {
        calcElementsThread.cancel();
    }
    final String text = getTrimmedText();
    if (!canShowListForEmptyPattern() && text.isEmpty()) {
        myListModel.removeAll();
        hideList();
        myTextFieldPanel.hideHint();
        myCard.show(myCardContainer, CHECK_BOX_CARD);
        return;
    }
    ListCellRenderer cellRenderer = myList.getCellRenderer();
    if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) {
        cellRenderer = ((ExpandedItemListCellRendererWrapper) cellRenderer).getWrappee();
    }
    final String pattern = patternToLowerCase(transformPattern(text));
    final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern);
    if (cellRenderer instanceof MatcherHolder) {
        ((MatcherHolder) cellRenderer).setPatternMatcher(matcher);
    }
    MatcherHolder.associateMatcher(myList, matcher);
    scheduleCalcElements(text, myCheckBox.isSelected(), modalityState, elements -> {
        ApplicationManager.getApplication().assertIsDispatchThread();
        backgroundCalculationFinished(elements, pos);
        if (postRunnable != null) {
            postRunnable.run();
        }
    });
}
Also used : Matcher(com.intellij.util.text.Matcher) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) MatcherHolder(com.intellij.util.text.MatcherHolder)

Aggregations

Matcher (com.intellij.util.text.Matcher)8 MinusculeMatcher (com.intellij.psi.codeStyle.MinusculeMatcher)6 DataManager (com.intellij.ide.DataManager)3 ActionFromOptionDescriptorProvider (com.intellij.ide.ui.search.ActionFromOptionDescriptorProvider)3 OptionDescription (com.intellij.ide.ui.search.OptionDescription)3 SearchableOptionsRegistrarImpl (com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl)3 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 ProgressManager (com.intellij.openapi.progress.ProgressManager)3 Project (com.intellij.openapi.project.Project)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 NameUtil (com.intellij.psi.codeStyle.NameUtil)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 java.util (java.util)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 SearchTopHitProvider (com.intellij.ide.SearchTopHitProvider)2 ApplyIntentionAction (com.intellij.ide.actions.ApplyIntentionAction)2 OptionsTopHitProvider (com.intellij.ide.ui.OptionsTopHitProvider)2 SearchableOptionsRegistrar (com.intellij.ide.ui.search.SearchableOptionsRegistrar)2