mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use spinner control for VcsCommitMessageMarginConfigurable
This commit is contained in:
committed by
Kirill Likhodedov
parent
fa82b9ebe6
commit
e9a61fa6af
+17
-68
@@ -15,27 +15,28 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.configurable;
|
||||
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
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 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 implements Configurable {
|
||||
public class VcsCommitMessageMarginConfigurable extends VcsCheckBoxWithSpinnerConfigurable {
|
||||
|
||||
private JCheckBox myEnableMarginCheckbox;
|
||||
private JTextField myRightMarginTextField;
|
||||
private final VcsConfiguration myConfiguration;
|
||||
|
||||
public VcsCommitMessageMarginConfigurable(Project project) {
|
||||
myConfiguration = VcsConfiguration.getInstance(project);
|
||||
super(project, VcsBundle.message("configuration.commit.message.margin.prompt"), "");
|
||||
myConfiguration = VcsConfiguration.getInstance(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpinnerNumberModel createSpinnerModel() {
|
||||
final int columns = myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE;
|
||||
return new SpinnerNumberModel(columns, 0, 10000, 1);
|
||||
}
|
||||
|
||||
@Nls
|
||||
@@ -44,81 +45,29 @@ public class VcsCommitMessageMarginConfigurable implements Configurable {
|
||||
return VcsBundle.message("configuration.commit.message.margin.title");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
myEnableMarginCheckbox = new JCheckBox(VcsBundle.message("configuration.commit.message.margin.prompt"), myConfiguration.USE_COMMIT_MESSAGE_MARGIN);
|
||||
myRightMarginTextField = new JTextField(Integer.toString(myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE), 5);
|
||||
myRightMarginTextField.setEnabled(myEnableMarginCheckbox.isSelected());
|
||||
wrapper.add(myEnableMarginCheckbox);
|
||||
wrapper.add(myRightMarginTextField);
|
||||
|
||||
myEnableMarginCheckbox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myRightMarginTextField.setEnabled(myEnableMarginCheckbox.isSelected());
|
||||
}
|
||||
});
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
if (myEnableMarginCheckbox.isSelected() != myConfiguration.USE_COMMIT_MESSAGE_MARGIN) {
|
||||
if (myHighlightRecentlyChanged.isSelected() != myConfiguration.USE_COMMIT_MESSAGE_MARGIN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getValidRightMargin() == null || getValidRightMargin() != myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE) {
|
||||
if (!Comparing.equal(myHighlightInterval.getValue(), myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If possible, returns a valid user-input right margin (i.e. an int greater than zero).
|
||||
* Otherwise, returns null.
|
||||
*/
|
||||
private Integer getValidRightMargin() {
|
||||
if (myRightMarginTextField == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Integer rightMargin = Integer.parseInt(myRightMarginTextField.getText());
|
||||
return rightMargin == null || rightMargin < 0 ? null : rightMargin;
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
myConfiguration.USE_COMMIT_MESSAGE_MARGIN = myEnableMarginCheckbox.isSelected();
|
||||
Integer rightMargin = getValidRightMargin();
|
||||
if (rightMargin == null) {
|
||||
// invalid right margin provided; revert to previous setting
|
||||
myRightMarginTextField.setText(Integer.toString(myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE));
|
||||
} else {
|
||||
myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE = rightMargin;
|
||||
}
|
||||
myConfiguration.USE_COMMIT_MESSAGE_MARGIN = myHighlightRecentlyChanged.isSelected();
|
||||
myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE = ((Number) myHighlightInterval.getValue()).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myEnableMarginCheckbox.setSelected(myConfiguration.USE_COMMIT_MESSAGE_MARGIN);
|
||||
myRightMarginTextField.setText(Integer.toString(myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
myHighlightRecentlyChanged.setSelected(myConfiguration.USE_COMMIT_MESSAGE_MARGIN);
|
||||
myHighlightInterval.setValue(myConfiguration.COMMIT_MESSAGE_MARGIN_SIZE);
|
||||
myHighlightInterval.setEnabled(myHighlightRecentlyChanged.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user