let user scopes have color

GitOrigin-RevId: 244c32358722b9e04191bda8878b31b38ac297b4
This commit is contained in:
Gregory.Shrago
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent fc44f9b724
commit 00618933d3
2 changed files with 32 additions and 7 deletions
@@ -1,16 +1,18 @@
// 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 com.intellij.ide.util.scopeChooser;
import com.intellij.openapi.util.ColoredItem;
import com.intellij.openapi.util.Comparing;
import com.intellij.psi.search.SearchScope;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author anna
*/
public class ScopeDescriptor {
public class ScopeDescriptor implements ColoredItem {
private final SearchScope myScope;
public ScopeDescriptor(@Nullable SearchScope scope) {
@@ -34,4 +36,10 @@ public class ScopeDescriptor {
public boolean scopeEquals(SearchScope scope) {
return Comparing.equal(myScope, scope);
}
@Nullable
@Override
public Color getColor() {
return myScope instanceof ColoredItem ? ((ColoredItem)myScope).getColor() : null;
}
}
@@ -7,14 +7,18 @@ import com.intellij.ide.util.treeView.WeighedItem;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ColoredItem;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packageDependencies.ChangeListsScopesProvider;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
import com.intellij.ui.FileColorManager;
import com.intellij.util.TreeItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -81,7 +85,7 @@ public class DefaultSearchScopeProviders {
List<NamedScope> changeLists = ChangeListsScopesProvider.getInstance(project).getFilteredScopes();
if (!changeLists.isEmpty()) {
for (NamedScope changeListScope : changeLists) {
result.add(wrapNamedScope(project, changeListScope));
result.add(wrapNamedScope(project, changeListScope, false));
}
}
return result;
@@ -102,7 +106,7 @@ public class DefaultSearchScopeProviders {
for (NamedScopesHolder holder : holders) {
NamedScope[] scopes = holder.getEditableScopes(); // predefined scopes already included
for (NamedScope scope : scopes) {
result.add(wrapNamedScope(project, scope));
result.add(wrapNamedScope(project, scope, true));
}
}
return result;
@@ -110,22 +114,35 @@ public class DefaultSearchScopeProviders {
}
@NotNull
private static GlobalSearchScope wrapNamedScope(@NotNull Project project, @NotNull NamedScope namedScope) {
private static GlobalSearchScope wrapNamedScope(@NotNull Project project, @NotNull NamedScope namedScope, boolean colored) {
GlobalSearchScope scope = GlobalSearchScopesCore.filterScope(project, namedScope);
return namedScope instanceof WeighedItem ? new MyWeightedScope(scope, ((WeighedItem)namedScope).getWeight()) : scope;
if (!colored && !(namedScope instanceof WeighedItem)) return scope;
int weight = namedScope instanceof WeighedItem ? ((WeighedItem)namedScope).getWeight() : -1;
Color color = !colored ? null :
//namedScope instanceof ColoredItem ? ((ColoredItem)namedScope).getColor() :
FileColorManager.getInstance(project).getScopeColor(namedScope.getName());
return new MyWeightedScope(scope, weight, color);
}
private static class MyWeightedScope extends DelegatingGlobalSearchScope implements WeighedItem {
private static class MyWeightedScope extends DelegatingGlobalSearchScope implements WeighedItem, ColoredItem {
final int weight;
final Color color;
MyWeightedScope(@NotNull GlobalSearchScope scope, int weight) {
MyWeightedScope(@NotNull GlobalSearchScope scope, int weight, Color color) {
super(scope);
this.weight = weight;
this.color = color;
}
@Override
public int getWeight() {
return weight;
}
@Nullable
@Override
public Color getColor() {
return color;
}
}
}