From 0dc2c3aa1de72273d2b1ff1186353be0cb92893a Mon Sep 17 00:00:00 2001 From: Daniel Marcotte Date: Sun, 3 Feb 2013 11:07:13 -0800 Subject: [PATCH] Refactor EditorTextFieldProvider to support more features Replace the EditorCustomization.Feature enum with an EditorFeature object which can support richer customization than "enabled/disabled". The catalyst for this change was the addition of RightMarginEditorFeature which needs a right margin size in addition to "enabled/disabled" --- .../ui/EditorTextFieldProviderImpl.java | 31 +------- .../ui/AbstractEditorCustomization.java | 77 ------------------- ...tionalPageAtBottomEditorCustomization.java | 13 ++-- .../AdditionalPageAtBottomEditorFeature.java | 7 ++ .../com/intellij/ui/EditorCustomization.java | 54 +++++++------ .../src/com/intellij/ui/EditorFeature.java | 16 ++++ .../intellij/ui/EditorTextFieldProvider.java | 35 ++------- ...orizontalScrollBarEditorCustomization.java | 11 +-- .../ui/HorizontalScrollBarEditorFeature.java | 7 ++ .../ui/OneLineEditorCustomization.java | 11 +-- .../com/intellij/ui/OneLineEditorFeature.java | 7 ++ .../ui/RightMarginEditorCustomization.java | 31 ++++++++ .../intellij/ui/RightMarginEditorFeature.java | 14 ++++ .../ui/SoftWrapsEditorCustomization.java | 11 +-- .../intellij/ui/SoftWrapsEditorFeature.java | 7 ++ .../ui/SpellCheckingEditorFeature.java | 7 ++ .../src/META-INF/LangExtensions.xml | 2 + .../changes/ui/NewEditChangelistPanel.java | 21 ++--- .../openapi/vcs/ui/CommitMessage.java | 45 +++-------- .../history/wholeTree/UsersFilterAction.java | 14 ++-- .../ui/SpellCheckingEditorCustomization.java | 21 +++-- 21 files changed, 205 insertions(+), 237 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/ui/AbstractEditorCustomization.java create mode 100644 platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorFeature.java create mode 100644 platform/platform-impl/src/com/intellij/ui/EditorFeature.java create mode 100644 platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorFeature.java create mode 100644 platform/platform-impl/src/com/intellij/ui/OneLineEditorFeature.java create mode 100644 platform/platform-impl/src/com/intellij/ui/RightMarginEditorCustomization.java create mode 100644 platform/platform-impl/src/com/intellij/ui/RightMarginEditorFeature.java create mode 100644 platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorFeature.java create mode 100644 platform/platform-impl/src/com/intellij/ui/SpellCheckingEditorFeature.java diff --git a/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java b/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java index 78a23cb38248..32d35da3ae0d 100644 --- a/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java @@ -75,40 +75,15 @@ public class EditorTextFieldProviderImpl implements EditorTextFieldProvider { @Override public EditorTextField getEditorField(@NotNull Language language, @NotNull Project project, - @NotNull final Iterable enabledFeatures, - @NotNull final Iterable disabledFeatures) { + @NotNull final Iterable features) { return new MyEditorTextField(language, project) { @Override protected void applyFeatures(@NotNull EditorCustomization[] customizations, @NotNull EditorEx editor) { - for (EditorCustomization.Feature feature : enabledFeatures) { + for (EditorFeature feature : features) { for (EditorCustomization customization : customizations) { - if (customization.getSupportedFeatures().contains(feature)) { - customization.addCustomization(editor, feature); - break; - } + customization.doProcessCustomization(editor, feature); } } - for (EditorCustomization.Feature feature : disabledFeatures) { - for (EditorCustomization customization : customizations) { - if (customization.getSupportedFeatures().contains(feature)) { - customization.removeCustomization(editor, feature); - break; - } - } - } - } - }; - } - - @NotNull - @Override - public EditorTextField getEditorField(@NotNull Language language, - @NotNull Project project, - @NotNull final AdHocEditorCustomizer customization) { - return new MyEditorTextField(language, project) { - @Override - protected void applyFeatures(@NotNull EditorCustomization[] customizations, @NotNull EditorEx editor) { - customization.customize(editor); } }; } diff --git a/platform/platform-impl/src/com/intellij/ui/AbstractEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/AbstractEditorCustomization.java deleted file mode 100644 index 1a477e8e7406..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/AbstractEditorCustomization.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2000-2011 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.ui; - -import com.intellij.openapi.editor.ex.EditorEx; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.Set; - -/** - * Base super class for {@link EditorCustomization editor customizations} that provide the following: - *
- * 
    - *
  • - * Don't process {@link #addCustomization(EditorEx, Feature)} and {@link #removeCustomization(EditorEx, Feature)} if given feature - * is not supported by the current customization (supported features are defined at constructor); - *
  • - *
- *
- * - * @author Denis Zhdanov - * @since 1/24/11 3:56 PM - */ -public abstract class AbstractEditorCustomization implements EditorCustomization { - - private final Set myFeatures = EnumSet.noneOf(Feature.class); - - protected AbstractEditorCustomization(@NotNull Feature... features) { - myFeatures.addAll(Arrays.asList(features)); - } - - @Override - public Set getSupportedFeatures() { - return myFeatures; - } - - @Override - public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { - if (!myFeatures.contains(feature)) { - return; - } - doProcessCustomization(editor, feature, true); - } - - @Override - public void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { - if (!myFeatures.contains(feature)) { - return; - } - doProcessCustomization(editor, feature, false); - } - - /** - * Template method for sub-classes to process target feature applying/removal and being sure that given feature - * is supported by the current customization. - * - * @param editor target editor to apply the given feature - * @param feature target feature to apply to the given editor - * @param apply flag the identifies if given feature should be applied/removed from the given editor - */ - protected abstract void doProcessCustomization(@NotNull EditorEx editor, @NotNull Feature feature, boolean apply); -} diff --git a/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorCustomization.java index c4c8abce75ac..aca064b21358 100644 --- a/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorCustomization.java @@ -19,19 +19,18 @@ import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; /** - * {@link EditorCustomization} for {@link EditorCustomization.Feature#ADDITIONAL_PAGE_AT_BOTTOM}. - * * @author Denis Zhdanov * @since 1/21/11 4:06 PM */ -public class AdditionalPageAtBottomEditorCustomization extends AbstractEditorCustomization { +public class AdditionalPageAtBottomEditorCustomization extends EditorCustomization { - public AdditionalPageAtBottomEditorCustomization() { - super(Feature.ADDITIONAL_PAGE_AT_BOTTOM); + @Override + protected Class getFeatureClass() { + return AdditionalPageAtBottomEditorFeature.class; } @Override - protected void doProcessCustomization(@NotNull EditorEx editor, @NotNull Feature feature, boolean apply) { - editor.getSettings().setAdditionalPageAtBottom(apply); + protected void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + editor.getSettings().setAdditionalPageAtBottom(feature.isEnabled()); } } diff --git a/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorFeature.java b/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorFeature.java new file mode 100644 index 000000000000..197659f64014 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/AdditionalPageAtBottomEditorFeature.java @@ -0,0 +1,7 @@ +package com.intellij.ui; + +public class AdditionalPageAtBottomEditorFeature extends EditorFeature { + public AdditionalPageAtBottomEditorFeature(boolean enabled) { + super(enabled); + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java index f32e63af091f..70301c76ebfb 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java @@ -19,43 +19,51 @@ import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.extensions.ExtensionPointName; import org.jetbrains.annotations.NotNull; -import java.util.Set; - /** * Defines contract for functionality that is able to customize editors. *

- * It's assumed that it works in terms of {@link Feature features} that can be applied to editors, i.e. every - * customization implementation is assumed to be able to provide support for [1; *] features. + * It's assumed that it works in terms of {@link EditorFeature features} that can be applied to editors, i.e. every + * customization implementation is assumed to have a corresponding {@link EditorFeature} implementation which + * enables/disables it and potentially provides some configuration. This indirection allows us to have customizer + * extensions provided by other modules (see {@link SpellCheckingEditorFeature} for example) * * @author Denis Zhdanov * @since Aug 20, 2010 4:26:04 PM */ -public interface EditorCustomization { +public abstract class EditorCustomization { - enum Feature { - SOFT_WRAP, SPELL_CHECK, HORIZONTAL_SCROLLBAR, ONE_LINE, ADDITIONAL_PAGE_AT_BOTTOM + public static ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.editorCustomization"); + + /** + * Apply the given feature to the given editor. + * + * Validates the given {@link EditorFeature} configures this customization, and hence can safely be + * called on all {@link EditorCustomization} extension points for any {@link EditorFeature} + * + * @param editor The editor to customize + * @param feature The feature configuration + */ + public void doProcessCustomization(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + if (!getFeatureClass().isAssignableFrom(feature.getClass())) { + return; + } + + customize(editor, feature); } - ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.editorCustomization"); - /** - * @return set of editor customization features supported by the current class - */ - Set getSupportedFeatures(); - - /** - * Asks to perform customization of the given editor for the given feature. + * All subclass must declare an {@link EditorFeature} class which configures them. * - * @param editor editor to customize - * @param feature feature to apply to the given editor + * @return The {@link EditorFeature} class which corresponds to this {@link EditorCustomization} */ - void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature); + protected abstract Class getFeatureClass(); /** - * Asks to un-apply customization performed earlier during {@link #addCustomization(EditorEx, Feature)} processing (if any). - * - * @param editor editor to customize - * @param feature feature to un-apply to the given editor + * Subclasses should apply their customizations in this method. Parameter "feature" is + * guaranteed by {@link #doProcessCustomization} to match the type returned by {@link #getFeatureClass} + * + * @param editor The editor to customize + * @param feature The feature configuration */ - void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature); + protected abstract void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature); } diff --git a/platform/platform-impl/src/com/intellij/ui/EditorFeature.java b/platform/platform-impl/src/com/intellij/ui/EditorFeature.java new file mode 100644 index 000000000000..895fc60fafdf --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/EditorFeature.java @@ -0,0 +1,16 @@ +package com.intellij.ui; + +/** + * Base class for editor feature configurations used by {@link EditorCustomization} + */ +public abstract class EditorFeature { + private boolean myEnabled; + + public EditorFeature(boolean enabled) { + myEnabled = enabled; + } + + public boolean isEnabled() { + return myEnabled; + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldProvider.java b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldProvider.java index 9703326767ad..ce207f615e6c 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldProvider.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldProvider.java @@ -16,7 +16,6 @@ package com.intellij.ui; import com.intellij.lang.Language; -import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; @@ -29,36 +28,16 @@ import org.jetbrains.annotations.NotNull; public interface EditorTextFieldProvider { /** - * It's possible either {@link EditorCustomization#addCustomization(EditorEx, EditorCustomization.Feature) apply} or - * {@link EditorCustomization#removeCustomization(EditorEx, EditorCustomization.Feature) remove} customizations from - * editor. This factory method allows to create editor where some customizations are explicitly enabled and - * another customizations are explicitly disabled. - * - * @param language target language used by document that will be displayed by returned editor - * @param project target project - * @param enabledFeatures explicitly enabled features for returned editor - * @param disabledFeatures explicitly disabled features for returned editor + * This factory method allows creation of an editor where some customizations are explicitly enabled and + * other customizations are explicitly disabled using the given {@link EditorFeature} objects. + * + * @param language target language used by document that will be displayed by returned editor + * @param project target project + * @param features {@link EditorFeature} objects which explicitly enable (and possibly configure) or disable features * @return */ @NotNull EditorTextField getEditorField(@NotNull Language language, @NotNull Project project, - @NotNull Iterable enabledFeatures, - @NotNull Iterable disabledFeatures); + @NotNull Iterable features); - /** - * Alternative to {@link #getEditorField(com.intellij.lang.Language, com.intellij.openapi.project.Project, Iterable, Iterable)} which - * allows you to define arbitrary customizations by implementing an {@link AdHocEditorCustomizer}. - * - * @param language target language used by document that will be displayed by returned editor - * @param project target project - * @param customization implementation of {@link AdHocEditorCustomizer} which will be called at editor creation - * - */ - @NotNull - EditorTextField getEditorField(@NotNull Language language, @NotNull Project project, - @NotNull AdHocEditorCustomizer customization); - - interface AdHocEditorCustomizer { - void customize(EditorEx editor); - } } diff --git a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java index e9654ccc96c1..41a90cf933af 100644 --- a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java @@ -23,14 +23,15 @@ import org.jetbrains.annotations.NotNull; * Date: 12/6/10 * Time: 10:18 AM */ -public class HorizontalScrollBarEditorCustomization extends AbstractEditorCustomization { +public class HorizontalScrollBarEditorCustomization extends EditorCustomization { - public HorizontalScrollBarEditorCustomization() { - super(Feature.HORIZONTAL_SCROLLBAR); + @Override + protected Class getFeatureClass() { + return HorizontalScrollBarEditorFeature.class; } @Override - protected void doProcessCustomization(@NotNull EditorEx editor, @NotNull Feature feature, boolean apply) { - editor.setHorizontalScrollbarVisible(apply); + protected void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + editor.setHorizontalScrollbarVisible(feature.isEnabled()); } } diff --git a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorFeature.java b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorFeature.java new file mode 100644 index 000000000000..0cf6db179326 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorFeature.java @@ -0,0 +1,7 @@ +package com.intellij.ui; + +public class HorizontalScrollBarEditorFeature extends EditorFeature { + public HorizontalScrollBarEditorFeature(boolean enabled) { + super(enabled); + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java index 4d35f07a5993..b6a03f05dde9 100644 --- a/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java @@ -21,14 +21,15 @@ import org.jetbrains.annotations.NotNull; /** * @author Kirill Likhodedov */ -public class OneLineEditorCustomization extends AbstractEditorCustomization { +public class OneLineEditorCustomization extends EditorCustomization { - public OneLineEditorCustomization() { - super(Feature.ONE_LINE); + @Override + protected Class getFeatureClass() { + return OneLineEditorFeature.class; } @Override - protected void doProcessCustomization(@NotNull EditorEx editor, @NotNull Feature feature, boolean apply) { - editor.setOneLineMode(apply); + protected void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + editor.setOneLineMode(feature.isEnabled()); } } diff --git a/platform/platform-impl/src/com/intellij/ui/OneLineEditorFeature.java b/platform/platform-impl/src/com/intellij/ui/OneLineEditorFeature.java new file mode 100644 index 000000000000..84666b0311ea --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/OneLineEditorFeature.java @@ -0,0 +1,7 @@ +package com.intellij.ui; + +public class OneLineEditorFeature extends EditorFeature { + public OneLineEditorFeature(boolean enabled) { + super(enabled); + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/RightMarginEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/RightMarginEditorCustomization.java new file mode 100644 index 000000000000..d66cc19112bb --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/RightMarginEditorCustomization.java @@ -0,0 +1,31 @@ +package com.intellij.ui; + +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.ex.EditorEx; +import org.jetbrains.annotations.NotNull; + +public class RightMarginEditorCustomization extends EditorCustomization { + + @Override + protected Class getFeatureClass() { + return RightMarginEditorFeature.class; + } + + @Override + protected void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + if (!(feature instanceof RightMarginEditorFeature)) { + return; + } + + RightMarginEditorFeature rightMarginEditorFeature = (RightMarginEditorFeature)feature; + + if (rightMarginEditorFeature.isEnabled()) { + editor.getSettings().setRightMarginShown(true); + editor.getSettings().setRightMargin(rightMarginEditorFeature.getRightMarginColumns()); + // ensure we've got a monospace font by loading up the global editor scheme + editor.setColorsScheme(EditorColorsManager.getInstance().getGlobalScheme()); + } else { + editor.getSettings().setRightMarginShown(false); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/RightMarginEditorFeature.java b/platform/platform-impl/src/com/intellij/ui/RightMarginEditorFeature.java new file mode 100644 index 000000000000..dd858fa3d4e5 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/RightMarginEditorFeature.java @@ -0,0 +1,14 @@ +package com.intellij.ui; + +public class RightMarginEditorFeature extends EditorFeature { + private int myRightMarginColumns; + + public RightMarginEditorFeature(boolean enabled, int rightMarginColumns) { + super(enabled); + myRightMarginColumns = rightMarginColumns; + } + + public int getRightMarginColumns() { + return myRightMarginColumns; + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java index 0c36b4d4dc5c..fbdd8705c076 100644 --- a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java @@ -26,14 +26,15 @@ import org.jetbrains.annotations.NotNull; * @author Denis Zhdanov * @since Aug 20, 2010 4:54:48 PM */ -public class SoftWrapsEditorCustomization extends AbstractEditorCustomization { +public class SoftWrapsEditorCustomization extends EditorCustomization { - public SoftWrapsEditorCustomization() { - super(Feature.SOFT_WRAP); + @Override + protected Class getFeatureClass() { + return SoftWrapsEditorFeature.class; } @Override - protected void doProcessCustomization(@NotNull EditorEx editor, @NotNull Feature feature, boolean apply) { - editor.getSettings().setUseSoftWraps(apply); + protected void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + editor.getSettings().setUseSoftWraps(feature.isEnabled()); } } diff --git a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorFeature.java b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorFeature.java new file mode 100644 index 000000000000..17a7882d5451 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorFeature.java @@ -0,0 +1,7 @@ +package com.intellij.ui; + +public class SoftWrapsEditorFeature extends EditorFeature { + public SoftWrapsEditorFeature(boolean enabled) { + super(enabled); + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/SpellCheckingEditorFeature.java b/platform/platform-impl/src/com/intellij/ui/SpellCheckingEditorFeature.java new file mode 100644 index 000000000000..34241c109330 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/SpellCheckingEditorFeature.java @@ -0,0 +1,7 @@ +package com.intellij.ui; + +public class SpellCheckingEditorFeature extends EditorFeature { + public SpellCheckingEditorFeature(boolean enabled) { + super(enabled); + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 906fa68fe0ac..f1a9929a8f28 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -580,6 +580,8 @@ + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java index 08bf1f474e26..6fe40d7205cb 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java @@ -25,14 +25,13 @@ import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.ui.EditorCustomization; -import com.intellij.ui.EditorTextField; -import com.intellij.ui.EditorTextFieldProvider; +import com.intellij.ui.*; import com.intellij.util.Consumer; import javax.swing.*; import java.awt.*; -import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; public abstract class NewEditChangelistPanel extends JPanel { private EditorTextField myNameTextField; @@ -162,15 +161,17 @@ public abstract class NewEditChangelistPanel extends JPanel { private static EditorTextField createEditorField(final Project project, final int defaultLines) { final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); final EditorTextField editorField; - final EnumSet enabledFeatures = EnumSet.of(EditorCustomization.Feature.SPELL_CHECK); - final EnumSet disabledFeatures = EnumSet.noneOf(EditorCustomization.Feature.class); + + final Set editorFeatures = new HashSet(); + editorFeatures.add(new SpellCheckingEditorFeature(true)); + if (defaultLines == 1) { - disabledFeatures.add(EditorCustomization.Feature.HORIZONTAL_SCROLLBAR); - enabledFeatures.add(EditorCustomization.Feature.ONE_LINE); + editorFeatures.add(new HorizontalScrollBarEditorFeature(false)); + editorFeatures.add(new OneLineEditorFeature(true)); } else { - enabledFeatures.add(EditorCustomization.Feature.SOFT_WRAP); + editorFeatures.add(new SoftWrapsEditorFeature(true)); } - editorField = service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, enabledFeatures, disabledFeatures); + editorField = service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, editorFeatures); final int height = editorField.getFontMetrics(editorField.getFont()).getHeight(); editorField.getComponent().setMinimumSize(new Dimension(100, (int)(height * 1.3))); return editorField; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java index 100d3aa73ff9..7c1a09f6cff3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java @@ -20,7 +20,6 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileTypes; @@ -33,6 +32,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.HashSet; +import java.util.Set; public class CommitMessage extends AbstractDataProviderPanel implements Disposable, CommitMessageI { @@ -114,37 +115,19 @@ public class CommitMessage extends AbstractDataProviderPanel implements Disposab * @return a commit message editor */ public static EditorTextField createCommitTextEditor(final Project project, boolean forceSpellCheckOn) { - final boolean checkSpelling; - final boolean useCommitMessageMargin; - final int commitMessageMarginSize; + Set features = new HashSet(); VcsConfiguration configuration = VcsConfiguration.getInstance(project); - if (configuration != null) { - checkSpelling = forceSpellCheckOn || configuration.CHECK_COMMIT_MESSAGE_SPELLING; - useCommitMessageMargin = configuration.USE_COMMIT_MESSAGE_MARGIN; - commitMessageMarginSize = configuration.COMMIT_MESSAGE_MARGIN_SIZE; + features.add(new SpellCheckingEditorFeature(forceSpellCheckOn || configuration.CHECK_COMMIT_MESSAGE_SPELLING)); + features.add(new RightMarginEditorFeature(configuration.USE_COMMIT_MESSAGE_MARGIN, configuration.COMMIT_MESSAGE_MARGIN_SIZE)); } else { - checkSpelling = true; - useCommitMessageMargin = false; - commitMessageMarginSize = -1; + features.add(new SpellCheckingEditorFeature(true)); + features.add(new RightMarginEditorFeature(false, -1)); } EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); - return service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), - project, - new EditorTextFieldProvider.AdHocEditorCustomizer() { - @Override - public void customize(EditorEx editor) { - toggleEditorSpellchecking(project, editor, checkSpelling); - - if (useCommitMessageMargin) { - editor.setColorsScheme(EditorColorsManager.getInstance().getGlobalScheme()); - editor.getSettings().setRightMarginShown(true); - editor.getSettings().setRightMargin(commitMessageMarginSize); - } - } - }); + return service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, features); } @Nullable @@ -195,16 +178,10 @@ public class CommitMessage extends AbstractDataProviderPanel implements Disposab private static void toggleEditorSpellchecking(Project project, EditorEx editorEx, boolean spellCheckingEnabled) { EditorCustomization[] customizations = Extensions.getExtensions(EditorCustomization.EP_NAME, project); - EditorCustomization.Feature spellCheckFeature = EditorCustomization.Feature.SPELL_CHECK; + SpellCheckingEditorFeature spellCheckFeature = new SpellCheckingEditorFeature(spellCheckingEnabled); + for (EditorCustomization customization : customizations) { - if (customization.getSupportedFeatures().contains(spellCheckFeature)) { - if (spellCheckingEnabled) { - customization.addCustomization(editorEx, spellCheckFeature); - } - else { - customization.removeCustomization(editorEx, spellCheckFeature); - } - } + customization.doProcessCustomization(editorEx, spellCheckFeature); } } diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/UsersFilterAction.java b/plugins/git4idea/src/git4idea/history/wholeTree/UsersFilterAction.java index f4c5ae0192bd..54ee8814c69b 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/UsersFilterAction.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/UsersFilterAction.java @@ -30,9 +30,7 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.ui.EditorCustomization; -import com.intellij.ui.EditorTextField; -import com.intellij.ui.EditorTextFieldProvider; +import com.intellij.ui.*; import com.intellij.util.Consumer; import com.intellij.util.TextFieldCompletionProvider; import com.intellij.util.TextFieldCompletionProviderDumbAware; @@ -42,8 +40,9 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.CompoundBorder; import java.awt.*; -import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @author irengrig @@ -169,9 +168,10 @@ public class UsersFilterAction extends BasePopupAction { private void createPopup(Project project) { final JPanel panel = new JPanel(new BorderLayout()); final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); - myEditorField = service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, - Collections.singletonList(EditorCustomization.Feature.SOFT_WRAP), - Collections.singletonList(EditorCustomization.Feature.SPELL_CHECK)); + Set features = new HashSet(); + features.add(new SoftWrapsEditorFeature(true)); + features.add(new SpellCheckingEditorFeature(false)); + myEditorField = service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, features); myEditorField.setBorder(new CompoundBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), myEditorField.getBorder())); myEditorField.setText("s"); myEditorField.setText(myCurrentText); diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java b/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java index 35375384a41e..359140506681 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java @@ -27,7 +27,9 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.spellchecker.inspections.SpellCheckingInspection; -import com.intellij.ui.AbstractEditorCustomization; +import com.intellij.ui.EditorCustomization; +import com.intellij.ui.EditorFeature; +import com.intellij.ui.SpellCheckingEditorFeature; import com.intellij.util.Function; import com.intellij.util.containers.WeakHashMap; import gnu.trove.THashSet; @@ -44,11 +46,16 @@ import java.util.*; * @author Denis Zhdanov * @since Aug 20, 2010 3:54:42 PM */ -public class SpellCheckingEditorCustomization extends AbstractEditorCustomization { +public class SpellCheckingEditorCustomization extends EditorCustomization { private static final Set SPELL_CHECK_TOOLS = new HashSet(); private static final boolean READY = init(); - + + @Override + protected Class getFeatureClass() { + return SpellCheckingEditorFeature.class; + } + @SuppressWarnings({"unchecked"}) private static boolean init() { // It's assumed that default spell checking inspection settings are just fine for processing all types of data. @@ -66,13 +73,11 @@ public class SpellCheckingEditorCustomization extends AbstractEditorCustomizatio } return true; } - - public SpellCheckingEditorCustomization() { - super(Feature.SPELL_CHECK); - } @Override - protected void doProcessCustomization(@NotNull EditorEx editor, @NotNull Feature feature, boolean apply) { + protected void customize(@NotNull EditorEx editor, @NotNull EditorFeature feature) { + boolean apply = feature.isEnabled(); + if (!READY) { return; }