Skip to content

Commit

Permalink
Fixed close entry editor block (#2187)
Browse files Browse the repository at this point in the history
* Fixed close entry editor block

* Public removed class StoreFieldAction
  • Loading branch information
Jürgen Lange authored and lenhard committed Oct 26, 2016
1 parent 2e6df6a commit a5fddf9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#2104](https://github.com/JabRef/jabref/issues/#2104): Crash after saving BibTeX source with parsing error
- Fixed [#2109](https://github.com/JabRef/jabref/issues/#2109): <kbd>Ctrl-s</kbd> doesn't trigger parsing error message
- Fixed RTFChars would only use "?" for characters with unicode over the value of 127, now it uses the base character (é -> e instead of ?)
- Fixed close action of entry editor not working after parsing error corrected

### Removed
- Removed 2nd preview style
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,12 @@ public class EntryEditor extends JPanel implements EntryContainer {

// text area from getting updated. This is used in cases where the source
// couldn't be parsed, and the user is given the option to edit it.
private boolean lastSourceAccepted = true; // This indicates whether the last

// attempt
private boolean lastFieldAccepted = true;
private boolean lastSourceAccepted = true; // This indicates whether the last attempt
// at parsing the source was successful. It is used to determine whether the
// dialog should close; it should stay open if the user received an error
// message about the source, whatever he or she chose to do about it.
private String lastSourceStringAccepted; // This is used to prevent double

// fields.
private String lastSourceStringAccepted; // This is used to prevent double fields.
// These values can be used to calculate the preferred height for the form.
// reqW starts at 1 because it needs room for the bibtex key field.
private int sourceIndex = -1; // The index the source panel has in tabbed.
Expand Down Expand Up @@ -1068,9 +1065,17 @@ public void close() {
updateField(source);
if (lastSourceAccepted) {
panel.entryEditorClosing(EntryEditor.this);
} else {
panel.runCommand(Actions.SAVE);
lastSourceAccepted = true;
}
} else {
panel.entryEditorClosing(EntryEditor.this);
if (lastFieldAccepted) {
panel.entryEditorClosing(EntryEditor.this);
} else {
panel.runCommand(Actions.SAVE);
lastFieldAccepted = true;
}
}
}

Expand All @@ -1083,10 +1088,11 @@ public CloseAction() {
@Override
public void actionPerformed(ActionEvent e) {
close();

}
}

public class StoreFieldAction extends AbstractAction {
class StoreFieldAction extends AbstractAction {

public StoreFieldAction() {
super("Store field value");
Expand Down Expand Up @@ -1118,6 +1124,7 @@ public void actionPerformed(ActionEvent event) {
if ((cleaned == null) || cleaned.equals(newValue)) {
textField.setValidBackgroundColor();
} else {
lastFieldAccepted = false;
textField.setInvalidBackgroundColor();
if (!SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(frame, Localization.lang("Invalid BibTeX key"),
Expand Down Expand Up @@ -1186,8 +1193,8 @@ public void actionPerformed(ActionEvent event) {
// properly formatted. If that happens, the field
// is not stored and the textarea turns red.
if (toSet != null) {
new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences())
.format(toSet, fieldEditor.getFieldName());
new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()).format(toSet,
fieldEditor.getFieldName());
}

String oldValue = entry.getField(fieldEditor.getFieldName()).orElse(null);
Expand All @@ -1207,7 +1214,8 @@ public void actionPerformed(ActionEvent event) {
}

// Add an UndoableFieldChange to the baseframe's undoManager.
UndoableFieldChange undoableFieldChange = new UndoableFieldChange(entry, fieldEditor.getFieldName(), oldValue, toSet);
UndoableFieldChange undoableFieldChange = new UndoableFieldChange(entry,
fieldEditor.getFieldName(), oldValue, toSet);
if (updateTimeStampIsSet()) {
NamedCompound ce = new NamedCompound(undoableFieldChange.getPresentationName());
ce.addEdit(undoableFieldChange);
Expand All @@ -1224,10 +1232,11 @@ public void actionPerformed(ActionEvent event) {
updateSource();
panel.markBaseChanged();
} catch (IllegalArgumentException ex) {
lastFieldAccepted = false;
fieldEditor.setInvalidBackgroundColor();
if (!SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(frame, Localization.lang("Error") + ": " + ex.getMessage(),
Localization.lang("Error setting field"), JOptionPane.ERROR_MESSAGE);
Localization.lang("Error setting field"), JOptionPane.ERROR_MESSAGE);
LOGGER.debug("Error setting field", ex);
requestFocus();
}
Expand All @@ -1240,8 +1249,7 @@ public void actionPerformed(ActionEvent event) {
if (fieldEditor.getTextComponent().hasFocus()) {
fieldEditor.setBackground(GUIGlobals.ACTIVE_EDITOR_COLOR);
}
} else if (source.isEditable()
&& !source.getText().equals(lastSourceStringAccepted)) {
} else if (source.isEditable() && !source.getText().equals(lastSourceStringAccepted)) {
validEntry = storeSource();
}

Expand Down

0 comments on commit a5fddf9

Please sign in to comment.