mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Properly and consistently sort editor color schemes (fixes IDEA-162904 Default "Editor colors and fonts" is "All hallow's eve")
This commit is contained in:
+1
-6
@@ -179,12 +179,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
|
||||
@NotNull
|
||||
public String[] getSchemeNames() {
|
||||
List<MyColorScheme> schemes = new ArrayList<>(mySchemes.values());
|
||||
Collections.sort(schemes, (o1, o2) -> {
|
||||
if (isReadOnly(o1) && !isReadOnly(o2)) return -1;
|
||||
if (!isReadOnly(o1) && isReadOnly(o2)) return 1;
|
||||
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
});
|
||||
Collections.sort(schemes, EditorColorSchemesComparator.INSTANCE);
|
||||
|
||||
List<String> names = new ArrayList<>(schemes.size());
|
||||
for (MyColorScheme scheme : schemes) {
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.colors.impl;
|
||||
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import static com.intellij.openapi.editor.colors.EditorColorsScheme.DEFAULT_SCHEME_NAME;
|
||||
|
||||
/**
|
||||
* Defines the order in which editor color schemes are displayed.
|
||||
*/
|
||||
public class EditorColorSchemesComparator implements Comparator<EditorColorsScheme> {
|
||||
public final static EditorColorSchemesComparator INSTANCE = new EditorColorSchemesComparator();
|
||||
|
||||
public final static int DEFAULT_SCHEME = 0;
|
||||
public final static int ONE_OF_DEFAULT_SCHEMES = DEFAULT_SCHEME + 1;
|
||||
public final static int BUNDLED_SCHEME = ONE_OF_DEFAULT_SCHEMES + 1;
|
||||
public final static int CUSTOM_SCHEME = BUNDLED_SCHEME + 1;
|
||||
|
||||
private EditorColorSchemesComparator() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(EditorColorsScheme s1, EditorColorsScheme s2) {
|
||||
int order1 = getOrder(s1);
|
||||
int order2 = getOrder(s2);
|
||||
if (order1 != order2) return order1 - order2;
|
||||
return s1.getName().compareToIgnoreCase(s2.getName());
|
||||
}
|
||||
|
||||
|
||||
private static int getOrder(@NotNull EditorColorsScheme scheme) {
|
||||
if (scheme instanceof AbstractColorsScheme) {
|
||||
EditorColorsScheme original = ((AbstractColorsScheme)scheme).getOriginal();
|
||||
if (original instanceof DefaultColorsScheme) {
|
||||
return DEFAULT_SCHEME_NAME.equals(original.getName()) ? DEFAULT_SCHEME : ONE_OF_DEFAULT_SCHEMES;
|
||||
}
|
||||
if (original instanceof ReadOnlyColorsScheme) {
|
||||
return BUNDLED_SCHEME;
|
||||
}
|
||||
}
|
||||
return CUSTOM_SCHEME;
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -288,13 +288,7 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers
|
||||
@Override
|
||||
public EditorColorsScheme[] getAllSchemes() {
|
||||
EditorColorsScheme[] result = getAllVisibleSchemes(mySchemeManager.getAllSchemes());
|
||||
Arrays.sort(result, (s1, s2) -> {
|
||||
if (isDefaultScheme(s1) && !isDefaultScheme(s2)) return -1;
|
||||
if (!isDefaultScheme(s1) && isDefaultScheme(s2)) return 1;
|
||||
if (s1.getName().equals(DEFAULT_NAME)) return -1;
|
||||
if (s2.getName().equals(DEFAULT_NAME)) return 1;
|
||||
return s1.getName().compareToIgnoreCase(s2.getName());
|
||||
});
|
||||
Arrays.sort(result, EditorColorSchemesComparator.INSTANCE);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user