mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-63770 Missing a way to turn spellchecker off for commit text field.
1. Editor customizations API is changed in a way to allow feature deactivation; 2. Added support for spell checking customization deactivation; 3. Commit dialog allows to toggle commit message spell checking;
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+3
-2
@@ -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<Feature> 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);
|
||||
}
|
||||
|
||||
@@ -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<Feature> 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);
|
||||
}
|
||||
|
||||
@@ -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<Feature> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -69,6 +69,7 @@ public final class VcsConfiguration implements PersistentStateComponent<Element>
|
||||
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")),
|
||||
|
||||
+25
-2
@@ -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<Object, Object> 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));
|
||||
|
||||
@@ -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<EditorCustomization.Feature> 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() {
|
||||
}
|
||||
}
|
||||
|
||||
+25
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user