From 6e1b659f29554402aa2a472cb0d02e5f1ce31268 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Thu, 26 Jan 2017 17:30:40 +0300 Subject: [PATCH] Modified color and code style schemes highlighting in schemes combo --- .../colors/impl/AbstractColorsScheme.java | 49 ++++++++++----- .../colors/impl/EditorColorsSchemeImpl.java | 63 +++++++++++++++++++ .../psi/codeStyle/CodeStyleSettings.java | 21 +++++++ .../codeStyle/CommonCodeStyleSettings.java | 13 ++++ .../CommonCodeStyleSettingsManager.java | 17 +++++ .../codeStyle/CustomCodeStyleSettings.java | 8 +++ .../options/CodeStyleAbstractPanel.java | 5 +- .../options/CodeStyleSchemesConfigurable.java | 5 +- .../options/codeStyle/CodeStyleMainPanel.java | 7 ++- .../codeStyle/CodeStyleSchemesModel.java | 17 ++++- .../codeStyle/CodeStyleSettingsListener.java | 4 +- .../options/colors/ColorAndFontOptions.java | 16 +++++ .../options/colors/NewColorAndFontPanel.java | 1 + .../schemes/AbstractSchemeActions.java | 8 ++- .../options/schemes/AbstractSchemesPanel.java | 4 ++ .../options/schemes/SchemesCombo.java | 43 ++++++++----- .../options/schemes/SchemesModel.java | 2 + .../colors/impl/EditorColorsManagerImpl.java | 2 +- .../src/com/intellij/util/ReflectionUtil.java | 21 +++++++ 19 files changed, 267 insertions(+), 39 deletions(-) diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java index eedf4c8f199f..ea27e1dd7951 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java @@ -889,9 +889,12 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial return root; } - public boolean isEqualToBundled(AbstractColorsScheme bundledScheme) { + public boolean equals(Object other) { + if (!(other instanceof AbstractColorsScheme)) return false; + AbstractColorsScheme otherScheme = (AbstractColorsScheme)other; + // parent is used only for default schemes (e.g. Darcula — bundled in all ide (opposite to IDE-specific, like Cobalt)) - if (myParentScheme != bundledScheme.myParentScheme && myParentScheme != bundledScheme) { + if (getBaseDefaultScheme(this) != getBaseDefaultScheme(otherScheme)) { return false; } @@ -903,23 +906,39 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial propertyName.equals(META_INFO_ORIGINAL) ) { continue; - } + } - if (!Comparing.equal(myMetaInfo.getProperty(propertyName), bundledScheme.myMetaInfo.getProperty(propertyName))) { + if (!Comparing.equal(myMetaInfo.getProperty(propertyName), otherScheme.myMetaInfo.getProperty(propertyName))) { return false; } } - return getLineSpacing() == bundledScheme.getLineSpacing() && - getConsoleLineSpacing() == bundledScheme.getConsoleLineSpacing() && - getQuickDocFontSize() == bundledScheme.getQuickDocFontSize() && - myFontPreferences.getRealFontFamilies().equals(bundledScheme.myFontPreferences.getRealFontFamilies()) && - myFontPreferences.useLigatures() == bundledScheme.myFontPreferences.useLigatures() && - myConsoleFontPreferences.useLigatures() == bundledScheme.myConsoleFontPreferences.useLigatures() && - myConsoleFontPreferences.getRealFontFamilies().equals(bundledScheme.myConsoleFontPreferences.getRealFontFamilies()) && - myColorsMap.equals(bundledScheme.myColorsMap) && - myAttributesMap.equals(bundledScheme.myAttributesMap) && - myFontPreferences.equals(bundledScheme.myFontPreferences) && - myConsoleFontPreferences.equals(bundledScheme.myConsoleFontPreferences); + return getLineSpacing() == otherScheme.getLineSpacing() && + getConsoleLineSpacing() == otherScheme.getConsoleLineSpacing() && + myFontPreferences.equals(otherScheme.getFontPreferences()) && + myConsoleFontPreferences.equals(otherScheme.getConsoleFontPreferences()) && + attributesEqual(otherScheme) && + colorsEqual(otherScheme) && + myFontPreferences.equals(otherScheme.myFontPreferences); + } + + protected boolean attributesEqual(AbstractColorsScheme otherScheme) { + return myAttributesMap.equals(otherScheme.myAttributesMap); + } + + protected boolean colorsEqual(AbstractColorsScheme otherScheme) { + return myColorsMap.equals(otherScheme.myColorsMap); + } + + @Nullable + private static EditorColorsScheme getBaseDefaultScheme(@NotNull EditorColorsScheme scheme) { + if (!(scheme instanceof AbstractColorsScheme)) { + return null; + } + if (scheme instanceof DefaultColorsScheme) { + return scheme; + } + EditorColorsScheme parent = ((AbstractColorsScheme)scheme).myParentScheme; + return parent != null ? getBaseDefaultScheme(parent) : null; } } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java index e102856ec6f4..77497d82351c 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java @@ -25,6 +25,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.function.Function; import static com.intellij.openapi.editor.markup.TextAttributes.USE_INHERITED_MARKER; @@ -85,4 +88,64 @@ public class EditorColorsSchemeImpl extends AbstractColorsScheme implements Exte newScheme.setDefaultMetaInfo(this); return newScheme; } + + @Override + protected boolean attributesEqual(AbstractColorsScheme otherScheme) { + return compareAttributes(otherScheme, new ArrayList<>()); + } + + @Override + protected boolean colorsEqual(AbstractColorsScheme otherScheme) { + return compareColors(otherScheme, new ArrayList<>()); + } + + private boolean compareAttributes(@NotNull AbstractColorsScheme otherScheme, + @NotNull Collection> filters) { + for (TextAttributesKey key : myAttributesMap.keySet()) { + if (!isTextAttributeKeyIgnored(filters, key) && !getAttributes(key).equals(otherScheme.getAttributes(key))) { + return false; + } + } + filters.add(key -> myAttributesMap.containsKey(key)); + if (myParentScheme instanceof EditorColorsSchemeImpl && + !((EditorColorsSchemeImpl)myParentScheme).compareAttributes(otherScheme, filters)) { + return false; + } + return true; + } + + private static boolean isTextAttributeKeyIgnored(@NotNull Collection> filters, + TextAttributesKey key) { + for (Function filter : filters) { + if (filter.apply(key)) return true; + } + return false; + } + + private boolean compareColors(@NotNull AbstractColorsScheme otherScheme, + @NotNull Collection> filters) { + for (ColorKey key : myColorsMap.keySet()) { + Color thisColor = getColor(key); + Color otherColor = otherScheme.getColor(key); + if (thisColor == null) { + return otherColor == null; + } + if (!isColorKeyIgnored(filters, key) && !thisColor.equals(otherColor)) { + return false; + } + } + filters.add(key -> myColorsMap.containsKey(key)); + if (myParentScheme instanceof EditorColorsSchemeImpl && + !((EditorColorsSchemeImpl)myParentScheme).compareColors(otherScheme, filters)) { + return false; + } + return true; + } + + private static boolean isColorKeyIgnored(@NotNull Collection> filters, ColorKey key) { + for (Function filter : filters) { + if (filter.apply(key)) return false; + } + return true; + } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java index c739b0bce5b7..a460d7b28294 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java @@ -35,6 +35,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.util.Processor; +import com.intellij.util.ReflectionUtil; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ClassMap; import org.jdom.Element; @@ -61,6 +62,8 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea @NonNls private static final String FILETYPE = "fileType"; private CommonCodeStyleSettingsManager myCommonSettingsManager = new CommonCodeStyleSettingsManager(this); + private static CodeStyleSettings myDefaults; + private UnknownElementWriter myUnknownElementWriter = UnknownElementWriter.EMPTY; public CodeStyleSettings() { @@ -1049,4 +1052,22 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea this.quote = quote; } } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CodeStyleSettings)) return false; + if (!ReflectionUtil.comparePublicNonFinalFields(this, obj)) return false; + if (!myCommonSettingsManager.equals(((CodeStyleSettings)obj).myCommonSettingsManager)) return false; + for (CustomCodeStyleSettings customSettings : myCustomSettings.values()) { + if (!customSettings.equals(((CodeStyleSettings)obj).getCustomSettings(customSettings.getClass()))) return false; + } + return true; + } + + public static CodeStyleSettings getDefaults() { + if (myDefaults == null) { + myDefaults = new CodeStyleSettings(); + } + return myDefaults; + } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java index fffe1080d636..c7ad504d9247 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java @@ -1041,4 +1041,17 @@ public class CommonCodeStyleSettings { myOverrideLanguageOptions = overrideLanguageOptions; } } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CommonCodeStyleSettings) { + if ( + ReflectionUtil.comparePublicNonFinalFields(this, obj) && + myIndentOptions.equals(((CommonCodeStyleSettings)obj).getIndentOptions()) + ) { + return true; + } + } + return false; + } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettingsManager.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettingsManager.java index d49725202ac3..5e9f7dde922c 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettingsManager.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettingsManager.java @@ -231,4 +231,21 @@ public class CommonCodeStyleSettingsManager { } } } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CommonCodeStyleSettingsManager) { + CommonCodeStyleSettingsManager other = (CommonCodeStyleSettingsManager)obj; + if (getCommonSettingsMap().size() != other.getCommonSettingsMap().size() || + myUnknownSettingsMap.size() != other.myUnknownSettingsMap.size()) { + return false; + } + for (Language language : myCommonSettingsMap.keySet()) { + CommonCodeStyleSettings theseSettings = myCommonSettingsMap.get(language); + CommonCodeStyleSettings otherSettings = other.getCommonSettings(language); + if (!theseSettings.equals(otherSettings)) return false; + } + } + return true; + } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CustomCodeStyleSettings.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CustomCodeStyleSettings.java index 3dc1c63943b6..1743c865204b 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CustomCodeStyleSettings.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CustomCodeStyleSettings.java @@ -19,6 +19,7 @@ import com.intellij.openapi.util.DefaultJDOMExternalizer; import com.intellij.openapi.util.DifferenceFilter; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; +import com.intellij.util.ReflectionUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -86,4 +87,11 @@ public abstract class CustomCodeStyleSettings implements Cloneable { */ protected void importLegacySettings() { } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CustomCodeStyleSettings)) return false; + if (!ReflectionUtil.comparePublicNonFinalFields(this, obj)) return false; + return true; + } } diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java index ad1289c3ec7c..e8cbca68fa21 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java @@ -133,7 +133,7 @@ public abstract class CodeStyleAbstractPanel implements Disposable { protected void somethingChanged() { if (myModel != null) { - myModel.fireCurrentSettingsChanged(); + myModel.fireBeforeCurrentSettingsChanged(); } } @@ -212,6 +212,9 @@ public abstract class CodeStyleAbstractPanel implements Disposable { try { apply(mySettings); + if (myModel != null) { + myModel.fireAfterCurrentSettingsChanged(); + } } catch (ConfigurationException ignore) { } diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java index ad3a8b7a8875..de08ba7b981b 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java @@ -231,8 +231,11 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent. } @Override - public void currentSettingsChanged() { + public void beforeCurrentSettingsChanged() { + } + @Override + public void afterCurrentSettingsChanged() { } @Override diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java index 7fc8f2d28e99..6ae492a7ed56 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java @@ -95,12 +95,17 @@ public class CodeStyleMainPanel extends JPanel implements TabbedLanguageCodeStyl } @Override - public void currentSettingsChanged() { + public void beforeCurrentSettingsChanged() { if (!myIsDisposed) { ensureCurrentPanel().onSomethingChanged(); } } + @Override + public void afterCurrentSettingsChanged() { + mySchemesPanel.updateOnCurrentSettingsChange(); + } + @Override public void usePerProjectSettingsOptionChanged() { mySchemesPanel.usePerProjectSettingsOptionChanged(); diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesModel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesModel.java index 208fe8df9cf9..c06c6882333b 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesModel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesModel.java @@ -179,8 +179,8 @@ public class CodeStyleSchemesModel implements SchemesModel { return false; } - public void fireCurrentSettingsChanged() { - myDispatcher.getMulticaster().currentSettingsChanged(); + public void fireBeforeCurrentSettingsChanged() { + myDispatcher.getMulticaster().beforeCurrentSettingsChanged(); } public void fireSchemeChanged(CodeStyleScheme scheme) { @@ -190,6 +190,10 @@ public class CodeStyleSchemesModel implements SchemesModel { public void fireSchemeListChanged() { myDispatcher.getMulticaster().schemeListChanged(); } + + public void fireAfterCurrentSettingsChanged() { + myDispatcher.getMulticaster().afterCurrentSettingsChanged(); + } public CodeStyleScheme getSelectedGlobalScheme() { return myGlobalSelected; @@ -238,7 +242,7 @@ public class CodeStyleSchemesModel implements SchemesModel { @Override public boolean canResetScheme(@NotNull CodeStyleScheme scheme) { - return true; + return scheme.isDefault(); } @Override @@ -261,6 +265,13 @@ public class CodeStyleSchemesModel implements SchemesModel { return findSchemeByName(name) != null; } + @Override + public boolean differsFromDefault(@NotNull CodeStyleScheme scheme) { + CodeStyleSettings defaults = CodeStyleSettings.getDefaults(); + CodeStyleSettings clonedSettings = getCloneSettings(scheme); + return !defaults.equals(clonedSettings); + } + public List getAllSortedSchemes() { List schemes = new ArrayList<>(); schemes.addAll(getSchemes()); diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSettingsListener.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSettingsListener.java index 7a1c480f2147..b1905443f4aa 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSettingsListener.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSettingsListener.java @@ -25,7 +25,9 @@ public interface CodeStyleSettingsListener extends EventListener { void schemeListChanged(); - void currentSettingsChanged(); + void beforeCurrentSettingsChanged(); + + void afterCurrentSettingsChanged(); void usePerProjectSettingsOptionChanged(); diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java index 3d8b36e3989e..70bf77b7a48f 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java @@ -29,6 +29,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.editor.colors.*; +import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager; import com.intellij.openapi.editor.colors.impl.*; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; @@ -192,6 +193,21 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract return mySchemes.get(name) != null || mySchemes.get(SchemeManager.EDITABLE_COPY_PREFIX + name) != null; } + @Override + public boolean differsFromDefault(@NotNull EditorColorsScheme scheme) { + if (scheme.getName().startsWith(SchemeManager.EDITABLE_COPY_PREFIX)) { + String displayName = SchemeManager.getDisplayName(scheme); + EditorColorsScheme defaultScheme = DefaultColorSchemesManager.getInstance().getScheme(displayName); + if (defaultScheme == null) { + defaultScheme = EditorColorsManager.getInstance().getScheme(displayName); + } + if (defaultScheme != null) { + return !scheme.equals(defaultScheme); + } + } + return false; + } + public static boolean isReadOnly(@NotNull final EditorColorsScheme scheme) { return ((MyColorScheme)scheme).isReadOnly(); } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/NewColorAndFontPanel.java b/platform/lang-impl/src/com/intellij/application/options/colors/NewColorAndFontPanel.java index 6196aac537f4..8fb55e9076cb 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/NewColorAndFontPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/NewColorAndFontPanel.java @@ -107,6 +107,7 @@ public class NewColorAndFontPanel extends JPanel { optionsPanel.addListener(new ColorAndFontSettingsListener.Abstract() { @Override public void settingsChanged() { + mySchemesPanel.updateOnCurrentSettingsChange(); optionsPanel.applyChangesToScheme(); previewPanel.updateView(); } diff --git a/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java b/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java index 51c1bbf16556..51f3ad2e7b47 100644 --- a/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java +++ b/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java @@ -107,7 +107,13 @@ public abstract class AbstractSchemeActions { public void update(AnActionEvent e) { Presentation p = e.getPresentation(); T scheme = getCurrentScheme(); - p.setEnabled(scheme != null && mySchemesPanel.getModel().canResetScheme(scheme)); + if(scheme != null && mySchemesPanel.getModel().canResetScheme(scheme)) { + p.setVisible(true); + p.setEnabled(mySchemesPanel.getModel().differsFromDefault(scheme)); + } + else { + p.setEnabledAndVisible(false); + } } } diff --git a/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemesPanel.java b/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemesPanel.java index 5c74ac2ab9bb..920977d19638 100644 --- a/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemesPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemesPanel.java @@ -133,4 +133,8 @@ public abstract class AbstractSchemesPanel extends JPanel { @NotNull public abstract SchemesModel getModel(); + + public void updateOnCurrentSettingsChange() { + mySchemesCombo.updateSelected(); + } } diff --git a/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesCombo.java b/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesCombo.java index b8d84c2b3a42..c08276ca5dde 100644 --- a/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesCombo.java +++ b/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesCombo.java @@ -45,6 +45,7 @@ public class SchemesCombo { private AbstractSchemesPanel mySchemesPanel; private final CardLayout myLayout; private final JTextField myNameEditorField; + private final MyComboBoxModel myComboBoxModel; private final static KeyStroke ESC_KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); private final static KeyStroke ENTER_KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); @@ -53,6 +54,7 @@ public class SchemesCombo { mySchemesPanel = schemesPanel; myLayout = new CardLayout(); myRootPanel = new JPanel(myLayout); + myComboBoxModel = new MyComboBoxModel(); createCombo(); myRootPanel.add(myComboBox); myNameEditorField = createNameEditorField(); @@ -76,6 +78,10 @@ public class SchemesCombo { }, ENTER_KEY_STROKE, JComponent.WHEN_FOCUSED); return nameEditorField; } + + public void updateSelected() { + myComboBox.repaint(); + } private void stopEdit() { String newName = myNameEditorField.getText(); @@ -105,7 +111,7 @@ public class SchemesCombo { } private void createCombo() { - myComboBox = new ComboBox<>(); + myComboBox = new ComboBox<>(myComboBoxModel); myComboBox.setRenderer(new MyListCellRenderer()); myComboBox.addActionListener(new ActionListener() { @Override @@ -113,15 +119,6 @@ public class SchemesCombo { mySchemesPanel.getActions().onSchemeChanged(getSelectedScheme()); } }); - myComboBox.setModel(new DefaultComboBoxModel>() { - @Override - public void setSelectedItem(Object anObject) { - if (anObject instanceof MySchemeListItem && ((MySchemeListItem)anObject).isSeparator()) { - return; - } - super.setSelectedItem(anObject); - } - }); } public void startEdit() { @@ -134,19 +131,24 @@ public class SchemesCombo { } private SimpleTextAttributes getSchemeAttributes(@NotNull MySchemeListItem item) { + SchemesModel model = mySchemesPanel.getModel(); T scheme = item.getScheme(); - return scheme != null && mySchemesPanel.getModel().canDeleteScheme(scheme) + SimpleTextAttributes baseAttributes = scheme !=null && model.canDeleteScheme(scheme) ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; + if (scheme != null && model.canResetScheme(scheme) && model.differsFromDefault(scheme)) { + return baseAttributes.derive(-1, JBColor.BLUE, null, null); + } + return baseAttributes; } public void resetSchemes(@NotNull Collection schemes) { - myComboBox.removeAllItems(); + myComboBoxModel.removeAllElements(); SchemesModel model = mySchemesPanel.getModel(); if (model.supportsProjectSchemes()) { - myComboBox.addItem(new MySeparatorItem(PROJECT_LEVEL)); + myComboBoxModel.addElement(new MySeparatorItem(PROJECT_LEVEL)); addItems(schemes, scheme -> model.isProjectScheme(scheme)); - myComboBox.addItem(new MySeparatorItem(IDE_LEVEL)); + myComboBoxModel.addElement(new MySeparatorItem(IDE_LEVEL)); addItems(schemes, scheme -> !model.isProjectScheme(scheme)); } else { @@ -157,7 +159,7 @@ public class SchemesCombo { private void addItems(@NotNull Collection schemes, Function filter) { for (T scheme : schemes) { if (filter.apply(scheme)) { - myComboBox.addItem(new MySchemeListItem<>(scheme)); + myComboBoxModel.addElement(new MySchemeListItem<>(scheme)); } } } @@ -297,4 +299,15 @@ public class SchemesCombo { } return null; } + + private class MyComboBoxModel extends DefaultComboBoxModel> { + + @Override + public void setSelectedItem(Object anObject) { + if (anObject instanceof MySchemeListItem && ((MySchemeListItem)anObject).isSeparator()) { + return; + } + super.setSelectedItem(anObject); + } + } } diff --git a/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesModel.java b/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesModel.java index b2771ccb43a6..d95b8204a12d 100644 --- a/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesModel.java +++ b/platform/lang-impl/src/com/intellij/application/options/schemes/SchemesModel.java @@ -32,4 +32,6 @@ public interface SchemesModel { boolean canRenameScheme(@NotNull T scheme); boolean nameExists(@NotNull String name); + + boolean differsFromDefault(@NotNull T scheme); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java index dee714f2a4ff..d109860a7750 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java @@ -128,7 +128,7 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers return false; } - return scheme.isEqualToBundled(bundledScheme); + return scheme.equals(bundledScheme); } @Override diff --git a/platform/util/src/com/intellij/util/ReflectionUtil.java b/platform/util/src/com/intellij/util/ReflectionUtil.java index 9ed61e54e526..aebeccede54d 100644 --- a/platform/util/src/com/intellij/util/ReflectionUtil.java +++ b/platform/util/src/com/intellij/util/ReflectionUtil.java @@ -16,6 +16,7 @@ package com.intellij.util; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.DifferenceFilter; import com.intellij.util.containers.ContainerUtil; @@ -500,6 +501,26 @@ public class ReflectionUtil { return valuesChanged; } + public static boolean comparePublicNonFinalFields(@NotNull Object first, + @NotNull Object second) { + Set firstFields = ContainerUtil.newHashSet(first.getClass().getFields()); + for (Field field : second.getClass().getFields()) { + if (firstFields.contains(field)) { + if (isPublic(field) && !isFinal(field)) { + try { + if (!Comparing.equal(field.get(first), field.get(second))) { + return false; + } + } + catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + } + return true; + } + public static void copyFieldValue(@NotNull Object from, @NotNull Object to, @NotNull Field field) throws IllegalAccessException { Class fieldType = field.getType();