mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (dead code; warnings; formatting)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.ui.search;
|
||||
|
||||
import com.intellij.application.options.OptionsContainingConfigurable;
|
||||
@@ -34,31 +33,30 @@ import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
import com.intellij.openapi.options.ex.ConfigurableWrapper;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Used by Installer's build buildSearchableOptions step. In order to run locally use TraverseUi configuration.
|
||||
* Pass corresponding -Didea.platform.prefix=YOUR_IDE_PREFIX to vm options and choose main_YOUR_IDE module
|
||||
* Used in installer's "build searchable options" step.
|
||||
*
|
||||
* In order to run locally, use "TraverseUi" run configuration (pass corresponding "idea.platform.prefix" property via VM options,
|
||||
* and choose correct main module).
|
||||
*/
|
||||
@SuppressWarnings({"CallToPrintStackTrace", "SynchronizeOnThis"})
|
||||
@SuppressWarnings({"CallToPrintStackTrace", "SynchronizeOnThis", "UseOfSystemOutOrSystemErr"})
|
||||
public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
@NonNls private static final String OPTIONS = "options";
|
||||
@NonNls private static final String CONFIGURABLE = "configurable";
|
||||
@NonNls private static final String ID = "id";
|
||||
@NonNls private static final String CONFIGURABLE_NAME = "configurable_name";
|
||||
@NonNls private static final String OPTION = "option";
|
||||
@NonNls private static final String NAME = "name";
|
||||
@NonNls private static final String PATH = "path";
|
||||
@NonNls private static final String HIT = "hit";
|
||||
private static final String OPTIONS = "options";
|
||||
private static final String CONFIGURABLE = "configurable";
|
||||
private static final String ID = "id";
|
||||
private static final String CONFIGURABLE_NAME = "configurable_name";
|
||||
private static final String OPTION = "option";
|
||||
private static final String NAME = "name";
|
||||
private static final String PATH = "path";
|
||||
private static final String HIT = "hit";
|
||||
|
||||
private String OUTPUT_PATH;
|
||||
|
||||
@@ -68,7 +66,6 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNls
|
||||
public String getCommandName() {
|
||||
return "traverseUI";
|
||||
}
|
||||
@@ -79,7 +76,7 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void main(String[] args){
|
||||
public void main(String[] args) {
|
||||
System.out.println("Starting searchable options index builder");
|
||||
try {
|
||||
startup(OUTPUT_PATH);
|
||||
@@ -93,52 +90,54 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
}
|
||||
|
||||
public static void startup(String outputPath) throws IOException {
|
||||
final HashMap<SearchableConfigurable, TreeSet<OptionDescription>> options =
|
||||
new HashMap<>();
|
||||
Map<SearchableConfigurable, Set<OptionDescription>> options = new HashMap<>();
|
||||
SearchUtil.processProjectConfigurables(ProjectManager.getInstance().getDefaultProject(), options);
|
||||
|
||||
Element root = new Element(OPTIONS);
|
||||
for (SearchableConfigurable configurable : options.keySet()) {
|
||||
for (SearchableConfigurable option : options.keySet()) {
|
||||
SearchableConfigurable configurable = option;
|
||||
|
||||
Element configurableElement = new Element(CONFIGURABLE);
|
||||
final String id = configurable.getId();
|
||||
if (id == null) continue;
|
||||
String id = configurable.getId();
|
||||
configurableElement.setAttribute(ID, id);
|
||||
configurableElement.setAttribute(CONFIGURABLE_NAME, configurable.getDisplayName());
|
||||
final TreeSet<OptionDescription> sortedOptions = options.get(configurable);
|
||||
Set<OptionDescription> sortedOptions = options.get(configurable);
|
||||
writeOptions(configurableElement, sortedOptions);
|
||||
|
||||
if (configurable instanceof ConfigurableWrapper) {
|
||||
final UnnamedConfigurable wrapped = ((ConfigurableWrapper)configurable).getConfigurable();
|
||||
UnnamedConfigurable wrapped = ((ConfigurableWrapper)configurable).getConfigurable();
|
||||
if (wrapped instanceof SearchableConfigurable) {
|
||||
configurable = (SearchableConfigurable)wrapped;
|
||||
}
|
||||
}
|
||||
if (configurable instanceof KeymapPanel){
|
||||
if (configurable instanceof KeymapPanel) {
|
||||
processKeymap(configurableElement);
|
||||
} else if (configurable instanceof OptionsContainingConfigurable){
|
||||
}
|
||||
else if (configurable instanceof OptionsContainingConfigurable) {
|
||||
processOptionsContainingConfigurable((OptionsContainingConfigurable)configurable, configurableElement);
|
||||
} else if (configurable instanceof PluginManagerConfigurable) {
|
||||
final TreeSet<OptionDescription> descriptions = wordsToOptionDescriptors(Collections.singleton(AvailablePluginsManagerMain.MANAGE_REPOSITORIES));
|
||||
for (OptionDescription description : descriptions) {
|
||||
}
|
||||
else if (configurable instanceof PluginManagerConfigurable) {
|
||||
for (OptionDescription description : wordsToOptionDescriptors(Collections.singleton(AvailablePluginsManagerMain.MANAGE_REPOSITORIES))) {
|
||||
append(null, AvailablePluginsManagerMain.MANAGE_REPOSITORIES, description.getOption(), configurableElement);
|
||||
}
|
||||
} else if (configurable instanceof AllFileTemplatesConfigurable) {
|
||||
}
|
||||
else if (configurable instanceof AllFileTemplatesConfigurable) {
|
||||
processFileTemplates(configurableElement);
|
||||
}
|
||||
|
||||
root.addContent(configurableElement);
|
||||
configurable.disposeUIResources();
|
||||
}
|
||||
final File file = new File(outputPath);
|
||||
if (!file.isFile()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
FileUtil.ensureCanCreateFile(new File(outputPath));
|
||||
JDOMUtil.writeDocument(new Document(root), outputPath, "\n");
|
||||
|
||||
System.out.println("Searchable options index builder completed");
|
||||
}
|
||||
|
||||
private static void processFileTemplates(Element configurableElement) {
|
||||
final SearchableOptionsRegistrar optionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
TreeSet<OptionDescription> options = new TreeSet<>();
|
||||
SearchableOptionsRegistrar optionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
Set<OptionDescription> options = new TreeSet<>();
|
||||
|
||||
FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
|
||||
processTemplates(optionsRegistrar, options, fileTemplateManager.getAllTemplates());
|
||||
@@ -149,45 +148,30 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
writeOptions(configurableElement, options);
|
||||
}
|
||||
|
||||
private static void processTemplates(SearchableOptionsRegistrar optionsRegistrar,
|
||||
TreeSet<OptionDescription> options,
|
||||
FileTemplate[] templates) {
|
||||
private static void processTemplates(SearchableOptionsRegistrar registrar, Set<OptionDescription> options, FileTemplate[] templates) {
|
||||
for (FileTemplate template : templates) {
|
||||
collectOptions(optionsRegistrar, options, template.getName());
|
||||
//collectOptions(optionsRegistrar, options, template.getDescription());
|
||||
collectOptions(registrar, options, template.getName(), null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectOptions(SearchableOptionsRegistrar optionsRegistrar,
|
||||
TreeSet<OptionDescription> options,
|
||||
String text) {
|
||||
collectOptions(optionsRegistrar, options, text, null);
|
||||
}
|
||||
|
||||
private static void collectOptions(SearchableOptionsRegistrar optionsRegistrar,
|
||||
TreeSet<OptionDescription> options,
|
||||
String text,
|
||||
String path) {
|
||||
final Set<String> strings = optionsRegistrar.getProcessedWordsWithoutStemming(text);
|
||||
for (String word : strings) {
|
||||
private static void collectOptions(SearchableOptionsRegistrar registrar, Set<OptionDescription> options, String text, String path) {
|
||||
for (String word : registrar.getProcessedWordsWithoutStemming(text)) {
|
||||
options.add(new OptionDescription(word, text, path));
|
||||
}
|
||||
}
|
||||
|
||||
private static void processOptionsContainingConfigurable(final OptionsContainingConfigurable configurable,
|
||||
final Element configurableElement) {
|
||||
final Set<String> optionsPath = configurable.processListOptions();
|
||||
final TreeSet<OptionDescription> result = wordsToOptionDescriptors(optionsPath);
|
||||
private static void processOptionsContainingConfigurable(OptionsContainingConfigurable configurable, Element configurableElement) {
|
||||
Set<String> optionsPath = configurable.processListOptions();
|
||||
Set<OptionDescription> result = wordsToOptionDescriptors(optionsPath);
|
||||
writeOptions(configurableElement, result);
|
||||
}
|
||||
|
||||
private static TreeSet<OptionDescription> wordsToOptionDescriptors(Set<String> optionsPath) {
|
||||
SearchableOptionsRegistrar searchableOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
final TreeSet<OptionDescription> result = new TreeSet<>();
|
||||
private static Set<OptionDescription> wordsToOptionDescriptors(Set<String> optionsPath) {
|
||||
SearchableOptionsRegistrar registrar = SearchableOptionsRegistrar.getInstance();
|
||||
Set<OptionDescription> result = new TreeSet<>();
|
||||
for (String opt : optionsPath) {
|
||||
final Set<String> words = searchableOptionsRegistrar.getProcessedWordsWithoutStemming(opt);
|
||||
for (String word : words) {
|
||||
if (word != null){
|
||||
for (String word : registrar.getProcessedWordsWithoutStemming(opt)) {
|
||||
if (word != null) {
|
||||
result.add(new OptionDescription(word, opt, null));
|
||||
}
|
||||
}
|
||||
@@ -195,7 +179,7 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void processKeymap(final Element configurableElement){
|
||||
private static void processKeymap(Element configurableElement) {
|
||||
final ActionManager actionManager = ActionManager.getInstance();
|
||||
final String componentName = actionManager.getComponentName();
|
||||
final SearchableOptionsRegistrar searchableOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
@@ -215,7 +199,7 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
writeOptions(configurableElement, options);
|
||||
}
|
||||
|
||||
private static void writeOptions(Element configurableElement, TreeSet<OptionDescription> options) {
|
||||
private static void writeOptions(Element configurableElement, Set<OptionDescription> options) {
|
||||
for (OptionDescription opt : options) {
|
||||
append(opt.getPath(), opt.getHit(), opt.getOption(), configurableElement);
|
||||
}
|
||||
@@ -230,4 +214,4 @@ public class TraverseUIStarter extends ApplicationStarterEx {
|
||||
optionElement.setAttribute(HIT, hit);
|
||||
configurableElement.addContent(optionElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.ui.search;
|
||||
|
||||
import com.intellij.application.options.SkipSelfSearchComponent;
|
||||
@@ -24,15 +23,12 @@ import com.intellij.openapi.options.MasterDetails;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.options.ex.GlassPanel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.TabbedPaneWrapper;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -40,36 +36,32 @@ import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 07-Feb-2006
|
||||
* @author anna
|
||||
* @since 07.02.2006
|
||||
*/
|
||||
public class SearchUtil {
|
||||
private static final Pattern HTML_PATTERN = Pattern.compile("<[^<>]*>");
|
||||
private static final Pattern QUOTED = Pattern.compile("\\\"([^\\\"]+)\\\"");
|
||||
private static final Pattern QUOTED = Pattern.compile("\"([^\"]+)\"");
|
||||
|
||||
public static final String HIGHLIGHT_WITH_BORDER = "searchUtil.highlightWithBorder";
|
||||
public static final String STYLE_END = "</style>";
|
||||
|
||||
private SearchUtil() {
|
||||
}
|
||||
private SearchUtil() { }
|
||||
|
||||
public static void processProjectConfigurables(Project project, HashMap<SearchableConfigurable, TreeSet<OptionDescription>> options) {
|
||||
public static void processProjectConfigurables(Project project, Map<SearchableConfigurable, Set<OptionDescription>> options) {
|
||||
processConfigurables(ShowSettingsUtilImpl.getConfigurables(project, false), options);
|
||||
}
|
||||
|
||||
private static void processConfigurables(final Configurable[] configurables,
|
||||
final HashMap<SearchableConfigurable, TreeSet<OptionDescription>> options) {
|
||||
private static void processConfigurables(Configurable[] configurables, Map<SearchableConfigurable, Set<OptionDescription>> options) {
|
||||
for (Configurable configurable : configurables) {
|
||||
if (configurable instanceof SearchableConfigurable) {
|
||||
TreeSet<OptionDescription> configurableOptions = new TreeSet<>();
|
||||
Set<OptionDescription> configurableOptions = new TreeSet<>();
|
||||
|
||||
if (configurable instanceof Configurable.Composite) {
|
||||
final Configurable[] children = ((Configurable.Composite)configurable).getConfigurables();
|
||||
@@ -86,26 +78,24 @@ public class SearchUtil {
|
||||
if (configurable instanceof MasterDetails) {
|
||||
final MasterDetails md = (MasterDetails)configurable;
|
||||
md.initUi();
|
||||
_processComponent(configurable, configurableOptions, md.getMaster());
|
||||
_processComponent(configurable, configurableOptions, md.getDetails().getComponent());
|
||||
processComponent(configurable, configurableOptions, md.getMaster());
|
||||
processComponent(configurable, configurableOptions, md.getDetails().getComponent());
|
||||
}
|
||||
else {
|
||||
_processComponent(configurable, configurableOptions, configurable.createComponent());
|
||||
processComponent(configurable, configurableOptions, configurable.createComponent());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void _processComponent(final Configurable configurable, final TreeSet<OptionDescription> configurableOptions,
|
||||
final JComponent component) {
|
||||
|
||||
if (component == null) return;
|
||||
|
||||
processUILabel(configurable.getDisplayName(), configurableOptions, null);
|
||||
processComponent(component, configurableOptions, null);
|
||||
private static void processComponent(Configurable configurable, Set<OptionDescription> configurableOptions, JComponent component) {
|
||||
if (component != null) {
|
||||
processUILabel(configurable.getDisplayName(), configurableOptions, null);
|
||||
processComponent(component, configurableOptions, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void processComponent(final JComponent component, final Set<OptionDescription> configurableOptions, @NonNls String path) {
|
||||
private static void processComponent(JComponent component, Set<OptionDescription> configurableOptions, String path) {
|
||||
if (component instanceof SkipSelfSearchComponent) return;
|
||||
final Border border = component.getBorder();
|
||||
if (border instanceof TitledBorder) {
|
||||
@@ -122,19 +112,19 @@ public class SearchUtil {
|
||||
}
|
||||
}
|
||||
else if (component instanceof JCheckBox) {
|
||||
@NonNls final String checkBoxTitle = ((JCheckBox)component).getText();
|
||||
final String checkBoxTitle = ((JCheckBox)component).getText();
|
||||
if (checkBoxTitle != null) {
|
||||
processUILabel(checkBoxTitle, configurableOptions, path);
|
||||
}
|
||||
}
|
||||
else if (component instanceof JRadioButton) {
|
||||
@NonNls final String radioButtonTitle = ((JRadioButton)component).getText();
|
||||
final String radioButtonTitle = ((JRadioButton)component).getText();
|
||||
if (radioButtonTitle != null) {
|
||||
processUILabel(radioButtonTitle, configurableOptions, path);
|
||||
}
|
||||
}
|
||||
else if (component instanceof JButton) {
|
||||
@NonNls final String buttonTitle = ((JButton)component).getText();
|
||||
final String buttonTitle = ((JButton)component).getText();
|
||||
if (buttonTitle != null) {
|
||||
processUILabel(buttonTitle, configurableOptions, path);
|
||||
}
|
||||
@@ -163,18 +153,15 @@ public class SearchUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void processUILabel(@NonNls final String title, final Set<OptionDescription> configurableOptions, String path) {
|
||||
private static void processUILabel(String title, Set<OptionDescription> configurableOptions, String path) {
|
||||
final Set<String> words = SearchableOptionsRegistrar.getInstance().getProcessedWordsWithoutStemming(title);
|
||||
@NonNls final String regex = "[\\W&&[^\\p{Punct}\\p{Blank}]]";
|
||||
final String regex = "[\\W&&[^\\p{Punct}\\p{Blank}]]";
|
||||
for (String option : words) {
|
||||
configurableOptions.add(new OptionDescription(option, HTML_PATTERN.matcher(title).replaceAll(" ").replaceAll(regex, " "), path));
|
||||
}
|
||||
}
|
||||
|
||||
public static Runnable lightOptions(final SearchableConfigurable configurable,
|
||||
final JComponent component,
|
||||
final String option,
|
||||
final GlassPanel glassPanel) {
|
||||
public static Runnable lightOptions(SearchableConfigurable configurable, JComponent component, String option, GlassPanel glassPanel) {
|
||||
return () -> {
|
||||
if (!traverseComponentsTree(configurable, glassPanel, component, option, true)) {
|
||||
traverseComponentsTree(configurable, glassPanel, component, option, false);
|
||||
@@ -191,7 +178,8 @@ public class SearchUtil {
|
||||
final Set<String> titleWords = searchableOptionsRegistrar.getProcessedWords(title);
|
||||
pathWords.removeAll(titleWords);
|
||||
if (pathWords.isEmpty()) return i;
|
||||
} else if (tabIdx.equalsIgnoreCase(title)) { //e.g. only stop words
|
||||
}
|
||||
else if (tabIdx.equalsIgnoreCase(title)) { //e.g. only stop words
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -210,12 +198,11 @@ public class SearchUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static boolean traverseComponentsTree(final SearchableConfigurable configurable,
|
||||
private static boolean traverseComponentsTree(SearchableConfigurable configurable,
|
||||
GlassPanel glassPanel,
|
||||
JComponent rootComponent,
|
||||
String option,
|
||||
boolean force) {
|
||||
|
||||
rootComponent.putClientProperty(HIGHLIGHT_WITH_BORDER, null);
|
||||
|
||||
if (option == null || option.trim().length() == 0) return false;
|
||||
@@ -271,7 +258,6 @@ public class SearchUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final Component[] components = rootComponent.getComponents();
|
||||
for (Component component : components) {
|
||||
if (component instanceof JComponent) {
|
||||
@@ -298,20 +284,19 @@ public class SearchUtil {
|
||||
return highlight;
|
||||
}
|
||||
|
||||
public static boolean isComponentHighlighted(String text, String option, final boolean force, final SearchableConfigurable configurable) {
|
||||
public static boolean isComponentHighlighted(String text, String option, boolean force, final SearchableConfigurable configurable) {
|
||||
if (text == null || option == null || option.length() == 0) return false;
|
||||
final SearchableOptionsRegistrar searchableOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
final Set<String> words = searchableOptionsRegistrar.getProcessedWords(option);
|
||||
final Set<String> options =
|
||||
configurable != null ? searchableOptionsRegistrar.replaceSynonyms(words, configurable) : words;
|
||||
final Set<String> options = configurable != null ? searchableOptionsRegistrar.replaceSynonyms(words, configurable) : words;
|
||||
if (options == null || options.isEmpty()) {
|
||||
return text.toLowerCase().indexOf(option.toLowerCase()) != -1;
|
||||
return text.toLowerCase(Locale.US).contains(option.toLowerCase(Locale.US));
|
||||
}
|
||||
final Set<String> tokens = searchableOptionsRegistrar.getProcessedWords(text);
|
||||
if (!force) {
|
||||
options.retainAll(tokens);
|
||||
final boolean highlight = !options.isEmpty();
|
||||
return highlight || text.toLowerCase().indexOf(option.toLowerCase()) != -1;
|
||||
return highlight || text.toLowerCase(Locale.US).contains(option.toLowerCase(Locale.US));
|
||||
}
|
||||
else {
|
||||
options.removeAll(tokens);
|
||||
@@ -319,7 +304,7 @@ public class SearchUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String markup(@NonNls @NotNull String textToMarkup, @Nullable String filter) {
|
||||
public static String markup(@NotNull String textToMarkup, @Nullable String filter) {
|
||||
if (filter == null || filter.length() == 0) {
|
||||
return textToMarkup;
|
||||
}
|
||||
@@ -332,11 +317,13 @@ public class SearchUtil {
|
||||
head = textToMarkup.substring(0, bodyStart);
|
||||
if (bodyEnd >= 0) {
|
||||
foot = textToMarkup.substring(bodyEnd);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
foot = "";
|
||||
}
|
||||
textToMarkup = textToMarkup.substring(bodyStart, bodyEnd);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
foot = "";
|
||||
head = "";
|
||||
}
|
||||
@@ -360,7 +347,7 @@ public class SearchUtil {
|
||||
|
||||
private static String quoteStrictOccurrences(final String textToMarkup, final String filter) {
|
||||
String cur = "";
|
||||
final String s = textToMarkup.toLowerCase();
|
||||
final String s = textToMarkup.toLowerCase(Locale.US);
|
||||
for (String part : filter.split(" ")) {
|
||||
if (s.contains(part)) {
|
||||
cur += "\"" + part + "\" ";
|
||||
@@ -372,13 +359,14 @@ public class SearchUtil {
|
||||
return cur;
|
||||
}
|
||||
|
||||
private static String markup(@NonNls String textToMarkup, final Pattern insideHtmlTagPattern, final String option) {
|
||||
private static String markup(String textToMarkup, final Pattern insideHtmlTagPattern, final String option) {
|
||||
final int styleIdx = textToMarkup.indexOf("<style");
|
||||
final int styleEndIdx = textToMarkup.indexOf("</style>");
|
||||
if (styleIdx < 0 || styleEndIdx < 0) {
|
||||
return markupInText(textToMarkup, insideHtmlTagPattern, option);
|
||||
}
|
||||
return markup(textToMarkup.substring(0, styleIdx), insideHtmlTagPattern, option) + markup(textToMarkup.substring(styleEndIdx + STYLE_END.length()), insideHtmlTagPattern, option);
|
||||
return markup(textToMarkup.substring(0, styleIdx), insideHtmlTagPattern, option) +
|
||||
markup(textToMarkup.substring(styleEndIdx + STYLE_END.length()), insideHtmlTagPattern, option);
|
||||
}
|
||||
|
||||
private static String markupInText(String textToMarkup, Pattern insideHtmlTagPattern, String option) {
|
||||
@@ -403,7 +391,7 @@ public class SearchUtil {
|
||||
}
|
||||
|
||||
public static void appendFragments(String filter,
|
||||
@NonNls String text,
|
||||
String text,
|
||||
@SimpleTextAttributes.StyleAttributeConstant int style,
|
||||
final Color foreground,
|
||||
final Color background,
|
||||
@@ -432,9 +420,10 @@ public class SearchUtil {
|
||||
final int start = index.intValue();
|
||||
if (pos > start) {
|
||||
final String highlighted = selectedWords.get(selectedWords.size() - 1);
|
||||
if (highlighted.length() < stripped.length()){
|
||||
if (highlighted.length() < stripped.length()) {
|
||||
selectedWords.remove(highlighted);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -469,111 +458,15 @@ public class SearchUtil {
|
||||
final Set<String> filters = SearchableOptionsRegistrar.getInstance().getProcessedWords(filter);
|
||||
final String[] words = text.substring(pos, end).split("[\\W&&[^-]]+");
|
||||
for (String word : words) {
|
||||
if (filters.contains(PorterStemmerUtil.stem(word.toLowerCase()))) {
|
||||
if (filters.contains(PorterStemmerUtil.stem(word.toLowerCase(Locale.US)))) {
|
||||
selectedWords.add(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JBPopup createPopup(final ConfigurableSearchTextField searchField,
|
||||
final JBPopup[] activePopup,
|
||||
final Alarm showHintAlarm,
|
||||
final Consumer<String> selectConfigurable,
|
||||
final Project project,
|
||||
final int down) {
|
||||
|
||||
final String filter = searchField.getText();
|
||||
if (filter == null || filter.length() == 0) return null;
|
||||
final Map<String, Set<String>> hints = SearchableOptionsRegistrar.getInstance().findPossibleExtension(filter, project);
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
final JList list = new JBList(model);
|
||||
for (String groupName : hints.keySet()) {
|
||||
model.addElement(groupName);
|
||||
final Set<String> descriptions = hints.get(groupName);
|
||||
if (descriptions != null) {
|
||||
for (String hit : descriptions) {
|
||||
if (hit == null) continue;
|
||||
model.addElement(new OptionDescription(null, groupName, hit, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
list.setCellRenderer(new DefaultListCellRenderer() {
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
final Component rendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if (value instanceof String) {
|
||||
setText("------ " + value + " ------");
|
||||
}
|
||||
else if (value instanceof OptionDescription) {
|
||||
setText(((OptionDescription)value).getHit());
|
||||
}
|
||||
return rendererComponent;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (model.size() > 0) {
|
||||
final Runnable onChosen = () -> {
|
||||
final Object selectedValue = list.getSelectedValue();
|
||||
if (selectedValue instanceof OptionDescription) {
|
||||
final OptionDescription description = ((OptionDescription)selectedValue);
|
||||
searchField.setText(description.getHit());
|
||||
searchField.addCurrentTextToHistory();
|
||||
SwingUtilities.invokeLater(() -> { //do not show look up again
|
||||
showHintAlarm.cancelAllRequests();
|
||||
selectConfigurable.consume(description.getConfigurableId());
|
||||
});
|
||||
}
|
||||
};
|
||||
final JBPopup popup = JBPopupFactory.getInstance()
|
||||
.createListPopupBuilder(list)
|
||||
.setItemChoosenCallback(onChosen)
|
||||
.setRequestFocus(down != 0)
|
||||
.createPopup();
|
||||
list.addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyCode() != KeyEvent.VK_ENTER && e.getKeyCode() != KeyEvent.VK_UP && e.getKeyCode() != KeyEvent.VK_DOWN &&
|
||||
e.getKeyCode() != KeyEvent.VK_PAGE_UP && e.getKeyCode() != KeyEvent.VK_PAGE_DOWN) {
|
||||
searchField.requestFocusInWindow();
|
||||
if (cancelPopups(activePopup) && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
return;
|
||||
}
|
||||
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
|
||||
searchField.process(
|
||||
new KeyEvent(searchField, KeyEvent.KEY_TYPED, e.getWhen(), e.getModifiers(), KeyEvent.VK_UNDEFINED, e.getKeyChar()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (down > 0) {
|
||||
if (list.getSelectedIndex() < list.getModel().getSize() - 1) {
|
||||
list.setSelectedIndex(list.getSelectedIndex() + 1);
|
||||
}
|
||||
}
|
||||
else if (down < 0) {
|
||||
if (list.getSelectedIndex() > 0) {
|
||||
list.setSelectedIndex(list.getSelectedIndex() - 1);
|
||||
}
|
||||
}
|
||||
return popup;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean cancelPopups(final JBPopup[] activePopup) {
|
||||
for (JBPopup popup : activePopup) {
|
||||
if (popup != null && popup.isVisible()) {
|
||||
popup.cancel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<Set<String>> findKeys(String filter, Set<String> quoted) {
|
||||
filter = processFilter(filter.toLowerCase(), quoted);
|
||||
filter = processFilter(filter.toLowerCase(Locale.US), quoted);
|
||||
final List<Set<String>> keySetList = new ArrayList<>();
|
||||
final SearchableOptionsRegistrar optionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
final Set<String> words = optionsRegistrar.getProcessedWords(filter);
|
||||
@@ -609,17 +502,6 @@ public class SearchUtil {
|
||||
return withoutQuoted + " " + filter.substring(beg);
|
||||
}
|
||||
|
||||
//to process event
|
||||
public static class ConfigurableSearchTextField extends SearchTextFieldWithStoredHistory {
|
||||
public ConfigurableSearchTextField() {
|
||||
super("ALL_CONFIGURABLES_PANEL_SEARCH_HISTORY");
|
||||
}
|
||||
|
||||
public void process(final KeyEvent e) {
|
||||
((TextFieldWithProcessing)getTextEditor()).processKeyEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Configurable> expand(ConfigurableGroup[] groups) {
|
||||
final ArrayList<Configurable> result = new ArrayList<>();
|
||||
for (ConfigurableGroup eachGroup : groups) {
|
||||
@@ -635,10 +517,9 @@ public class SearchUtil {
|
||||
for (Configurable each : configurables) {
|
||||
addChildren(each, result);
|
||||
}
|
||||
|
||||
result = ContainerUtil.filter(result, configurable -> !(configurable instanceof SearchableConfigurable.Parent) || ((SearchableConfigurable.Parent)configurable).isVisible());
|
||||
|
||||
return result;
|
||||
|
||||
return ContainerUtil.filter(result, configurable -> !(configurable instanceof SearchableConfigurable.Parent) ||
|
||||
((SearchableConfigurable.Parent)configurable).isVisible());
|
||||
}
|
||||
|
||||
private static void addChildren(Configurable configurable, List<Configurable> list) {
|
||||
@@ -650,5 +531,4 @@ public class SearchUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user