mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
UX-1 new SearchEverywhere popup
* recent files
This commit is contained in:
+4
@@ -20,6 +20,10 @@ public class ContributorSearchResult<T> {
|
||||
this.hasMoreItems = hasMoreItems;
|
||||
}
|
||||
|
||||
public ContributorSearchResult(List<T> items) {
|
||||
this(items, false);
|
||||
}
|
||||
|
||||
public List<T> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// 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.actions.searcheverywhere;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.codeStyle.MinusculeMatcher;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RecentFilesSEContributor extends FileSearchEverywhereContributor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getSearchProviderId() {
|
||||
return RecentFilesSEContributor.class.getSimpleName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupName() {
|
||||
return "Recent Files";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String includeNonProjectItemsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortWeight() {
|
||||
return 70;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContributorSearchResult<Object> search(Project project, String pattern, boolean everywhere, ProgressIndicator progressIndicator, int elementsLimit) {
|
||||
MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern).build();
|
||||
List<VirtualFile> opened = Arrays.asList(FileEditorManager.getInstance(project).getSelectedFiles());
|
||||
List<VirtualFile> history = Lists.reverse(EditorHistoryManager.getInstance(project).getFileList());
|
||||
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
Stream<VirtualFile> stream = history.stream();
|
||||
if (!StringUtil.isEmptyOrSpaces(pattern)) {
|
||||
stream = stream.filter(file -> matcher.matches(file.getName()));
|
||||
}
|
||||
List<Object> res = stream.filter(vf -> !opened.contains(vf) && vf.isValid())
|
||||
.distinct()
|
||||
.map(vf -> psiManager.findFile(vf))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return res.size() > elementsLimit
|
||||
? new ContributorSearchResult<>(res.subList(0, elementsLimit), true)
|
||||
: new ContributorSearchResult<>(res);
|
||||
}
|
||||
}
|
||||
+2
@@ -49,6 +49,8 @@ public class SearchEverywhereManagerImpl implements SearchEverywhereManager {
|
||||
// fill service contributors
|
||||
TopHitSEContributor topHitContributor = new TopHitSEContributor(s -> mySearchEverywhereUI.getSearchField().setText(s));
|
||||
myServiceContributors.add(topHitContributor);
|
||||
RecentFilesSEContributor recentContributor = new RecentFilesSEContributor();
|
||||
myServiceContributors.add(recentContributor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -619,7 +619,7 @@ public class SearchEverywhereUI extends BorderLayoutPanel implements Disposable,
|
||||
} else {
|
||||
boolean clearBefore = true;
|
||||
for (SearchEverywhereContributor contributor : allContributors) {
|
||||
anyFound = anyFound || addContributorItems(contributor, MULTIPLE_CONTRIBUTORS_ELEMENTS_LIMIT, clearBefore);
|
||||
anyFound |= addContributorItems(contributor, MULTIPLE_CONTRIBUTORS_ELEMENTS_LIMIT, clearBefore);
|
||||
clearBefore = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user