[log] Remember users which were recently used in the user filter.

This commit is contained in:
Kirill Likhodedov
2013-10-26 16:55:27 +04:00
parent fd263bcb50
commit 86b09842d4
4 changed files with 47 additions and 3 deletions
@@ -20,8 +20,14 @@ import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.vcs.log.VcsLogSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
/**
* Stores UI configuration based on user activity and preferences.
* Differs from {@link VcsLogSettings} in the fact, that these settings have no representation in the UI settings,
@@ -30,10 +36,13 @@ import org.jetbrains.annotations.Nullable;
@State(name = "Vcs.Log.UiProperties", storages = {@Storage(file = StoragePathMacros.WORKSPACE_FILE)})
public class VcsLogUiProperties implements PersistentStateComponent<VcsLogUiProperties.State> {
private static final int RECENTLY_FILTERED_USERS_AMOUNT = 5;
private State myState = new State();
public static class State {
public boolean SHOW_DETAILS = false;
public Deque<String> RECENTLY_FILTERED_USERS = new ArrayDeque<String>();
}
@Nullable
@@ -59,4 +68,19 @@ public class VcsLogUiProperties implements PersistentStateComponent<VcsLogUiProp
myState.SHOW_DETAILS = showDetails;
}
public void addRecentlyFilteredUser(@NotNull String username) {
if (myState.RECENTLY_FILTERED_USERS.contains(username)) {
return;
}
myState.RECENTLY_FILTERED_USERS.addFirst(username);
if (myState.RECENTLY_FILTERED_USERS.size() > RECENTLY_FILTERED_USERS_AMOUNT) {
myState.RECENTLY_FILTERED_USERS.removeLast();
}
}
@NotNull
public List<String> getRecentlyFilteredUsers() {
return new ArrayList<String>(myState.RECENTLY_FILTERED_USERS);
}
}
@@ -39,6 +39,7 @@ public class VcsLogUI {
@NotNull private final VcsLogDataHolder myLogDataHolder;
@NotNull private final MainFrame myMainFrame;
@NotNull private final VcsLogColorManager myColorManager;
@NotNull private final VcsLogUiProperties myUiProperties;
@NotNull private final VcsLogFilterer myFilterer;
@Nullable private GraphElement prevGraphElement;
@@ -47,6 +48,7 @@ public class VcsLogUI {
@NotNull VcsLogColorManager manager, @NotNull VcsLogUiProperties uiProperties) {
myLogDataHolder = logDataHolder;
myColorManager = manager;
myUiProperties = uiProperties;
myFilterer = new VcsLogFilterer(logDataHolder, this);
myMainFrame = new MainFrame(myLogDataHolder, this, project, uiProperties);
project.getMessageBus().connect(project).subscribe(VcsLogDataHolder.REFRESH_COMPLETED, new Runnable() {
@@ -208,4 +210,9 @@ public class VcsLogUI {
public JBTable getTable() {
return myMainFrame.getGraphTable();
}
@NotNull
public VcsLogUiProperties getUiProperties() {
return myUiProperties;
}
}
@@ -26,11 +26,13 @@ import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.ui.components.JBTextField;
import com.intellij.vcs.log.VcsLogFilter;
import com.intellij.vcs.log.data.VcsLogDataHolder;
import com.intellij.vcs.log.data.VcsLogUiProperties;
import com.intellij.vcs.log.data.VcsLogUserFilter;
import org.jetbrains.annotations.Nullable;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.List;
/**
* Show a popup to select a user or enter the user name.
@@ -39,10 +41,12 @@ class UserFilterPopupComponent extends FilterPopupComponent {
private static final String ME = "me";
private final VcsLogDataHolder myDataHolder;
private final VcsLogUiProperties myUiProperties;
UserFilterPopupComponent(VcsLogClassicFilterUi filterUi, VcsLogDataHolder dataHolder) {
UserFilterPopupComponent(VcsLogClassicFilterUi filterUi, VcsLogDataHolder dataHolder, VcsLogUiProperties uiProperties) {
super(filterUi, "User");
myDataHolder = dataHolder;
myUiProperties = uiProperties;
}
@Override
@@ -50,7 +54,15 @@ class UserFilterPopupComponent extends FilterPopupComponent {
DefaultActionGroup group = new DefaultActionGroup();
group.add(createAllAction());
group.add(new SetValueAction(ME, this));
// TODO show recently selected users
List<String> recentlyFilteredUsers = myUiProperties.getRecentlyFilteredUsers();
if (!recentlyFilteredUsers.isEmpty()) {
group.addSeparator("Recently searched");
for (String recentUser : recentlyFilteredUsers) {
group.add(new SetValueAction(recentUser, this));
}
}
group.addSeparator();
group.add(new SelectUserAction());
return group;
}
@@ -65,6 +77,7 @@ class UserFilterPopupComponent extends FilterPopupComponent {
if (value == ME) {
return new VcsLogUserFilter.Me(myDataHolder.getCurrentUser());
}
myUiProperties.addRecentlyFilteredUser(value);
return new VcsLogUserFilter.ByName(value);
}
@@ -56,7 +56,7 @@ public class VcsLogClassicFilterUi implements VcsLogFilterUi {
}
});
FilterPopupComponent branchFilter = new BranchFilterPopupComponent(this, ui);
FilterPopupComponent userFilter = new UserFilterPopupComponent(this, ui.getLogDataHolder());
FilterPopupComponent userFilter = new UserFilterPopupComponent(this, ui.getLogDataHolder(), ui.getUiProperties());
myFilterPopupComponents = ContainerUtil.newArrayList();
myFilterPopupComponents.add(branchFilter);