From 5d255311657444dba1e8e5174ea57fe6601d2ce6 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Mon, 10 Nov 2008 21:46:34 +0300 Subject: [PATCH] Revet color chemes API chages. Will be commited via "Remote run commit" --- .../options/colors/ColorAndFontOptions.java | 17 ++--- .../application/options/colors/FontOptions.java | 22 +++++-- .../application/options/colors/SchemesPanel.java | 18 ++++- .../diff/impl/settings/DiffOptionsPanel.java | 8 +-- .../editor/colors/impl/DefaultColorsScheme.java | 2 +- .../colors/impl/EditorColorsManagerImpl.java | 77 +++------------------- .../src/META-INF/PlatformExtensionPoints.xml | 2 - .../src/messages/ApplicationBundle.properties | 6 +- .../src/messages/OptionsBundle.properties | 4 +- 9 files changed, 56 insertions(+), 100 deletions(-) diff --git a/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java b/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java index 0b438f9d64..5561943b78 100644 --- a/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java +++ b/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java @@ -18,7 +18,6 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager; import com.intellij.openapi.editor.colors.impl.DefaultColorsScheme; import com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl; -import com.intellij.openapi.editor.colors.impl.ReadOnlyColorsScheme; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.options.Configurable; @@ -126,16 +125,16 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract return mySelectedScheme.getDescriptors(); } - public static boolean isReadOnly(final EditorColorsScheme scheme) { - return ((MyColorScheme)scheme).isReadOnly(); + public static boolean isDefault(EditorColorsScheme scheme) { + return ((MyColorScheme)scheme).isDefault(); } public String[] getSchemeNames() { ArrayList schemes = new ArrayList(mySchemes.values()); Collections.sort(schemes, new Comparator() { public int compare(MyColorScheme o1, MyColorScheme o2) { - if (isReadOnly(o1) && !isReadOnly(o2)) return -1; - if (!isReadOnly(o1) && isReadOnly(o2)) return 1; + if (isDefault(o1) && !isDefault(o2)) return -1; + if (!isDefault(o1) && isDefault(o2)) return 1; return o1.getName().compareToIgnoreCase(o2.getName()); } @@ -685,8 +684,8 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract myRootSchemesPanel = null; } - public boolean currentSchemeIsReadOnly() { - return isReadOnly(mySelectedScheme); + public boolean currentSchemeIsDefault() { + return mySelectedScheme.isDefault(); } public boolean currentSchemeIsShared() { @@ -910,10 +909,6 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract return myParentScheme instanceof DefaultColorsScheme; } - public boolean isReadOnly() { - return myParentScheme instanceof ReadOnlyColorsScheme; - } - public boolean isModified() { if (isFontModified()) return true; diff --git a/lang-impl/src/com/intellij/application/options/colors/FontOptions.java b/lang-impl/src/com/intellij/application/options/colors/FontOptions.java index 176d9bcb07..500675b460 100644 --- a/lang-impl/src/com/intellij/application/options/colors/FontOptions.java +++ b/lang-impl/src/com/intellij/application/options/colors/FontOptions.java @@ -7,6 +7,7 @@ import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.ui.FixedSizeButton; +import com.intellij.openapi.ui.Messages; import com.intellij.ui.DocumentAdapter; import com.intellij.ui.IdeBorderFactory; import com.intellij.util.EventDispatcher; @@ -54,7 +55,7 @@ public class FontOptions extends JPanel implements OptionsPanel{ myEditorFontSizeField.setText(Integer.toString(getCurrentScheme().getEditorFontSize())); myFontNameField.setText(getCurrentScheme().getEditorFontName()); - if (ColorAndFontOptions.isReadOnly(myOptions.getSelectedScheme())) { + if (ColorAndFontOptions.isDefault(myOptions.getSelectedScheme())) { myLineSpacingField.setEnabled(false); myEditorFontSizeField.setEditable(false); myFontNameField.setEnabled(false); @@ -135,8 +136,8 @@ public class FontOptions extends JPanel implements OptionsPanel{ myFontNameButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EditorColorsScheme current = getCurrentScheme(); - if (ColorAndFontOptions.isReadOnly(current) || ColorSettingsUtil.isSharedScheme(current)) { - ColorAndFontPanel.showReadOnlyMessage(FontOptions.this, ColorSettingsUtil.isSharedScheme(current)); + if (ColorAndFontOptions.isDefault(current) || ColorSettingsUtil.isSharedScheme(current)) { + showReadOnlyMessage(FontOptions.this, ColorSettingsUtil.isSharedScheme(current)); return; } @@ -188,6 +189,17 @@ public class FontOptions extends JPanel implements OptionsPanel{ return editorFontPanel; } + public static void showReadOnlyMessage(JComponent parent, final boolean sharedScheme) { + if (!sharedScheme) { + Messages.showMessageDialog(parent, ApplicationBundle.message("error.default.scheme.cannot.be.modified"), + ApplicationBundle.message("title.cannot.modify.default.scheme"), Messages.getInformationIcon()); + } + else { + Messages.showMessageDialog(parent, ApplicationBundle.message("error.shared.scheme.cannot.be.modified"), + ApplicationBundle.message("title.cannot.modify.default.scheme"), Messages.getInformationIcon()); + } + } + private void selectFont() { initFontTables(); @@ -227,8 +239,8 @@ public class FontOptions extends JPanel implements OptionsPanel{ public boolean updateDescription(boolean modified) { EditorColorsScheme scheme = myOptions.getSelectedScheme(); - if (modified && (ColorAndFontOptions.isReadOnly(scheme) || ColorSettingsUtil.isSharedScheme(scheme))) { - ColorAndFontPanel.showReadOnlyMessage(this, ColorSettingsUtil.isSharedScheme(scheme)); + if (modified && (ColorAndFontOptions.isDefault(scheme) || ColorSettingsUtil.isSharedScheme(scheme))) { + showReadOnlyMessage(this, ColorSettingsUtil.isSharedScheme(scheme)); return false; } diff --git a/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java b/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java index 4cdf1d2d6c..810abb03fc 100644 --- a/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java +++ b/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java @@ -9,6 +9,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl; import com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl; import com.intellij.openapi.options.SchemesManager; +import com.intellij.openapi.ui.Messages; import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.Nullable; @@ -44,7 +45,7 @@ public class SchemesPanel extends JPanel { public void actionPerformed(ActionEvent e) { if (mySchemeComboBox.getSelectedIndex() != -1) { EditorColorsScheme selected = myOptions.selectScheme((String)mySchemeComboBox.getSelectedItem()); - if (ColorAndFontOptions.isReadOnly(selected)) { + if (ColorAndFontOptions.isDefault(selected)) { myDeleteButton.setEnabled(false); if (myExportButton != null) { myExportButton.setEnabled(false); @@ -87,6 +88,17 @@ public class SchemesPanel extends JPanel { return null; } + public static void showReadOnlyMessage(JComponent parent, final boolean sharedScheme) { + if (!sharedScheme) { + Messages.showMessageDialog(parent, ApplicationBundle.message("error.default.scheme.cannot.be.modified"), + ApplicationBundle.message("title.cannot.modify.default.scheme"), Messages.getInformationIcon()); + } + else { + Messages.showMessageDialog(parent, ApplicationBundle.message("error.shared.scheme.cannot.be.modified"), + ApplicationBundle.message("title.cannot.modify.default.scheme"), Messages.getInformationIcon()); + } + } + private JPanel createSchemePanel() { JPanel panel = new JPanel(new GridBagLayout()); @@ -188,8 +200,8 @@ public class SchemesPanel extends JPanel { public boolean updateDescription(boolean modified) { EditorColorsScheme scheme = myOptions.getSelectedScheme(); - if (modified && (ColorAndFontOptions.isReadOnly(scheme) || ColorSettingsUtil.isSharedScheme(scheme))) { - ColorAndFontPanel.showReadOnlyMessage(this, ColorSettingsUtil.isSharedScheme(scheme)); + if (modified && (ColorAndFontOptions.isDefault(scheme) || ColorSettingsUtil.isSharedScheme(scheme))) { + showReadOnlyMessage(this, ColorSettingsUtil.isSharedScheme(scheme)); return false; } diff --git a/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java b/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java index aa6315a0c9..257f717734 100644 --- a/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java +++ b/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java @@ -197,11 +197,9 @@ public class DiffOptionsPanel implements OptionsPanel { } private boolean checkModifiableScheme() { - boolean isReadOnly = myOptions.currentSchemeIsReadOnly(); - if (isReadOnly) { - ColorAndFontPanel.showReadOnlyMessage(myWholePanel, myOptions.currentSchemeIsShared()); - } - return !isReadOnly; + boolean isDefault = myOptions.currentSchemeIsDefault(); + if (isDefault) ColorAndFontPanel.showReadOnlyMessage(myWholePanel, myOptions.currentSchemeIsShared()); + return !isDefault; } private MyColorAndFontDescription getSelectedDescription() { diff --git a/platform-impl/src/com/intellij/openapi/editor/colors/impl/DefaultColorsScheme.java b/platform-impl/src/com/intellij/openapi/editor/colors/impl/DefaultColorsScheme.java index cc76eeeb64..b181ef932f 100644 --- a/platform-impl/src/com/intellij/openapi/editor/colors/impl/DefaultColorsScheme.java +++ b/platform-impl/src/com/intellij/openapi/editor/colors/impl/DefaultColorsScheme.java @@ -13,7 +13,7 @@ import org.jdom.Element; import java.awt.*; -public class DefaultColorsScheme extends AbstractColorsScheme implements ReadOnlyColorsScheme { +public class DefaultColorsScheme extends AbstractColorsScheme { private String myName; public DefaultColorsScheme(DefaultColorSchemesManager defaultColorSchemesManager) { diff --git a/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java b/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java index 90d481b9b6..088e429fb8 100644 --- a/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java +++ b/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java @@ -54,8 +54,15 @@ public class EditorColorsManagerImpl extends EditorColorsManager new SchemeProcessor() { public EditorColorsSchemeImpl readScheme(final Document document) throws InvalidDataException, IOException, JDOMException { + Element root = document.getRootElement(); - return loadSchemeFromDocument(document, true); + if (root == null || !SCHEME_NODE_NAME.equals(root.getName())) { + throw new InvalidDataException(); + } + + EditorColorsSchemeImpl scheme = new EditorColorsSchemeImpl(null, DefaultColorSchemesManager.getInstance()); + scheme.readExternal(root); + return scheme; } public Document writeScheme(final EditorColorsSchemeImpl scheme) throws WriteExternalException { @@ -76,7 +83,7 @@ public class EditorColorsManagerImpl extends EditorColorsManager } public boolean shouldBeSaved(final EditorColorsSchemeImpl scheme) { - return !(scheme instanceof ReadOnlyColorsScheme); + return true; } public void initScheme(final EditorColorsSchemeImpl scheme) { @@ -97,74 +104,10 @@ public class EditorColorsManagerImpl extends EditorColorsManager addDefaultSchemes(); - // Load default schemes from providers - loadAdditionalDefaultSchemes(); loadAllSchemes(); - setGlobalScheme(myDefaultColorSchemesManager.getAllSchemes()[0]); } - private void loadAdditionalDefaultSchemes() { - // Get color schemes from EPs - //for (BundledColorSchemesProvider provider : BundledColorSchemesProvider.EP_NAME.getExtensions()) { - // final String[] schemesPaths = provider.getBundledSchemesRelativePaths(); - // - // for (final String schemePath : schemesPaths) { - // try { - // final InputStream inputStream = DecodeDefaultsUtil.getDefaultsInputStream(provider, schemePath); - // if (inputStream == null) { - // final String msg = OptionsBundle.message("options.color.schemes.load.read.error", schemePath); - // LOG.info(msg); - // Messages.showErrorDialog(msg, OptionsBundle.message("options.color.schemes.load.settings.title")); - // continue; - // } - // - // final Document document; - // try { - // document = JDOMUtil.loadDocument(inputStream); - // } - // catch (JDOMException e) { - // LOG.info("Error reading scheme from " + schemePath + ": " + e.getLocalizedMessage()); - // throw e; - // } - // final EditorColorsSchemeImpl scheme = loadSchemeFromDocument(document, false); - // mySchemesManager.addNewScheme(scheme, false); - // } - // catch (final Exception e) { - // ApplicationManager.getApplication().invokeLater( - // new Runnable(){ - // public void run() { - // final String msg = OptionsBundle.message("options.color.schemes.load.read.error", schemePath + ": " + e.getLocalizedMessage()); - // LOG.info(msg, e); - // Messages.showErrorDialog(msg, OptionsBundle.message("options.color.schemes.load.settings.title")); - // } - // } - // ); - // - // } - // } - //} - } - - private EditorColorsSchemeImpl loadSchemeFromDocument(final Document document, - final boolean isEditable) - throws InvalidDataException { - - final Element root = document.getRootElement(); - - if (root == null || !SCHEME_NODE_NAME.equals(root.getName())) { - throw new InvalidDataException(); - } - - final EditorColorsSchemeImpl scheme = isEditable - // editable scheme - ? new EditorColorsSchemeImpl(null, DefaultColorSchemesManager.getInstance()) - //not editable scheme - : new ReadOnlyColorsSchemeImpl(null, DefaultColorSchemesManager.getInstance()); - scheme.readExternal(root); - return scheme; - } - // ------------------------------------------------------------------------- // ApplicationComponent interface implementation // ------------------------------------------------------------------------- @@ -333,4 +276,4 @@ public class EditorColorsManagerImpl extends EditorColorsManager public SchemesManager getSchemesManager() { return mySchemesManager; } -} \ No newline at end of file +} diff --git a/platform-resources/src/META-INF/PlatformExtensionPoints.xml b/platform-resources/src/META-INF/PlatformExtensionPoints.xml index 5e6adc980e..4fea349f29 100644 --- a/platform-resources/src/META-INF/PlatformExtensionPoints.xml +++ b/platform-resources/src/META-INF/PlatformExtensionPoints.xml @@ -77,6 +77,4 @@ - - diff --git a/platform-resources_eng/src/messages/ApplicationBundle.properties b/platform-resources_eng/src/messages/ApplicationBundle.properties index a242c580d4..c05ae20601 100644 --- a/platform-resources_eng/src/messages/ApplicationBundle.properties +++ b/platform-resources_eng/src/messages/ApplicationBundle.properties @@ -437,9 +437,9 @@ editbox.font.size=Size: editbox.line.spacing=Line spacing: combobox.scheme.name=Scheme name: progress.analyzing.fonts=Analyzing Fonts -error.readonly.scheme.cannot.be.modified=Read-only scheme cannot be modified. Please do "Save As..." first. +error.default.scheme.cannot.be.modified=Default scheme cannot be modified. Please do "Save As..." first. error.shared.scheme.cannot.be.modified=Shared scheme cannot be modified. Please do "Save As..." first. -title.cannot.modify.readonly.scheme=Cannot Modify read-only Scheme +title.cannot.modify.default.scheme=Cannot Modify Default Scheme title.save.color.scheme.as=Save Color Scheme As title.path.variables=Path Variables editbox.path.macro.value=Value: @@ -469,4 +469,4 @@ button.new=&New building.include.indices=Building include indices... loading.include.indices=Loading include indices... use.external.annotations=Use &external annotations -insert.override.annotation=Insert @&Override annotation \ No newline at end of file +insert.override.annotation=Insert @&Override annotation diff --git a/platform-resources_eng/src/messages/OptionsBundle.properties b/platform-resources_eng/src/messages/OptionsBundle.properties index f0c981391d..40669106eb 100644 --- a/platform-resources_eng/src/messages/OptionsBundle.properties +++ b/platform-resources_eng/src/messages/OptionsBundle.properties @@ -147,12 +147,10 @@ project.settings.display.name=Project Settings [{0}] template.project.settings.short.name=Template Project project.settings.short.name=Project options.color.schemes.presentable.name=Color schemes -options.color.schemes.load.settings.title=Load Settings -options.color.schemes.load.read.error=Cannot read scheme from {0} options.editor.settings.presentable.name=Editor settings options.java.attribute.descriptor.info=Info options.java.attribute.descriptor.server.problems=Problem from server options.java.attribute.descriptor.server.duplicate=Duplicate from server options.general.color.descriptor.injected.language.fragment=Injected language fragment options.general.attribute.descriptior.identifier.under.caret=Identifier under caret -options.general.attribute.descriptior.identifier.under.caret.write=Identifier under caret (write) \ No newline at end of file +options.general.attribute.descriptior.identifier.under.caret.write=Identifier under caret (write) -- 2.11.4.GIT