mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove modification flag and listeners from fields because use of them makes Apply button always active even no real changes was made
This commit is contained in:
+2
-21
@@ -5,31 +5,11 @@ import com.jetbrains.edu.learning.settings.StudyOptionsProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class CCOptions implements StudyOptionsProvider {
|
||||
private JRadioButton myHtmlRadioButton;
|
||||
private JRadioButton myMarkdownRadioButton;
|
||||
private JPanel myPanel;
|
||||
private boolean myIsModified = false;
|
||||
|
||||
|
||||
public CCOptions() {
|
||||
myHtmlRadioButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myIsModified = true;
|
||||
}
|
||||
});
|
||||
|
||||
myMarkdownRadioButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myIsModified = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -47,7 +27,8 @@ public class CCOptions implements StudyOptionsProvider {
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return myIsModified;
|
||||
final boolean htmlAsDefaultTaskFormat = CCSettings.getInstance().useHtmlAsDefaultTaskFormat();
|
||||
return myHtmlRadioButton.isSelected() != htmlAsDefaultTaskFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-20
@@ -40,30 +40,17 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
private JPanel myPane;
|
||||
private JBCheckBox myEnableTestingFromSamples;
|
||||
|
||||
private boolean myCredentialsModified;
|
||||
|
||||
public StepicStudyOptions() {
|
||||
myLoginTextField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
myCredentialsModified = true;
|
||||
erasePassword();
|
||||
}
|
||||
});
|
||||
|
||||
myPasswordField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
myCredentialsModified = true;
|
||||
}
|
||||
});
|
||||
|
||||
myEnableTestingFromSamples.addChangeListener(e -> myCredentialsModified = true);
|
||||
}
|
||||
|
||||
private void erasePassword() {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -88,6 +75,10 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
private void setPassword(@NotNull final String password) {
|
||||
myPasswordField.setText(password);
|
||||
}
|
||||
|
||||
private boolean isTestingFromSamplesEnabled() {
|
||||
return myEnableTestingFromSamples.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
@@ -98,7 +89,6 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
setLogin(user.getEmail());
|
||||
setPassword(user.getPassword());
|
||||
myEnableTestingFromSamples.setSelected(taskManager.isEnableTestingFromSamples());
|
||||
resetCredentialsModification();
|
||||
}
|
||||
else {
|
||||
LOG.warn("No study object is opened");
|
||||
@@ -112,11 +102,12 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
if (myCredentialsModified) {
|
||||
if (isModified()) {
|
||||
final Project project = StudyUtils.getStudyProject();
|
||||
if (project != null) {
|
||||
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
taskManager.setEnableTestingFromSamples(myEnableTestingFromSamples.isSelected());
|
||||
|
||||
final String login = getLogin();
|
||||
final String password = getPassword();
|
||||
if (!StringUtil.isEmptyOrSpaces(login) && !StringUtil.isEmptyOrSpaces(password)) {
|
||||
@@ -141,7 +132,6 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
LOG.warn("No study object is opened");
|
||||
}
|
||||
}
|
||||
resetCredentialsModification();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -151,11 +141,15 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return myCredentialsModified;
|
||||
}
|
||||
final Project project = StudyUtils.getStudyProject();
|
||||
if (project == null) return false;
|
||||
|
||||
public void resetCredentialsModification() {
|
||||
myCredentialsModified = false;
|
||||
final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
final StepicUser user = taskManager.getUser();
|
||||
|
||||
return !getLogin().equals(user.getEmail())
|
||||
|| !getPassword().equals(user.getPassword())
|
||||
|| !isTestingFromSamplesEnabled() == taskManager.isEnableTestingFromSamples();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
|
||||
Reference in New Issue
Block a user