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"
This commit is contained in:
Daniel Marcotte
2013-02-14 19:04:50 +04:00
committed by Kirill Likhodedov
parent 4cfa1a3e0e
commit 0dc2c3aa1d
21 changed files with 205 additions and 237 deletions
@@ -75,40 +75,15 @@ public class EditorTextFieldProviderImpl implements EditorTextFieldProvider {
@Override
public EditorTextField getEditorField(@NotNull Language language,
@NotNull Project project,
@NotNull final Iterable<EditorCustomization.Feature> enabledFeatures,
@NotNull final Iterable<EditorCustomization.Feature> disabledFeatures) {
@NotNull final Iterable<EditorFeature> 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);
}
};
}
@@ -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:
* <pre>
* <ul>
* <li>
* 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);
* </li>
* </ul>
* </pre>
*
* @author Denis Zhdanov
* @since 1/24/11 3:56 PM
*/
public abstract class AbstractEditorCustomization implements EditorCustomization {
private final Set<Feature> myFeatures = EnumSet.noneOf(Feature.class);
protected AbstractEditorCustomization(@NotNull Feature... features) {
myFeatures.addAll(Arrays.asList(features));
}
@Override
public Set<Feature> 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);
}
@@ -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<? extends EditorFeature> 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());
}
}
@@ -0,0 +1,7 @@
package com.intellij.ui;
public class AdditionalPageAtBottomEditorFeature extends EditorFeature {
public AdditionalPageAtBottomEditorFeature(boolean enabled) {
super(enabled);
}
}
@@ -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.
* <p/>
* 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 <code>[1; *]</code> 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<EditorCustomization> 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<EditorCustomization> EP_NAME = ExtensionPointName.create("com.intellij.editorCustomization");
/**
* @return set of editor customization features supported by the current class
*/
Set<Feature> 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<? extends EditorFeature> 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);
}
@@ -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;
}
}
@@ -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<EditorCustomization.Feature> enabledFeatures,
@NotNull Iterable<EditorCustomization.Feature> disabledFeatures);
@NotNull Iterable<EditorFeature> 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);
}
}
@@ -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<? extends EditorFeature> 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());
}
}
@@ -0,0 +1,7 @@
package com.intellij.ui;
public class HorizontalScrollBarEditorFeature extends EditorFeature {
public HorizontalScrollBarEditorFeature(boolean enabled) {
super(enabled);
}
}
@@ -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<? extends EditorFeature> 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());
}
}
@@ -0,0 +1,7 @@
package com.intellij.ui;
public class OneLineEditorFeature extends EditorFeature {
public OneLineEditorFeature(boolean enabled) {
super(enabled);
}
}
@@ -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<? extends EditorFeature> 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);
}
}
}
@@ -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;
}
}
@@ -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<? extends EditorFeature> 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());
}
}
@@ -0,0 +1,7 @@
package com.intellij.ui;
public class SoftWrapsEditorFeature extends EditorFeature {
public SoftWrapsEditorFeature(boolean enabled) {
super(enabled);
}
}
@@ -0,0 +1,7 @@
package com.intellij.ui;
public class SpellCheckingEditorFeature extends EditorFeature {
public SpellCheckingEditorFeature(boolean enabled) {
super(enabled);
}
}
@@ -580,6 +580,8 @@
<editorCustomization implementation="com.intellij.ui.HorizontalScrollBarEditorCustomization"/>
<editorCustomization implementation="com.intellij.ui.AdditionalPageAtBottomEditorCustomization"/>
<editorCustomization implementation="com.intellij.ui.OneLineEditorCustomization"/>
<editorCustomization implementation="com.intellij.ui.RightMarginEditorCustomization"/>
<!-- Colors & Fonts-->
<editorOptionsProvider instance="com.intellij.application.options.colors.ColorAndFontOptions"
id="reference.settingsdialog.IDE.editor.colors"/>
@@ -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<EditorCustomization.Feature> enabledFeatures = EnumSet.of(EditorCustomization.Feature.SPELL_CHECK);
final EnumSet<EditorCustomization.Feature> disabledFeatures = EnumSet.noneOf(EditorCustomization.Feature.class);
final Set<EditorFeature> editorFeatures = new HashSet<EditorFeature>();
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;
@@ -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<EditorFeature> features = new HashSet<EditorFeature>();
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);
}
}
@@ -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<EditorFeature> features = new HashSet<EditorFeature>();
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);
@@ -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<LocalInspectionToolWrapper> SPELL_CHECK_TOOLS = new HashSet<LocalInspectionToolWrapper>();
private static final boolean READY = init();
@Override
protected Class<? extends EditorFeature> 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;
}