[git] migrate properties for external logs

This commit is contained in:
Julia Beliaeva
2018-07-04 19:54:16 +03:00
parent 5c590b9f02
commit bd68b41c9e
3 changed files with 53 additions and 7 deletions
@@ -50,6 +50,7 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
Multiset<RecentGroup> branchFrequencies = HashMultiset.create();
Multiset<RecentGroup> userFrequencies = HashMultiset.create();
for (Map.Entry<String, VcsLogUiPropertiesImpl.State> entry : myState.TAB_STATES.entrySet()) {
if (entry.getKey().startsWith("EXTERNAL")) continue; // do not migrate recent items for external logs
VcsLogUiPropertiesImpl.State s = entry.getValue();
branchFrequencies.addAll(map(s.RECENTLY_FILTERED_BRANCH_GROUPS, RecentGroup::new));
userFrequencies.addAll(map(s.RECENTLY_FILTERED_USER_GROUPS, RecentGroup::new));
@@ -65,6 +66,17 @@ public class VcsLogProjectTabsProperties implements PersistentStateComponent<Vcs
}
}
/**
* Method for migrating external log tabs properties to the other storage.
* Finds a state by id and removes it.
* To be removed after 2018.3 release.
*/
@Deprecated
@Nullable
public VcsLogUiPropertiesImpl.State removeTabState(@NotNull String id) {
return myState.TAB_STATES.remove(id);
}
@Override
@NotNull
public MainVcsLogUiProperties createProperties(@NotNull final String id) {
@@ -217,7 +217,7 @@ public abstract class VcsLogUiPropertiesImpl<S extends VcsLogUiPropertiesImpl.St
}
}
private static class TextFilterSettings {
public static class TextFilterSettings {
public boolean REGEX = false;
public boolean MATCH_CASE = false;
}
@@ -1,10 +1,9 @@
// 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 git4idea.log;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xmlb.annotations.XCollection;
import com.intellij.util.xmlb.annotations.XMap;
@@ -25,10 +24,12 @@ import java.util.Map;
)
public class GitExternalLogTabsProperties implements PersistentStateComponent<GitExternalLogTabsProperties.State>, VcsLogTabsProperties {
@NotNull private final VcsLogApplicationSettings myAppSettings;
@NotNull private final ProjectManager myProjectManager;
private State myState = new State();
public GitExternalLogTabsProperties(@NotNull VcsLogApplicationSettings settings) {
public GitExternalLogTabsProperties(@NotNull VcsLogApplicationSettings settings, @NotNull ProjectManager projectManager) {
myAppSettings = settings;
myProjectManager = projectManager;
}
@Nullable
@@ -45,10 +46,43 @@ public class GitExternalLogTabsProperties implements PersistentStateComponent<Gi
@NotNull
@Override
public MainVcsLogUiProperties createProperties(@NotNull String id) {
myState.TAB_STATES.putIfAbsent(id, new TabState());
if (!myState.TAB_STATES.containsKey(id)) {
myState.TAB_STATES.put(id, createOrMigrateTabState(id));
}
return new MyVcsLogUiProperties(id);
}
@NotNull
private TabState createOrMigrateTabState(@NotNull String id) {
// migration from VcsLogProjectTabsProperties, to remove after 2018.3 release
Project[] projects = myProjectManager.getOpenProjects();
for (Project project : projects) {
VcsLogProjectTabsProperties projectTabsProperties = ServiceManager.getServiceIfCreated(project, VcsLogProjectTabsProperties.class);
if (projectTabsProperties != null) {
VcsLogUiPropertiesImpl.State oldState = projectTabsProperties.removeTabState(id);
if (oldState != null) {
TabState newState = new TabState();
newState.SHOW_DETAILS_IN_CHANGES = oldState.SHOW_DETAILS_IN_CHANGES;
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));
newState.HIGHLIGHTERS.putAll(oldState.HIGHLIGHTERS);
newState.FILTERS.putAll(oldState.FILTERS);
newState.COLUMN_WIDTH.putAll(oldState.COLUMN_WIDTH);
newState.COLUMN_ORDER.addAll(oldState.COLUMN_ORDER);
newState.TEXT_FILTER_SETTINGS.MATCH_CASE = oldState.TEXT_FILTER_SETTINGS.MATCH_CASE;
newState.TEXT_FILTER_SETTINGS.REGEX = oldState.TEXT_FILTER_SETTINGS.REGEX;
return newState;
}
}
}
return new TabState();
}
public static class State {
@XMap
public Map<String, TabState> TAB_STATES = ContainerUtil.newTreeMap();