From 175bf6aab93171ae135c8df980337839f8cab116 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Thu, 12 Jan 2017 20:14:12 +0300 Subject: [PATCH] [vcs-log] speedsearch for users --- .../vcs/log/ui/frame/IndexSpeedSearch.java | 56 ++++++++++++++++++- .../vcs/log/ui/frame/VcsLogGraphTable.java | 4 +- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IndexSpeedSearch.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IndexSpeedSearch.java index 5d7fefe81be6..9644d63a1978 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IndexSpeedSearch.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IndexSpeedSearch.java @@ -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 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 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 myMatchedUsers; + + public SimpleVcsLogUserFilter(@NotNull List matchedUsers) { + super(ContainerUtil.map(matchedUsers, VcsUserUtil::getShortPresentation), Collections.emptyMap(), + ContainerUtil.newHashSet(matchedUsers)); + myMatchedUsers = matchedUsers; + } + + @NotNull + @Override + public Collection getUsers(@NotNull VirtualFile root) { + return myMatchedUsers; + } + } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java index 7c678df38e3b..8b56ea9f5664 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java @@ -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() {