[vcs-log] keep recent filters in a map by filter name

This commit is contained in:
Julia Beliaeva
2018-07-04 19:54:16 +03:00
parent bd68b41c9e
commit cb474f4df3
7 changed files with 64 additions and 93 deletions
@@ -20,6 +20,7 @@ import com.intellij.vcs.log.graph.PermanentGraph;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -33,15 +34,10 @@ public interface MainVcsLogUiProperties extends VcsLogUiProperties {
VcsLogUiProperty<Boolean> TEXT_FILTER_REGEX = new VcsLogUiProperty<>("TextFilter.Regex");
VcsLogUiProperty<Boolean> SHOW_CHANGES_FROM_PARENTS = new VcsLogUiProperty<>("Changes.ShowChangesFromParents");
void addRecentlyFilteredUserGroup(@NotNull List<String> usersInGroup);
void addRecentlyFilteredBranchGroup(@NotNull List<String> valuesInGroup);
void addRecentlyFilteredGroup(@NotNull String filterName, @NotNull Collection<String> values);
@NotNull
List<List<String>> getRecentlyFilteredUserGroups();
@NotNull
List<List<String>> getRecentlyFilteredBranchGroups();
List<List<String>> getRecentlyFilteredGroups(@NotNull String filterName);
void saveFilterValues(@NotNull String filterName, @Nullable List<String> values);
@@ -14,6 +14,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import static com.intellij.util.containers.ContainerUtil.*;
import static com.intellij.vcs.log.ui.filter.BranchFilterPopupComponent.BRANCH_FILTER_NAME;
import static com.intellij.vcs.log.ui.filter.UserFilterPopupComponent.USER_FILER_NAME;
import static java.util.Comparator.comparingInt;
@State(name = "Vcs.Log.Tabs.Properties", storages = {@Storage(file = StoragePathMacros.WORKSPACE_FILE)})
@@ -42,10 +44,9 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
}
private void migrateRecentItems() {
if (isEmpty(myState.RECENTLY_FILTERED_BRANCH_GROUPS) && isEmpty(myState.RECENTLY_FILTERED_USER_GROUPS)) {
if (isEmpty(myState.RECENT_FILTERS)) {
myState.RECENTLY_FILTERED_BRANCH_GROUPS = new ArrayDeque<>();
myState.RECENTLY_FILTERED_USER_GROUPS = new ArrayDeque<>();
myState.RECENT_FILTERS = newHashMap();
Multiset<RecentGroup> branchFrequencies = HashMultiset.create();
Multiset<RecentGroup> userFrequencies = HashMultiset.create();
@@ -61,8 +62,8 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
List<RecentGroup> sortedBranches = sorted(branchFrequencies.elementSet(), comparingInt(value -> -branchFrequencies.count(value)));
List<RecentGroup> sortedUsers = sorted(userFrequencies.elementSet(), comparingInt(value -> -userFrequencies.count(value)));
myState.RECENTLY_FILTERED_BRANCH_GROUPS.addAll(getFirstItems(sortedBranches, RECENTLY_FILTERED_VALUES_LIMIT));
myState.RECENTLY_FILTERED_USER_GROUPS.addAll(getFirstItems(sortedUsers, RECENTLY_FILTERED_VALUES_LIMIT));
myState.RECENT_FILTERS.put(BRANCH_FILTER_NAME, newArrayList(getFirstItems(sortedBranches, RECENTLY_FILTERED_VALUES_LIMIT)));
myState.RECENT_FILTERS.put(USER_FILER_NAME, newArrayList(getFirstItems(sortedUsers, RECENTLY_FILTERED_VALUES_LIMIT)));
}
}
@@ -97,28 +98,37 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
return newArrayList(myState.OPEN_TABS);
}
public static void addRecentGroup(@NotNull List<String> valuesInGroup, @NotNull Deque<RecentGroup> stateField) {
RecentGroup group = new RecentGroup();
group.FILTER_VALUES = valuesInGroup;
if (stateField.contains(group)) {
public static void addRecentGroup(@NotNull Map<String, List<RecentGroup>> stateField,
@NotNull String filterName,
@NotNull Collection<String> values) {
List<RecentGroup> recentGroups = stateField.get(filterName);
if (recentGroups == null) {
recentGroups = newArrayList();
stateField.put(filterName, recentGroups);
}
RecentGroup group = new RecentGroup(values);
if (recentGroups.contains(group)) {
return;
}
stateField.addFirst(group);
while (stateField.size() > RECENTLY_FILTERED_VALUES_LIMIT) {
stateField.removeLast();
recentGroups.add(0, group);
while (recentGroups.size() > RECENTLY_FILTERED_VALUES_LIMIT) {
recentGroups.remove(recentGroups.size() - 1);
}
}
@NotNull
public static List<List<String>> getRecentGroup(@NotNull Deque<RecentGroup> stateField) {
return map2List(stateField, group -> group.FILTER_VALUES);
public static List<List<String>> getRecentGroup(@NotNull Map<String, List<RecentGroup>> stateField, @NotNull String filterName) {
List<RecentGroup> values = stateField.get(filterName);
if (values == null) {
return emptyList();
}
return map2List(values, group -> group.FILTER_VALUES);
}
public static class State {
public Map<String, VcsLogUiPropertiesImpl.State> TAB_STATES = newTreeMap();
public LinkedHashSet<String> OPEN_TABS = newLinkedHashSet();
public Deque<RecentGroup> RECENTLY_FILTERED_USER_GROUPS = new ArrayDeque<>();
public Deque<RecentGroup> RECENTLY_FILTERED_BRANCH_GROUPS = new ArrayDeque<>();
public Map<String, List<RecentGroup>> RECENT_FILTERS = newHashMap();
}
public static class RecentGroup {
@@ -128,8 +138,12 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
public RecentGroup() {
}
public RecentGroup(@NotNull Collection<String> values) {
FILTER_VALUES.addAll(values);
}
public RecentGroup(@NotNull VcsLogUiPropertiesImpl.UserGroup oldGroup) {
FILTER_VALUES.addAll(oldGroup.users);
this(oldGroup.users);
}
@Override
@@ -171,25 +185,14 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
}
@Override
public void addRecentlyFilteredUserGroup(@NotNull List<String> usersInGroup) {
addRecentGroup(usersInGroup, myState.RECENTLY_FILTERED_USER_GROUPS);
public void addRecentlyFilteredGroup(@NotNull String filterName, @NotNull Collection<String> values) {
addRecentGroup(myState.RECENT_FILTERS, filterName, values);
}
@Override
public void addRecentlyFilteredBranchGroup(@NotNull List<String> valuesInGroup) {
addRecentGroup(valuesInGroup, myState.RECENTLY_FILTERED_BRANCH_GROUPS);
}
@Override
@NotNull
public List<List<String>> getRecentlyFilteredUserGroups() {
return getRecentGroup(myState.RECENTLY_FILTERED_USER_GROUPS);
}
@Override
@NotNull
public List<List<String>> getRecentlyFilteredBranchGroups() {
return getRecentGroup(myState.RECENTLY_FILTERED_BRANCH_GROUPS);
public List<List<String>> getRecentlyFilteredGroups(@NotNull String filterName) {
return getRecentGroup(myState.RECENT_FILTERS, filterName);
}
}
}
@@ -38,16 +38,16 @@ import org.jetbrains.annotations.Nullable;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogBranchFilter> {
public static final String BRANCH_FILTER_NAME = "Branch";
private final VcsLogClassicFilterUi.BranchFilterModel myBranchFilterModel;
public BranchFilterPopupComponent(@NotNull MainVcsLogUiProperties uiProperties,
@NotNull VcsLogClassicFilterUi.BranchFilterModel filterModel) {
super("Branch", uiProperties, filterModel);
super(BRANCH_FILTER_NAME, uiProperties, filterModel);
myBranchFilterModel = filterModel;
}
@@ -86,17 +86,6 @@ public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponen
return actionGroup;
}
@NotNull
@Override
protected List<List<String>> getRecentValuesFromSettings() {
return myUiProperties.getRecentlyFilteredBranchGroups();
}
@Override
protected void rememberValuesInSettings(@NotNull Collection<String> values) {
myUiProperties.addRecentlyFilteredBranchGroup(new ArrayList<>(values));
}
@NotNull
@Override
protected List<String> getAllValues() {
@@ -48,9 +48,13 @@ abstract class MultipleValueFilterPopupComponent<Filter extends VcsLogFilter> ex
}
@NotNull
protected abstract List<List<String>> getRecentValuesFromSettings();
protected List<List<String>> getRecentValuesFromSettings() {
return myUiProperties.getRecentlyFilteredGroups(myName);
}
protected abstract void rememberValuesInSettings(@NotNull Collection<String> values);
protected void rememberValuesInSettings(@NotNull Collection<String> values) {
myUiProperties.addRecentlyFilteredGroup(myName, values);
}
@NotNull
protected abstract List<String> getAllValues();
@@ -31,21 +31,21 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.TreeSet;
/**
* Show a popup to select a user or enter the user name.
*/
class UserFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogUserFilter> {
public class UserFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogUserFilter> {
public static final String USER_FILER_NAME = "User";
@NotNull private final VcsLogData myLogData;
@NotNull private final List<String> myAllUsers;
UserFilterPopupComponent(@NotNull MainVcsLogUiProperties uiProperties,
@NotNull VcsLogData logData,
@NotNull FilterModel<VcsLogUserFilter> filterModel) {
super("User", uiProperties, filterModel);
super(USER_FILER_NAME, uiProperties, filterModel);
myLogData = logData;
myAllUsers = collectUsers(logData);
}
@@ -85,17 +85,6 @@ class UserFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogU
return group;
}
@NotNull
@Override
protected List<List<String>> getRecentValuesFromSettings() {
return myUiProperties.getRecentlyFilteredUserGroups();
}
@Override
protected void rememberValuesInSettings(@NotNull Collection<String> values) {
myUiProperties.addRecentlyFilteredUserGroup(new ArrayList<>(values));
}
@NotNull
@Override
protected List<String> getAllValues() {
@@ -34,7 +34,7 @@ public abstract class VcsLogPopupComponent extends JPanel {
private static final int GAP_BEFORE_ARROW = 3;
private static final int BORDER_SIZE = 2;
@NotNull private final String myName;
@NotNull protected final String myName;
@NotNull private JLabel myNameLabel;
@NotNull private JLabel myValueLabel;
@@ -8,14 +8,17 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xmlb.annotations.XCollection;
import com.intellij.util.xmlb.annotations.XMap;
import com.intellij.vcs.log.impl.*;
import com.intellij.vcs.log.impl.VcsLogProjectTabsProperties.RecentGroup;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.intellij.vcs.log.ui.filter.BranchFilterPopupComponent.BRANCH_FILTER_NAME;
import static com.intellij.vcs.log.ui.filter.UserFilterPopupComponent.USER_FILER_NAME;
@State(
name = "Git.Log.External.Tabs.Properties",
storages = {
@@ -66,10 +69,10 @@ public class GitExternalLogTabsProperties implements PersistentStateComponent<Gi
newState.LONG_EDGES_VISIBLE = oldState.LONG_EDGES_VISIBLE;
newState.BEK_SORT_TYPE = oldState.BEK_SORT_TYPE;
newState.SHOW_ROOT_NAMES = oldState.SHOW_ROOT_NAMES;
newState.RECENT_BRANCH_FILTERS.addAll(ContainerUtil.map(oldState.RECENTLY_FILTERED_BRANCH_GROUPS,
VcsLogProjectTabsProperties.RecentGroup::new));
newState.RECENT_USER_FILTERS.addAll(ContainerUtil.map(oldState.RECENTLY_FILTERED_USER_GROUPS,
VcsLogProjectTabsProperties.RecentGroup::new));
List<RecentGroup> recentBranches = ContainerUtil.map2List(oldState.RECENTLY_FILTERED_BRANCH_GROUPS, RecentGroup::new);
List<RecentGroup> recentUsers = ContainerUtil.map2List(oldState.RECENTLY_FILTERED_USER_GROUPS, RecentGroup::new);
newState.RECENT_FILTERS.put(BRANCH_FILTER_NAME, recentBranches);
newState.RECENT_FILTERS.put(USER_FILER_NAME, recentUsers);
newState.HIGHLIGHTERS.putAll(oldState.HIGHLIGHTERS);
newState.FILTERS.putAll(oldState.FILTERS);
newState.COLUMN_WIDTH.putAll(oldState.COLUMN_WIDTH);
@@ -90,9 +93,7 @@ public class GitExternalLogTabsProperties implements PersistentStateComponent<Gi
public static class TabState extends VcsLogUiPropertiesImpl.State {
@XCollection
public Deque<VcsLogProjectTabsProperties.RecentGroup> RECENT_USER_FILTERS = new ArrayDeque<>();
@XCollection
public Deque<VcsLogProjectTabsProperties.RecentGroup> RECENT_BRANCH_FILTERS = new ArrayDeque<>();
public Map<String, List<RecentGroup>> RECENT_FILTERS = ContainerUtil.newHashMap();
}
private class MyVcsLogUiProperties extends VcsLogUiPropertiesImpl<TabState> {
@@ -115,25 +116,14 @@ public class GitExternalLogTabsProperties implements PersistentStateComponent<Gi
}
@Override
public void addRecentlyFilteredUserGroup(@NotNull List<String> usersInGroup) {
VcsLogProjectTabsProperties.addRecentGroup(usersInGroup, getState().RECENT_USER_FILTERS);
}
@Override
public void addRecentlyFilteredBranchGroup(@NotNull List<String> valuesInGroup) {
VcsLogProjectTabsProperties.addRecentGroup(valuesInGroup, getState().RECENT_BRANCH_FILTERS);
public void addRecentlyFilteredGroup(@NotNull String filterName, @NotNull Collection<String> values) {
VcsLogProjectTabsProperties.addRecentGroup(getState().RECENT_FILTERS, filterName, values);
}
@NotNull
@Override
public List<List<String>> getRecentlyFilteredUserGroups() {
return VcsLogProjectTabsProperties.getRecentGroup(getState().RECENT_USER_FILTERS);
}
@NotNull
@Override
public List<List<String>> getRecentlyFilteredBranchGroups() {
return VcsLogProjectTabsProperties.getRecentGroup(getState().RECENT_BRANCH_FILTERS);
public List<List<String>> getRecentlyFilteredGroups(@NotNull String filterName) {
return VcsLogProjectTabsProperties.getRecentGroup(getState().RECENT_FILTERS, filterName);
}
}
}