mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs] optionally wrap in commit dialog when text reaches right margin
IDEA-53615 * Add a checkbox to the Settings | Version Control. Keep the VcsCheckBoxWithSpinnerConfigurable structure by having it as a sub-configurable. * Add an option to the VcsConfiguration. * Add a simple editor customization and pass through the hard wrap option setter to EditorSettings & SettingsImpl.
This commit is contained in:
@@ -28,6 +28,7 @@ public interface EditorSettings {
|
||||
void setRightMargin(int myRightMargin);
|
||||
|
||||
boolean isWrapWhenTypingReachesRightMargin(Project project);
|
||||
void setWrapWhenTypingReachesRightMargin(boolean val);
|
||||
|
||||
boolean isLineNumbersShown();
|
||||
void setLineNumbersShown(boolean val);
|
||||
@@ -114,5 +115,5 @@ public interface EditorSettings {
|
||||
|
||||
boolean isPreselectRename();
|
||||
void setPreselectRename(final boolean val);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class SettingsImpl implements EditorSettings {
|
||||
private Boolean myUseCustomSoftWrapIndent = null;
|
||||
private Integer myCustomSoftWrapIndent = null;
|
||||
private Boolean myRenamePreselect = null;
|
||||
private Boolean myWrapWhenTypingReachesRightMargin = null;
|
||||
|
||||
public SettingsImpl(@Nullable EditorEx editor) {
|
||||
myEditor = editor;
|
||||
@@ -147,7 +148,19 @@ public class SettingsImpl implements EditorSettings {
|
||||
|
||||
@Override
|
||||
public boolean isWrapWhenTypingReachesRightMargin(Project project) {
|
||||
return CodeStyleFacade.getInstance(project).isWrapWhenTypingReachesRightMargin();
|
||||
return myWrapWhenTypingReachesRightMargin != null ?
|
||||
myWrapWhenTypingReachesRightMargin.booleanValue() :
|
||||
CodeStyleFacade.getInstance(project).isWrapWhenTypingReachesRightMargin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWrapWhenTypingReachesRightMargin(boolean val) {
|
||||
Boolean newValue = Boolean.valueOf(val);
|
||||
if (newValue.equals(myWrapWhenTypingReachesRightMargin)) {
|
||||
return;
|
||||
}
|
||||
myWrapWhenTypingReachesRightMargin = newValue;
|
||||
fireEditorRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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;
|
||||
|
||||
/**
|
||||
* @author Kirill Likhodedov
|
||||
*/
|
||||
public class WrapWhenTypingReachesRightMarginCustomization extends SimpleEditorCustomization {
|
||||
|
||||
public static final WrapWhenTypingReachesRightMarginCustomization ENABLED = new WrapWhenTypingReachesRightMarginCustomization(true);
|
||||
public static final WrapWhenTypingReachesRightMarginCustomization DISABLED = new WrapWhenTypingReachesRightMarginCustomization(false);
|
||||
|
||||
public static EditorCustomization getInstance(boolean value) {
|
||||
return value ? ENABLED : DISABLED;
|
||||
}
|
||||
|
||||
private WrapWhenTypingReachesRightMarginCustomization(boolean enabled) {
|
||||
super(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(@NotNull EditorEx editor) {
|
||||
editor.getSettings().setWrapWhenTypingReachesRightMargin(isEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,6 +93,7 @@ public final class VcsConfiguration implements PersistentStateComponent<Element>
|
||||
public String UPDATE_FILTER_SCOPE_NAME;
|
||||
public boolean USE_COMMIT_MESSAGE_MARGIN = false;
|
||||
public int COMMIT_MESSAGE_MARGIN_SIZE = 72;
|
||||
public boolean WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = false;
|
||||
|
||||
public enum StandardOption {
|
||||
ADD(VcsBundle.message("vcs.command.name.add")),
|
||||
|
||||
+84
-25
@@ -15,59 +15,118 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.configurable;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.VcsConfiguration;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class VcsCommitMessageMarginConfigurable extends VcsCheckBoxWithSpinnerConfigurable {
|
||||
public class VcsCommitMessageMarginConfigurable implements UnnamedConfigurable {
|
||||
|
||||
private final VcsConfiguration myConfiguration;
|
||||
|
||||
private final MySpinnerConfigurable mySpinnerConfigurable;
|
||||
private final JBCheckBox myWrapCheckbox;
|
||||
|
||||
public VcsCommitMessageMarginConfigurable(Project project) {
|
||||
super(project, VcsBundle.message("configuration.commit.message.margin.prompt"), "");
|
||||
myConfiguration = VcsConfiguration.getInstance(myProject);
|
||||
myConfiguration = VcsConfiguration.getInstance(project);
|
||||
mySpinnerConfigurable = new MySpinnerConfigurable(project);
|
||||
myWrapCheckbox = new JBCheckBox(ApplicationBundle.message("checkbox.wrap.typing.on.right.margin"), false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected SpinnerNumberModel createSpinnerModel() {
|
||||
final int columns = myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE;
|
||||
return new SpinnerNumberModel(columns, 0, 10000, 1);
|
||||
}
|
||||
public JComponent createComponent() {
|
||||
JComponent spinnerComponent = mySpinnerConfigurable.createComponent();
|
||||
mySpinnerConfigurable.myHighlightRecentlyChanged.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myWrapCheckbox.setEnabled(mySpinnerConfigurable.myHighlightRecentlyChanged.isSelected());
|
||||
}
|
||||
});
|
||||
|
||||
@Nls
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return VcsBundle.message("configuration.commit.message.margin.title");
|
||||
JPanel rootPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
rootPanel.add(spinnerComponent);
|
||||
rootPanel.add(myWrapCheckbox);
|
||||
return rootPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
if (myHighlightRecentlyChanged.isSelected() != myConfiguration.USE_COMMIT_MESSAGE_MARGIN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Comparing.equal(myHighlightInterval.getValue(), myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return mySpinnerConfigurable.isModified() || myWrapCheckbox.isSelected() != myConfiguration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
myConfiguration.USE_COMMIT_MESSAGE_MARGIN = myHighlightRecentlyChanged.isSelected();
|
||||
myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE = ((Number) myHighlightInterval.getValue()).intValue();
|
||||
mySpinnerConfigurable.apply();
|
||||
myConfiguration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = myWrapCheckbox.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myHighlightRecentlyChanged.setSelected(myConfiguration.USE_COMMIT_MESSAGE_MARGIN);
|
||||
myHighlightInterval.setValue(myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE);
|
||||
myHighlightInterval.setEnabled(myHighlightRecentlyChanged.isSelected());
|
||||
mySpinnerConfigurable.reset();
|
||||
myWrapCheckbox.setSelected(myConfiguration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN);
|
||||
myWrapCheckbox.setEnabled(mySpinnerConfigurable.myHighlightRecentlyChanged.isSelected());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
mySpinnerConfigurable.disposeUIResources();
|
||||
}
|
||||
|
||||
private class MySpinnerConfigurable extends VcsCheckBoxWithSpinnerConfigurable {
|
||||
|
||||
public MySpinnerConfigurable(Project project) {
|
||||
super(project, VcsBundle.message("configuration.commit.message.margin.prompt"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpinnerNumberModel createSpinnerModel() {
|
||||
final int columns = myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE;
|
||||
return new SpinnerNumberModel(columns, 0, 10000, 1);
|
||||
}
|
||||
|
||||
@Nls
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return VcsBundle.message("configuration.commit.message.margin.title");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
if (myHighlightRecentlyChanged.isSelected() != myConfiguration.USE_COMMIT_MESSAGE_MARGIN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Comparing.equal(myHighlightInterval.getValue(), myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
myConfiguration.USE_COMMIT_MESSAGE_MARGIN = myHighlightRecentlyChanged.isSelected();
|
||||
myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE = ((Number) myHighlightInterval.getValue()).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myHighlightRecentlyChanged.setSelected(myConfiguration.USE_COMMIT_MESSAGE_MARGIN);
|
||||
myHighlightInterval.setValue(myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE);
|
||||
myHighlightInterval.setEnabled(myHighlightRecentlyChanged.isSelected());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public class CommitMessage extends AbstractDataProviderPanel implements Disposab
|
||||
boolean enableSpellChecking = forceSpellCheckOn || configuration.CHECK_COMMIT_MESSAGE_SPELLING;
|
||||
features.add(SpellCheckingEditorCustomization.getInstance(enableSpellChecking));
|
||||
features.add(new RightMarginEditorCustomization(configuration.USE_COMMIT_MESSAGE_MARGIN, configuration.COMMIT_MESSAGE_MARGIN_SIZE));
|
||||
features.add(WrapWhenTypingReachesRightMarginCustomization.getInstance(configuration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN));
|
||||
} else {
|
||||
features.add(SpellCheckingEditorCustomization.ENABLED);
|
||||
features.add(new RightMarginEditorCustomization(false, -1));
|
||||
|
||||
Reference in New Issue
Block a user