Skip to content

Commit

Permalink
fix issue JabRef#3562
Browse files Browse the repository at this point in the history
  • Loading branch information
PJozeph committed Dec 25, 2017
1 parent dd83589 commit a6f67b2
Showing 1 changed file with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,42 @@ public void actionPerformed(ActionEvent e) {
am.put("close", closeAction);

ok.addActionListener(e -> {
storeSettings();
if (propertiesChanged()) {
storeSettings();
}
dispose();
});

cancel.addActionListener(e -> dispose());
}

private boolean propertiesChanged() {
Charset oldEncoding = panel.getBibDatabaseContext().getMetaData().getEncoding()
.orElse(Globals.prefs.getDefaultEncoding());
Charset newEncoding = (Charset) encoding.getSelectedItem();
boolean saveActionsChanged = fieldFormatterCleanupsPanel.hasChanged();
boolean saveOrderConfigChanged = newAndOldOrderCinfigIsSame(getNewSaveOrderConfig(), oldSaveOrderConfig);
boolean changed = saveOrderConfigChanged || !newEncoding.equals(oldEncoding)
|| !oldFileVal.equals(fileDir.getText()) || !oldFileIndvVal.equals(fileDirIndv.getText())
|| (oldProtectVal != protect.isSelected()) || saveActionsChanged;
return changed;
}

private boolean newAndOldOrderCinfigIsSame(SaveOrderConfig newSaveOrderConfig, SaveOrderConfig oldSaveOrderConfig) {
return newSaveOrderConfig.equals(oldSaveOrderConfig) ? false : true;
}

private SaveOrderConfig getNewSaveOrderConfig() {
SaveOrderConfig saveOrderConfig = null;
if (saveInOriginalOrder.isSelected()) {
saveOrderConfig = SaveOrderConfig.getDefaultSaveOrder();
} else {
saveOrderConfig = saveOrderPanel.getSaveOrderConfig();
saveOrderConfig.setSaveInSpecifiedOrder();
}
return saveOrderConfig;
}

private void setupSortOrderConfiguration() {
saveInOriginalOrder = new JRadioButton(Localization.lang("Save entries in their original order"));
saveInSpecifiedOrder = new JRadioButton(Localization.lang("Save entries ordered as specified"));
Expand Down Expand Up @@ -270,21 +299,10 @@ private void storeSettings() {
metaData.markAsNotProtected();
}

SaveOrderConfig newSaveOrderConfig;
if (saveInOriginalOrder.isSelected()) {
newSaveOrderConfig = SaveOrderConfig.getDefaultSaveOrder();
} else {
newSaveOrderConfig = saveOrderPanel.getSaveOrderConfig();
newSaveOrderConfig.setSaveInSpecifiedOrder();
}
SaveOrderConfig newSaveOrderConfig = getNewSaveOrderConfig();

// See if any of the values have been modified:
boolean saveOrderConfigChanged;
if (newSaveOrderConfig.equals(oldSaveOrderConfig)) {
saveOrderConfigChanged = false;
} else {
saveOrderConfigChanged = true;
}
boolean saveOrderConfigChanged = newAndOldOrderCinfigIsSame(getNewSaveOrderConfig(), oldSaveOrderConfig);

if (saveOrderConfigChanged) {
if (newSaveOrderConfig.equals(SaveOrderConfig.getDefaultSaveOrder())) {
Expand Down

0 comments on commit a6f67b2

Please sign in to comment.