Revert "fix cyclic initialization of FileColorManager"

This reverts commit 005cc812

GitOrigin-RevId: f7e03430d1fe6d2d6b52fc4b0e95b4431d4f9b28
This commit is contained in:
Vladimir Krivosheev
2019-09-05 13:32:24 +00:00
committed by intellij-monorepo-bot
parent cf336dc1b6
commit 03cc8f65aa
4 changed files with 62 additions and 35 deletions
@@ -1,4 +1,5 @@
// Copyright 2000-2019 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 com.intellij.ui;
import com.intellij.openapi.components.ServiceManager;
@@ -34,6 +35,9 @@ public abstract class FileColorManager {
public abstract Collection<String> getColorNames();
@Nullable
public abstract Color getFileColor(@NotNull final PsiFile file);
@Nullable
public abstract Color getFileColor(@NotNull final VirtualFile file);
@@ -42,6 +46,8 @@ public abstract class FileColorManager {
public abstract boolean isShared(@NotNull final String scopeName);
public abstract boolean isColored(@NotNull String scopeName, final boolean shared);
@Nullable
public abstract Color getRendererBackground(VirtualFile file);
@@ -1,11 +1,9 @@
// Copyright 2000-2019 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 com.intellij.ui.tabs;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
@@ -26,8 +24,10 @@ import java.util.*;
* @author spleaner
* @author Konstantin Bulenkov
*/
@State(name = "FileColors", storages = @Storage(StoragePathMacros.WORKSPACE_FILE))
public final class FileColorManagerImpl extends FileColorManager implements PersistentStateComponent<Element> {
@State(
name = "FileColors",
storages = {@Storage(StoragePathMacros.WORKSPACE_FILE)})
public class FileColorManagerImpl extends FileColorManager implements PersistentStateComponent<Element> {
public static final String FC_ENABLED = "FileColorsEnabled";
public static final String FC_TABS_ENABLED = "FileColorsForTabsEnabled";
public static final String FC_PROJECT_VIEW_ENABLED = "FileColorsForProjectViewEnabled";
@@ -44,14 +44,14 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
.put("Yellow", JBColor.namedColor("FileColor.Yellow", new JBColor(0xffffe4, 0x4f4b41)))
.build();
public FileColorManagerImpl(@NotNull Project project) {
public FileColorManagerImpl(@NotNull final Project project) {
myProject = project;
myModel = new FileColorsModel(project);
}
private void initProjectLevelConfigurations() {
if (myProjectLevelConfigurationManager == null) {
myProjectLevelConfigurationManager = myProject.getService(FileColorProjectLevelConfigurationManager.class);
myProjectLevelConfigurationManager = ServiceManager.getService(myProject, FileColorProjectLevelConfigurationManager.class);
}
}
@@ -95,16 +95,30 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
PropertiesComponent.getInstance().setValue(FC_PROJECT_VIEW_ENABLED, Boolean.toString(enabled));
}
public Element getState(final boolean shared) {
Element element = new Element("state");
myModel.save(element, shared);
return element;
}
@Override
@Nullable
public Color getColor(@NotNull String name) {
public Color getColor(@NotNull final String name) {
Color color = ourDefaultColors.get(name);
return color == null ? ColorUtil.fromHex(name, null) : color;
if (color != null) {
return color;
}
return ColorUtil.fromHex(name, null);
}
@Override
public Element getState() {
return myModel.save(false);
initProjectLevelConfigurations();
return getState(false);
}
void loadState(Element state, final boolean shared) {
myModel.load(state, shared);
}
@Override
@@ -116,7 +130,13 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
@Override
public void loadState(@NotNull Element state) {
myModel.load(state, false);
initProjectLevelConfigurations();
loadState(state, false);
}
@Override
public boolean isColored(@NotNull final String scopeName, final boolean shared) {
return myModel.isColored(scopeName, shared);
}
@Nullable
@@ -138,7 +158,7 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
public Color getRendererBackground(PsiFile file) {
if (file == null) return null;
VirtualFile vFile = file.getVirtualFile();
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) return null;
return getRendererBackground(vFile);
@@ -146,17 +166,24 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
@Override
public void addScopeColor(@NotNull String scopeName, @NotNull String colorName, boolean isProjectLevel) {
initProjectLevelConfigurations();
myModel.add(scopeName, colorName, isProjectLevel);
}
@Override
@Nullable
public Color getFileColor(@NotNull VirtualFile file) {
public Color getFileColor(@NotNull final PsiFile file) {
initProjectLevelConfigurations();
String colorName = myModel.getColor(file, getProject());
final String colorName = myModel.getColor(file);
return colorName == null ? null : getColor(colorName);
}
@Override
@Nullable
public Color getFileColor(@NotNull final VirtualFile file) {
initProjectLevelConfigurations();
final String colorName = myModel.getColor(file, getProject());
return colorName == null ? null : getColor(colorName);
}
@@ -165,21 +192,17 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
public Color getScopeColor(@NotNull String scopeName) {
initProjectLevelConfigurations();
String colorName = myModel.getScopeColor(scopeName, getProject());
final String colorName = myModel.getScopeColor(scopeName, getProject());
return colorName == null ? null : getColor(colorName);
}
@Override
public boolean isShared(@NotNull String scopeName) {
initProjectLevelConfigurations();
public boolean isShared(@NotNull final String scopeName) {
return myModel.isProjectLevel(scopeName);
}
@NotNull
FileColorsModel getModel() {
initProjectLevelConfigurations();
return myModel;
}
@@ -194,8 +217,6 @@ public final class FileColorManagerImpl extends FileColorManager implements Pers
}
public List<FileColorConfiguration> getProjectLevelConfigurations() {
initProjectLevelConfigurations();
return myModel.getProjectLevelConfigurations();
}
@@ -1,4 +1,5 @@
// Copyright 2000-2019 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 com.intellij.ui.tabs;
import com.intellij.openapi.components.PersistentStateComponent;
@@ -10,20 +11,20 @@ import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
@State(name="SharedFileColors", storages = @Storage("fileColors.xml"))
final class FileColorProjectLevelConfigurationManager implements PersistentStateComponent<Element> {
public class FileColorProjectLevelConfigurationManager implements PersistentStateComponent<Element> {
private final Project myProject;
FileColorProjectLevelConfigurationManager(@NotNull Project project) {
public FileColorProjectLevelConfigurationManager(@NotNull final Project project) {
myProject = project;
}
@Override
public Element getState() {
return ((FileColorManagerImpl)FileColorManager.getInstance(myProject)).getModel().save(true);
return ((FileColorManagerImpl)FileColorManager.getInstance(myProject)).getState(true);
}
@Override
public void loadState(@NotNull Element state) {
((FileColorManagerImpl)FileColorManager.getInstance(myProject)).getModel().load(state, true);
((FileColorManagerImpl)FileColorManager.getInstance(myProject)).loadState(state, true);
}
}
@@ -1,4 +1,5 @@
// Copyright 2000-2019 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 com.intellij.ui.tabs;
import com.intellij.ide.util.PropertiesComponent;
@@ -29,7 +30,8 @@ import java.util.Map;
* @author spleaner
* @author Konstantin Bulenkov
*/
public final class FileColorsModel implements Cloneable {
// todo[spL]: listen to scope rename
public class FileColorsModel implements Cloneable {
public static final String FILE_COLOR = "fileColor";
private final List<FileColorConfiguration> myApplicationLevelConfigurations = new ArrayList<>();
@@ -40,7 +42,7 @@ public final class FileColorsModel implements Cloneable {
@NotNull
private final Project myProject;
FileColorsModel(@NotNull Project project) {
FileColorsModel(@NotNull final Project project) {
myProject = project;
initPredefinedAndGlobalScopes();
}
@@ -103,9 +105,7 @@ public final class FileColorsModel implements Cloneable {
return colorName;
}
@NotNull
Element save(boolean isProjectLevel) {
Element e = new Element("state");
public void save(@NotNull Element e, boolean isProjectLevel) {
List<FileColorConfiguration> configurations = isProjectLevel ? myProjectLevelConfigurations : myApplicationLevelConfigurations;
for (FileColorConfiguration configuration : configurations) {
String scopeName = configuration.getScopeName();
@@ -120,7 +120,6 @@ public final class FileColorsModel implements Cloneable {
PropertiesComponent.getInstance().setValue(scopeName, null);
}
}
return e;
}
public void load(@NotNull Element e, boolean isProjectLevel) {