diff --git a/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java b/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java index 95b03534e709..2120756100e0 100644 --- a/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java @@ -89,7 +89,7 @@ public class EditorTextFieldProviderImpl implements EditorTextFieldProvider { for (EditorCustomization.Feature feature : features) { for (EditorCustomization customization : customizations) { if (customization.getSupportedFeatures().contains(feature)) { - customization.customize(ex, feature); + customization.addCustomization(ex, feature); break; } } diff --git a/platform/platform-impl/src/com/intellij/AbstractUnappliableEditorCustomization.java b/platform/platform-impl/src/com/intellij/AbstractUnappliableEditorCustomization.java new file mode 100644 index 000000000000..65348be2e58f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/AbstractUnappliableEditorCustomization.java @@ -0,0 +1,34 @@ +/* + * 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; + +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.ui.EditorCustomization; +import org.jetbrains.annotations.NotNull; + +/** + * Basic super class for {@link EditorCustomization editor customizations} that don't consider un-applying feature. + * + * @author Denis Zhdanov + * @since 1/14/11 12:52 PM + */ +public abstract class AbstractUnappliableEditorCustomization implements EditorCustomization { + + @Override + public void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { + // Do nothing + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java index 24b2f3479de0..9741d70fe058 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java @@ -49,5 +49,13 @@ public interface EditorCustomization { * @param editor editor to customize * @param feature feature to apply to the given editor */ - void customize(@NotNull EditorEx editor, @NotNull Feature feature); + void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature); + + /** + * 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 + */ + void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature); } diff --git a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java index 9150bedb6668..9f9e84b94d33 100644 --- a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.AbstractUnappliableEditorCustomization; import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; @@ -26,12 +27,12 @@ import java.util.Set; * Date: 12/6/10 * Time: 10:18 AM */ -public class HorizontalScrollBarEditorCustomization implements EditorCustomization { +public class HorizontalScrollBarEditorCustomization extends AbstractUnappliableEditorCustomization { public Set getSupportedFeatures() { return EnumSet.of(Feature.NO_HORIZONTAL_SCROLLBAR); } - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { if (Feature.NO_HORIZONTAL_SCROLLBAR.equals(feature)) { editor.setHorizontalScrollbarVisible(false); } diff --git a/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java index ab4d16161049..df719184a920 100644 --- a/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.AbstractUnappliableEditorCustomization; import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; @@ -24,12 +25,12 @@ import java.util.Set; /** * @author Kirill Likhodedov */ -public class OneLineEditorCustomization implements EditorCustomization { +public class OneLineEditorCustomization extends AbstractUnappliableEditorCustomization { public Set getSupportedFeatures() { return EnumSet.of(Feature.ONE_LINE); } - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { if (Feature.ONE_LINE.equals(feature)) { editor.setOneLineMode(true); } diff --git a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java index 60ec41f4c7d0..83d69140e5ad 100644 --- a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.AbstractUnappliableEditorCustomization; import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; @@ -29,7 +30,7 @@ import java.util.Set; * @author Denis Zhdanov * @since Aug 20, 2010 4:54:48 PM */ -public class SoftWrapsEditorCustomization implements EditorCustomization { +public class SoftWrapsEditorCustomization extends AbstractUnappliableEditorCustomization { @Override public Set getSupportedFeatures() { @@ -37,7 +38,7 @@ public class SoftWrapsEditorCustomization implements EditorCustomization { } @Override - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { editor.getSettings().setUseSoftWraps(true); } } diff --git a/platform/platform-resources-en/src/messages/VcsBundle.properties b/platform/platform-resources-en/src/messages/VcsBundle.properties index 3b33cf95cdf6..a6d3e11aba3b 100644 --- a/platform/platform-resources-en/src/messages/VcsBundle.properties +++ b/platform/platform-resources-en/src/messages/VcsBundle.properties @@ -34,6 +34,7 @@ border.standard.after.checkin.options.group=After {0} checkbox.checkin.options.check.files.up.to.date=Check remote status checkbox.checkin.options.optimize.imports=&Optimize imports checkbox.checkin.options.reformat.code=&Reformat code +checkbox.check.commit.message.spelling=Check commit message spelling progress.text.searching.for.modified.files=Searching for modified files button.text.overwrite.modified.file=&Overwrite Modified File button.text.overwrite.modified.files=&Overwrite Modified Files diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java index b77a064b3e33..aa6c1bee2f41 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java @@ -69,6 +69,7 @@ public final class VcsConfiguration implements PersistentStateComponent public boolean ENABLE_BACKGROUND_PROCESSES = false; public int CHANGED_ON_SERVER_INTERVAL = 60; public boolean SHOW_ONLY_CHANGED_IN_SELECTION_DIFF = true; + public boolean CHECK_COMMIT_MESSAGE_SPELLING = true; public enum StandardOption { ADD(VcsBundle.message("vcs.command.name.add")), diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index efe87f0fcc11..5a5e64283010 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -38,7 +38,6 @@ import com.intellij.openapi.vcs.checkin.*; import com.intellij.openapi.vcs.ui.CommitMessage; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.EditorTextField; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.SeparatorFactory; import com.intellij.util.Alarm; @@ -49,6 +48,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.io.File; import java.util.*; import java.util.List; @@ -94,6 +95,8 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj private final PseudoMap myAdditionalData; private String myHelpId; + + private final JCheckBox myCheckSpellingBox; private static class MyUpdateButtonsRunnable implements Runnable { private CommitChangeListDialog myDialog; @@ -261,6 +264,23 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj } } + myCheckSpellingBox = new JCheckBox(VcsBundle.message("checkbox.check.commit.message.spelling")); + myCheckSpellingBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); + boolean checkSpelling = e.getStateChange() == ItemEvent.SELECTED; + if (configuration != null) { + configuration.CHECK_COMMIT_MESSAGE_SPELLING = checkSpelling; + } + myCommitMessageArea.setCheckSpelling(checkSpelling); + } + }); + VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); + if (configuration != null) { + myCheckSpellingBox.setSelected(configuration.CHECK_COMMIT_MESSAGE_SPELLING); + } + myActionName = VcsBundle.message("commit.dialog.title"); myAdditionalOptionsPanel = new JPanel(); @@ -767,7 +787,10 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj JPanel infoPanel = new JPanel(new BorderLayout()); myChangesInfoCalculator = new CommitLegendPanel.ChangeInfoCalculator(); myLegend = new CommitLegendPanel(myChangesInfoCalculator); - infoPanel.add(myLegend.getComponent(), BorderLayout.NORTH); + JPanel commonPanel = new JPanel(new BorderLayout()); + commonPanel.add(myLegend.getComponent()); + commonPanel.add(myCheckSpellingBox, BorderLayout.SOUTH); + infoPanel.add(commonPanel, BorderLayout.NORTH); infoPanel.add(myAdditionalOptionsPanel, BorderLayout.CENTER); rootPane.add(infoPanel, BorderLayout.EAST); infoPanel.setBorder(IdeBorderFactory.createEmptyBorder(0, 10, 0, 0)); 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 ac4f6e9ee8eb..30d5cc60444c 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 @@ -21,9 +21,13 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.ActionToolbar; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.ui.EditorCustomization; import com.intellij.ui.EditorTextField; import com.intellij.ui.EditorTextFieldProvider; @@ -32,14 +36,23 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.EnumSet; +import java.util.Set; public class CommitMessage extends JPanel implements Disposable { private final EditorTextField myEditorField; + private final Project myProject; public CommitMessage(Project project) { super(new BorderLayout()); - myEditorField = createEditorField(project); + boolean checkSpelling = true; + VcsConfiguration configuration = VcsConfiguration.getInstance(project); + if (configuration != null) { + checkSpelling = configuration.CHECK_COMMIT_MESSAGE_SPELLING; + } + myEditorField = createEditorField(project, checkSpelling); + myProject = project; // Note that we assume here that editor used for commit message processing uses font family implied by LAF (in contrast, // IJ code editor uses monospaced font). Hence, we don't need any special actions here @@ -64,10 +77,14 @@ public class CommitMessage extends JPanel implements Disposable { setBorder(BorderFactory.createEmptyBorder()); } - private static EditorTextField createEditorField(final Project project) { + private static EditorTextField createEditorField(final Project project, final boolean checkSpelling) { EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); + Set features = EnumSet.of(EditorCustomization.Feature.SOFT_WRAP); + if (checkSpelling) { + features.add(EditorCustomization.Feature.SPELL_CHECK); + } return service.getEditorField( - FileTypes.PLAIN_TEXT.getLanguage(), project, EditorCustomization.Feature.SOFT_WRAP, EditorCustomization.Feature.SPELL_CHECK + FileTypes.PLAIN_TEXT.getLanguage(), project, features.toArray(new EditorCustomization.Feature[features.size()]) ); } @@ -98,6 +115,26 @@ public class CommitMessage extends JPanel implements Disposable { myEditorField.selectAll(); } + public void setCheckSpelling(boolean check) { + Editor editor = myEditorField.getEditor(); + if (!(editor instanceof EditorEx)) { + return; + } + EditorEx editorEx = (EditorEx)editor; + EditorCustomization[] customizations = Extensions.getExtensions(EditorCustomization.EP_NAME, myProject); + EditorCustomization.Feature feature = EditorCustomization.Feature.SPELL_CHECK; + for (EditorCustomization customization : customizations) { + if (customization.getSupportedFeatures().contains(feature)) { + if (check) { + customization.addCustomization(editorEx, feature); + } + else { + customization.removeCustomization(editorEx, feature); + } + } + } + } + public void dispose() { } } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java b/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java index c455a7977b79..8d009ed94c43 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java @@ -16,6 +16,7 @@ package com.intellij.spellchecker.ui; import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.intention.IntentionManager; import com.intellij.codeInspection.InspectionProfile; @@ -120,7 +121,7 @@ public class SpellCheckingEditorCustomization implements EditorCustomization { } @Override - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { if (INSPECTION_PROFILE_WRAPPER == null) { return; } @@ -136,5 +137,28 @@ public class SpellCheckingEditorCustomization implements EditorCustomization { } file.putUserData(InspectionProfileWrapper.KEY, INSPECTION_PROFILE_WRAPPER); editor.putUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY, false); + updateRepresentation(project, file); + } + + @Override + public void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { + Project project = editor.getProject(); + if (project == null) { + return; + } + + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); + if (file == null) { + return; + } + file.putUserData(InspectionProfileWrapper.KEY, null); + updateRepresentation(project, file); + } + + private static void updateRepresentation(@NotNull Project project, @NotNull PsiFile file) { + DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(project); + if (analyzer != null) { + analyzer.restart(file); + } } }