mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Decouple DefaultChooseByNameItemProvider from ChooseByNameBase
Allow using name filtering logic without a complete ChooseByNameBase instance
This commit is contained in:
@@ -87,7 +87,7 @@ import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.keymap.KeymapUtil.getActiveKeymapShortcuts;
|
||||
|
||||
public abstract class ChooseByNameBase {
|
||||
public abstract class ChooseByNameBase implements ChooseByNameView {
|
||||
public static final String TEMPORARILY_FOCUSABLE_COMPONENT_KEY = "ChooseByNameBase.TemporarilyFocusableComponent";
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.gotoByName.ChooseByNameBase");
|
||||
@@ -200,6 +200,12 @@ public abstract class ChooseByNameBase {
|
||||
myInitIsDone = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSearchInAnyPlace() {
|
||||
return mySearchInAnyPlace;
|
||||
}
|
||||
@@ -239,6 +245,7 @@ public abstract class ChooseByNameBase {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ChooseByNameModel getModel() {
|
||||
return myModel;
|
||||
}
|
||||
@@ -717,6 +724,7 @@ public abstract class ChooseByNameBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transformPattern(String pattern) {
|
||||
return pattern;
|
||||
}
|
||||
@@ -774,6 +782,7 @@ public abstract class ChooseByNameBase {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getNames(boolean checkboxState) {
|
||||
if (ourLoadNamesEachTime) {
|
||||
@@ -1468,6 +1477,7 @@ public abstract class ChooseByNameBase {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canShowListForEmptyPattern() {
|
||||
return isShowListForEmptyPattern() || isShowListAfterCompletionKeyStroke() && lastKeyStrokeIsCompletion();
|
||||
}
|
||||
@@ -1487,6 +1497,7 @@ public abstract class ChooseByNameBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumListSizeLimit() {
|
||||
return myMaximumListSizeLimit;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.util.gotoByName;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public interface ChooseByNameView {
|
||||
Project getProject();
|
||||
|
||||
ChooseByNameModel getModel();
|
||||
|
||||
boolean isSearchInAnyPlace();
|
||||
|
||||
String transformPattern(String pattern);
|
||||
|
||||
boolean canShowListForEmptyPattern();
|
||||
|
||||
int getMaximumListSizeLimit();
|
||||
|
||||
String[] getNames(boolean everywhere);
|
||||
}
|
||||
+23
-27
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.util.gotoByName;
|
||||
|
||||
import com.intellij.concurrency.JobLauncher;
|
||||
@@ -56,7 +42,16 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
boolean everywhere,
|
||||
@NotNull final ProgressIndicator indicator,
|
||||
@NotNull final Processor<Object> consumer) {
|
||||
if (base.myProject != null) base.myProject.putUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN, pattern);
|
||||
return filterElements(base, pattern, everywhere, indicator, getPathProximityComparator(), consumer);
|
||||
}
|
||||
|
||||
public static boolean filterElements(@NotNull ChooseByNameView base,
|
||||
@NotNull String pattern,
|
||||
boolean everywhere,
|
||||
@NotNull ProgressIndicator indicator,
|
||||
@Nullable PathProximityComparator pathProximityComparator,
|
||||
@NotNull Processor<Object> consumer) {
|
||||
if (base.getProject() != null) base.getProject().putUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN, pattern);
|
||||
|
||||
String namePattern = getNamePattern(base, pattern);
|
||||
String qualifierPattern = getQualifierPattern(base, pattern);
|
||||
@@ -113,7 +108,8 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
|
||||
Comparator<Object> weightComparator = new Comparator<Object>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Comparator<Object> modelComparator = model instanceof Comparator ? (Comparator<Object>)model : getPathProximityComparator();
|
||||
Comparator<Object> modelComparator = model instanceof Comparator ? (Comparator<Object>)model :
|
||||
(pathProximityComparator != null ? pathProximityComparator : new PathProximityComparator(null));
|
||||
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
@@ -132,7 +128,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
idFilter = ((ContributorsBasedGotoByModel)model).getIdFilter(everywhere);
|
||||
}
|
||||
|
||||
GlobalSearchScope searchScope = FindSymbolParameters.searchScopeFor(base.myProject, everywhere);
|
||||
GlobalSearchScope searchScope = FindSymbolParameters.searchScopeFor(base.getProject(), everywhere);
|
||||
FindSymbolParameters parameters = new FindSymbolParameters(pattern, namePattern, searchScope, idFilter);
|
||||
|
||||
for (MatchResult result : namesList) {
|
||||
@@ -186,7 +182,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getQualifierPattern(@NotNull ChooseByNameBase base, @NotNull String pattern) {
|
||||
private static String getQualifierPattern(@NotNull ChooseByNameView base, @NotNull String pattern) {
|
||||
pattern = base.transformPattern(pattern);
|
||||
final String[] separators = base.getModel().getSeparators();
|
||||
int lastSeparatorOccurrence = 0;
|
||||
@@ -201,7 +197,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getNamePattern(@NotNull ChooseByNameBase base, String pattern) {
|
||||
private static String getNamePattern(@NotNull ChooseByNameView base, String pattern) {
|
||||
String transformedPattern = base.transformPattern(pattern);
|
||||
return getNamePattern(base.getModel(), transformedPattern);
|
||||
}
|
||||
@@ -221,7 +217,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> split(@NotNull String s, @NotNull ChooseByNameBase base) {
|
||||
private static List<String> split(@NotNull String s, @NotNull ChooseByNameView base) {
|
||||
List<String> answer = new ArrayList<>();
|
||||
for (String token : StringUtil.tokenize(s, StringUtil.join(base.getModel().getSeparators(), ""))) {
|
||||
if (!token.isEmpty()) {
|
||||
@@ -233,7 +229,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
private static MatchResult matchQualifier(@NotNull Object element,
|
||||
@NotNull final ChooseByNameBase base,
|
||||
@NotNull final ChooseByNameView base,
|
||||
@NotNull List<Pair<String, MinusculeMatcher>> patternsAndMatchers) {
|
||||
final String name = base.getModel().getFullName(element);
|
||||
if (name == null) return null;
|
||||
@@ -276,7 +272,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Pair<String, MinusculeMatcher>> getPatternsAndMatchers(@NotNull String qualifierPattern, @NotNull final ChooseByNameBase base) {
|
||||
private static List<Pair<String, MinusculeMatcher>> getPatternsAndMatchers(@NotNull String qualifierPattern, @NotNull final ChooseByNameView base) {
|
||||
return ContainerUtil.map2List(split(qualifierPattern, base), s -> {
|
||||
String namePattern = addSearchAnywherePatternDecorationIfNeeded(base, getNamePattern(base, s));
|
||||
return Pair.create(namePattern, buildPatternMatcher(namePattern, NameUtil.MatchingCaseSensitivity.NONE));
|
||||
@@ -300,7 +296,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
}
|
||||
|
||||
private static void processNamesByPattern(@NotNull final ChooseByNameBase base,
|
||||
private static void processNamesByPattern(@NotNull final ChooseByNameView base,
|
||||
@NotNull final String[] names,
|
||||
@NotNull final String pattern,
|
||||
final ProgressIndicator indicator,
|
||||
@@ -320,7 +316,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String convertToMatchingPattern(@NotNull ChooseByNameBase base, @NotNull String pattern) {
|
||||
private static String convertToMatchingPattern(@NotNull ChooseByNameView base, @NotNull String pattern) {
|
||||
pattern = removeModelSpecificMarkup(base.getModel(), pattern);
|
||||
|
||||
if (!base.canShowListForEmptyPattern() && pattern.isEmpty()) {
|
||||
@@ -331,7 +327,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String addSearchAnywherePatternDecorationIfNeeded(@NotNull ChooseByNameBase base, @NotNull String pattern) {
|
||||
private static String addSearchAnywherePatternDecorationIfNeeded(@NotNull ChooseByNameView base, @NotNull String pattern) {
|
||||
String trimmedPattern;
|
||||
if (base.isSearchInAnyPlace() && !(trimmedPattern = pattern.trim()).isEmpty() && trimmedPattern.length() > 1) {
|
||||
pattern = "*" + pattern;
|
||||
@@ -348,7 +344,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static MatchResult matches(@NotNull ChooseByNameBase base,
|
||||
protected static MatchResult matches(@NotNull ChooseByNameView base,
|
||||
@NotNull String pattern,
|
||||
@NotNull MinusculeMatcher matcher,
|
||||
@Nullable String name) {
|
||||
|
||||
Reference in New Issue
Block a user