mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Make File Colors settings app level
remove Tests from shared scopes. It's local now.
This commit is contained in:
@@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
@Colored(color = "ff0000")
|
||||
@Colored(color = "e7fadb")
|
||||
public class TestsScope extends NamedScope {
|
||||
public static final String NAME = IdeBundle.message("predefined.scope.tests.name");
|
||||
public TestsScope(@NotNull Project project) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.problems.WolfTheProblemSolver;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.scope.packageSet.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -80,4 +81,14 @@ public class DefaultScopesProvider implements CustomScopesProvider {
|
||||
}
|
||||
return scopes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public NamedScope findCustomScope(String name) {
|
||||
for (NamedScope scope : getAllCustomScopes()) {
|
||||
if (name.equals(scope.getName())) {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.intellij.ui.tabs;
|
||||
import com.intellij.notification.impl.ui.StickyButton;
|
||||
import com.intellij.notification.impl.ui.StickyButtonUI;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.packageDependencies.NonProjectFilesScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
@@ -35,9 +34,7 @@ import javax.swing.plaf.ButtonUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -79,14 +76,7 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
final String[] names = ArrayUtil.toStringArray(myScopeNames.keySet());
|
||||
Arrays.sort(names, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1 == NonProjectFilesScope.NAME ? 1 : o2 == NonProjectFilesScope.NAME ? -1 : 0;
|
||||
}
|
||||
});
|
||||
myScopeComboBox = new JComboBox(names);
|
||||
myScopeComboBox = new JComboBox(ArrayUtil.toStringArray(myScopeNames.keySet()));
|
||||
myScopeComboBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateCustomButton();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.ui.tabs;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
@@ -23,7 +24,6 @@ import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packageDependencies.NonProjectFilesScope;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
@@ -46,12 +46,11 @@ import java.util.List;
|
||||
name = "FileColors",
|
||||
storages = {@Storage(id = "other", file = "$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";
|
||||
private final Project myProject;
|
||||
private final FileColorsModel myModel;
|
||||
private FileColorSharedConfigurationManager mySharedConfigurationManager;
|
||||
private boolean myEnabled = true;
|
||||
private boolean myEnabledForTabs = true;
|
||||
private boolean myEnabledForNonProject = true;
|
||||
|
||||
private static final Map<String, Color> ourDefaultColors;
|
||||
|
||||
@@ -77,39 +76,39 @@ public class FileColorManagerImpl extends FileColorManager implements Persistent
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return myEnabled;
|
||||
return PropertiesComponent.getInstance().getBoolean(FC_ENABLED, true);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
myEnabled = enabled;
|
||||
PropertiesComponent.getInstance().setValue(FC_ENABLED, Boolean.toString(enabled));
|
||||
}
|
||||
|
||||
public void setEnabledForTabs(boolean b) {
|
||||
myEnabledForTabs = b;
|
||||
public void setEnabledForTabs(boolean enabled) {
|
||||
PropertiesComponent.getInstance().setValue(FC_TABS_ENABLED, Boolean.toString(enabled));
|
||||
}
|
||||
|
||||
public boolean isEnabledForTabs() {
|
||||
return myEnabledForTabs;
|
||||
return PropertiesComponent.getInstance().getBoolean(FC_TABS_ENABLED, true);
|
||||
}
|
||||
|
||||
public Element getState(final boolean shared) {
|
||||
Element element = new Element("state");
|
||||
if (!shared) {
|
||||
element.setAttribute("enabled", Boolean.toString(myEnabled));
|
||||
element.setAttribute("enabledForTabs", Boolean.toString(myEnabledForTabs));
|
||||
}
|
||||
//if (!shared) {
|
||||
// element.setAttribute("enabled", Boolean.toString(myEnabled));
|
||||
// element.setAttribute("enabledForTabs", Boolean.toString(myEnabledForTabs));
|
||||
//}
|
||||
|
||||
myModel.save(element, shared);
|
||||
if (!shared) {
|
||||
final boolean exists = findConfigurationByName(NonProjectFilesScope.NAME, myModel.getLocalConfigurations()) != null;
|
||||
if (myEnabledForNonProject && !exists) {
|
||||
myEnabledForNonProject = false;
|
||||
} else if (!myEnabledForNonProject && exists) {
|
||||
myEnabledForNonProject = true;
|
||||
}
|
||||
|
||||
element.setAttribute("showNonProject", Boolean.toString(myEnabledForNonProject));
|
||||
}
|
||||
//if (!shared) {
|
||||
// final boolean exists = findConfigurationByName(NonProjectFilesScope.NAME, myModel.getLocalConfigurations()) != null;
|
||||
// if (myEnabledForNonProject && !exists) {
|
||||
// myEnabledForNonProject = false;
|
||||
// } else if (!myEnabledForNonProject && exists) {
|
||||
// myEnabledForNonProject = true;
|
||||
// }
|
||||
//
|
||||
// element.setAttribute("showNonProject", Boolean.toString(myEnabledForNonProject));
|
||||
//}
|
||||
|
||||
return element;
|
||||
}
|
||||
@@ -129,21 +128,21 @@ public class FileColorManagerImpl extends FileColorManager implements Persistent
|
||||
@SuppressWarnings({"AutoUnboxing"})
|
||||
void loadState(Element state, final boolean shared) {
|
||||
if (!shared) {
|
||||
final String enabled = state.getAttributeValue("enabled");
|
||||
myEnabled = enabled == null ? true : Boolean.valueOf(enabled);
|
||||
//final String enabled = state.getAttributeValue("enabled");
|
||||
//myEnabled = enabled == null ? true : Boolean.valueOf(enabled);
|
||||
//
|
||||
//final String enabledForTabs = state.getAttributeValue("enabledForTabs");
|
||||
//myEnabledForTabs = enabledForTabs == null ? true : Boolean.valueOf(enabledForTabs);
|
||||
|
||||
final String enabledForTabs = state.getAttributeValue("enabledForTabs");
|
||||
myEnabledForTabs = enabledForTabs == null ? true : Boolean.valueOf(enabledForTabs);
|
||||
|
||||
final String showNonProject = state.getAttributeValue("showNonProject");
|
||||
myEnabledForNonProject = showNonProject == null ? true : Boolean.valueOf(showNonProject);
|
||||
//final String showNonProject = state.getAttributeValue("showNonProject");
|
||||
//myEnabledForNonProject = showNonProject == null ? true : Boolean.valueOf(showNonProject);
|
||||
}
|
||||
|
||||
myModel.load(state, shared);
|
||||
final List<FileColorConfiguration> local = myModel.getLocalConfigurations();
|
||||
if (!shared && myEnabledForNonProject && findConfigurationByName(NonProjectFilesScope.NAME, local) == null) {
|
||||
local.add(new FileColorConfiguration(NonProjectFilesScope.NAME, NonProjectFilesScope.DEFAULT_COLOR));
|
||||
}
|
||||
//final List<FileColorConfiguration> local = myModel.getLocalConfigurations();
|
||||
//if (!shared && myEnabledForNonProject && findConfigurationByName(NonProjectFilesScope.NAME, local) == null) {
|
||||
// local.add(new FileColorConfiguration(NonProjectFilesScope.NAME, NonProjectFilesScope.DEFAULT_COLOR));
|
||||
//}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MethodMayBeStatic"})
|
||||
|
||||
@@ -16,17 +16,25 @@
|
||||
|
||||
package com.intellij.ui.tabs;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.packageDependencies.DefaultScopesProvider;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.scope.NonProjectFilesScope;
|
||||
import com.intellij.psi.search.scope.TestsScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
@@ -38,6 +46,15 @@ public class FileColorsModel implements Cloneable {
|
||||
|
||||
private final List<FileColorConfiguration> myConfigurations;
|
||||
private final List<FileColorConfiguration> mySharedConfigurations;
|
||||
private static final Map<String, String> globalScopes;
|
||||
private static Map<String, String> globalScopesColors;
|
||||
static {
|
||||
globalScopes = new HashMap<String, String>();
|
||||
globalScopes.put(NonProjectFilesScope.NAME, "file.colors.enable.non.project");
|
||||
globalScopes.put(TestsScope.NAME, "file.colors.enable.tests");
|
||||
|
||||
globalScopesColors = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
@@ -45,20 +62,51 @@ public class FileColorsModel implements Cloneable {
|
||||
myProject = project;
|
||||
myConfigurations = new ArrayList<FileColorConfiguration>();
|
||||
mySharedConfigurations = new ArrayList<FileColorConfiguration>();
|
||||
|
||||
if (globalScopesColors.size() < globalScopes.size()) {
|
||||
final DefaultScopesProvider defaultScopesProvider = DefaultScopesProvider.getInstance(project);
|
||||
for (String scopeName : globalScopes.keySet()) {
|
||||
final NamedScope scope = defaultScopesProvider.findCustomScope(scopeName);
|
||||
assert scope != null : "There is no custom scope with name " + scopeName;
|
||||
final Color color = ColorUtil.getColor(scope.getClass());
|
||||
assert color != null : scope.getClass().getName() + " is not annotated with @Colored";
|
||||
globalScopesColors.put(scopeName, ColorUtil.toHex(color));
|
||||
}
|
||||
}
|
||||
initGlobalScopes();
|
||||
}
|
||||
|
||||
private FileColorsModel(@NotNull final Project project,
|
||||
@NotNull final List<FileColorConfiguration> regular,
|
||||
@NotNull final List<FileColorConfiguration> shared) {
|
||||
myProject = project;
|
||||
myConfigurations = regular;
|
||||
mySharedConfigurations = shared;
|
||||
myConfigurations = new ArrayList<FileColorConfiguration>();
|
||||
mySharedConfigurations = new ArrayList<FileColorConfiguration>();
|
||||
myConfigurations.addAll(regular);
|
||||
mySharedConfigurations.addAll(shared);
|
||||
initGlobalScopes();
|
||||
}
|
||||
|
||||
private void initGlobalScopes() {
|
||||
for (String scopeName : globalScopes.keySet()) {
|
||||
if (findConfiguration(scopeName, false) == null) {
|
||||
final String color = PropertiesComponent.getInstance().getOrInit(globalScopes.get(scopeName), globalScopesColors.get(scopeName));
|
||||
if (color.length() != 0) {
|
||||
myConfigurations.add(new FileColorConfiguration(scopeName, color));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(final Element e, final boolean shared) {
|
||||
final List<FileColorConfiguration> configurations = shared ? mySharedConfigurations : myConfigurations;
|
||||
for (final FileColorConfiguration configuration : configurations) {
|
||||
configuration.save(e);
|
||||
final String name = configuration.getScopeName();
|
||||
if (!shared && globalScopes.containsKey(name)) {
|
||||
PropertiesComponent.getInstance().setValue(name, configuration.getColorName());
|
||||
} else {
|
||||
configuration.save(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,12 +116,29 @@ public class FileColorsModel implements Cloneable {
|
||||
configurations.clear();
|
||||
|
||||
final List<Element> list = (List<Element>)e.getChildren(FILE_COLOR);
|
||||
final Map<String, String> global = new HashMap<String, String>(globalScopes);
|
||||
for (Element child : list) {
|
||||
final FileColorConfiguration configuration = FileColorConfiguration.load(child);
|
||||
if (configuration != null) {
|
||||
if (!shared) {
|
||||
final String name = configuration.getScopeName();
|
||||
if (globalScopes.get(name) != null) {
|
||||
global.remove(name);
|
||||
}
|
||||
}
|
||||
configurations.add(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
if (!shared) {
|
||||
final PropertiesComponent properties = PropertiesComponent.getInstance();
|
||||
for (String scope : global.keySet()) {
|
||||
final String colorName = properties.getValue(scope);
|
||||
if (colorName != null) {
|
||||
configurations.add(new FileColorConfiguration(scope, colorName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FileColorsModel clone() throws CloneNotSupportedException {
|
||||
@@ -105,15 +170,6 @@ public class FileColorsModel implements Cloneable {
|
||||
add(configuration, shared);
|
||||
}
|
||||
|
||||
public void remove(@NotNull final String scopeName, boolean shared) {
|
||||
final List<FileColorConfiguration> configurations = shared ? mySharedConfigurations : myConfigurations;
|
||||
final FileColorConfiguration configuration = findConfiguration(scopeName, shared);
|
||||
|
||||
if (configuration != null) {
|
||||
configurations.remove(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FileColorConfiguration findConfiguration(final String scopeName, final boolean shared) {
|
||||
final List<FileColorConfiguration> configurations = shared ? mySharedConfigurations : myConfigurations;
|
||||
@@ -172,11 +228,6 @@ public class FileColorsModel implements Cloneable {
|
||||
return mySharedConfigurations.contains(configuration);
|
||||
}
|
||||
|
||||
public void remove(FileColorConfiguration configuration, boolean shared) {
|
||||
final List<FileColorConfiguration> configurations = shared ? mySharedConfigurations : myConfigurations;
|
||||
configurations.remove(configuration);
|
||||
}
|
||||
|
||||
public void setConfigurations(final List<FileColorConfiguration> configurations, final boolean shared) {
|
||||
if (shared) {
|
||||
mySharedConfigurations.clear();
|
||||
@@ -184,7 +235,18 @@ public class FileColorsModel implements Cloneable {
|
||||
}
|
||||
else {
|
||||
myConfigurations.clear();
|
||||
myConfigurations.addAll(configurations);
|
||||
final HashMap<String, String> global = new HashMap<String, String>(globalScopes);
|
||||
for (FileColorConfiguration configuration : configurations) {
|
||||
myConfigurations.add(configuration);
|
||||
final String name = configuration.getScopeName();
|
||||
if (global.containsKey(name)) {
|
||||
PropertiesComponent.getInstance().setValue(global.get(name), configuration.getColorName());
|
||||
global.remove(name);
|
||||
}
|
||||
}
|
||||
for (String name : global.keySet()) {
|
||||
PropertiesComponent.getInstance().setValue(global.get(name), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ public abstract class PropertiesComponent {
|
||||
return Boolean.valueOf(getValue(name)).booleanValue();
|
||||
}
|
||||
|
||||
public final boolean getBoolean(@NonNls String name, boolean defaultValue) {
|
||||
return isValueSet(name) ? isTrueValue(name) : defaultValue;
|
||||
}
|
||||
|
||||
public abstract boolean isValueSet(String name);
|
||||
|
||||
public abstract String getValue(@NonNls String name);
|
||||
|
||||
@@ -35,5 +35,5 @@ public @interface Colored {
|
||||
* @return color as hex-string
|
||||
*/
|
||||
@RegExp(prefix = "[0-9a-f]{6}")
|
||||
String color() default "ffffff";
|
||||
String color();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user