[vcs-log] speedsearch for users

This commit is contained in:
Julia Beliaeva
2017-01-13 14:16:41 +03:00
parent 9bf2b7de9b
commit 175bf6aab9
2 changed files with 58 additions and 2 deletions
@@ -15,22 +15,50 @@
*/
package com.intellij.vcs.log.ui.frame;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.vcs.log.VcsUser;
import com.intellij.vcs.log.VcsUserRegistry;
import com.intellij.vcs.log.data.VisiblePack;
import com.intellij.vcs.log.data.index.IndexedDetails;
import com.intellij.vcs.log.data.index.VcsLogIndex;
import com.intellij.vcs.log.impl.VcsLogUserFilterImpl;
import com.intellij.vcs.log.impl.VcsLogUtil;
import com.intellij.vcs.log.util.VcsUserUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class IndexSpeedSearch extends VcsLogSpeedSearch {
@NotNull private final VcsLogIndex myIndex;
@NotNull private final VcsUserRegistry myUserRegistry;
public IndexSpeedSearch(@NotNull VcsLogIndex index, @NotNull VcsLogGraphTable component) {
@Nullable private Set<Integer> myMatchedByUserCommits;
public IndexSpeedSearch(@NotNull Project project, @NotNull VcsLogIndex index, @NotNull VcsLogGraphTable component) {
super(component);
myIndex = index;
myUserRegistry = ServiceManager.getService(project, VcsUserRegistry.class);
addChangeListener(evt -> {
if (evt.getPropertyName().equals(ENTERED_PREFIX_PROPERTY_NAME)) {
String pattern = (String)evt.getNewValue();
if (pattern != null) {
List<VcsUser> matchedUsers = ContainerUtil.filter(myUserRegistry.getUsers(),
user -> compare(VcsUserUtil.getShortPresentation(user), pattern));
myMatchedByUserCommits = myIndex.filter(Collections.singletonList(new SimpleVcsLogUserFilter(matchedUsers)));
}
else {
myMatchedByUserCommits = null;
}
}
});
}
@Override
@@ -56,4 +84,30 @@ public class IndexSpeedSearch extends VcsLogSpeedSearch {
if (message == null) return super.getElementText(row);
return IndexedDetails.getSubject(message);
}
@Override
protected boolean isMatchingElement(Object row, String pattern) {
String str = this.getElementText(row);
return (str != null && compare(str, pattern)) ||
(myMatchedByUserCommits != null &&
!myMatchedByUserCommits.isEmpty() &&
// getting id from row takes time, so optimizing a little here
myMatchedByUserCommits.contains(myComponent.getModel().getIdAtRow((Integer)row)));
}
private static class SimpleVcsLogUserFilter extends VcsLogUserFilterImpl {
@NotNull private final List<VcsUser> myMatchedUsers;
public SimpleVcsLogUserFilter(@NotNull List<VcsUser> matchedUsers) {
super(ContainerUtil.map(matchedUsers, VcsUserUtil::getShortPresentation), Collections.emptyMap(),
ContainerUtil.newHashSet(matchedUsers));
myMatchedUsers = matchedUsers;
}
@NotNull
@Override
public Collection<VcsUser> getUsers(@NotNull VirtualFile root) {
return myMatchedUsers;
}
}
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.*;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.speedSearch.SpeedSearchUtil;
import com.intellij.ui.table.JBTable;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.DateFormatUtil;
@@ -132,7 +133,7 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider,
PopupHandler.installPopupHandler(this, VcsLogActionPlaces.POPUP_ACTION_GROUP, VcsLogActionPlaces.VCS_LOG_TABLE_PLACE);
ScrollingUtil.installActions(this, false);
new IndexSpeedSearch(myLogData.getIndex(), this) {
new IndexSpeedSearch(myLogData.getProject(), myLogData.getIndex(), this) {
@Override
protected boolean isSpeedSearchEnabled() {
return VcsLogGraphTable.this.isSpeedSearchEnabled() && super.isSpeedSearchEnabled();
@@ -669,6 +670,7 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider,
return;
}
append(value.toString(), applyHighlighters(this, row, column, hasFocus, selected));
SpeedSearchUtil.applySpeedSearchHighlighting(table, this, false, selected);
}
public int getHorizontalTextPadding() {