Skip to content

Commit

Permalink
Library properties: no change but.. (issue #3562) (#3579)
Browse files Browse the repository at this point in the history
* fix issue #3562

* fix issue #3562 (fix typo)

* fix issue #3562 (inline)

* fix issue #3562 (inline 2)

* fix issue #3562 (inline 2)

* fix issue #3562 (checkstyleMain)
  • Loading branch information
PJozeph authored and tobiasdiez committed Dec 31, 2017
1 parent 7a578de commit 504f7d8
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,38 @@ 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 = !getNewSaveOrderConfig().equals(oldSaveOrderConfig);
boolean changed = saveOrderConfigChanged || !newEncoding.equals(oldEncoding)
|| !oldFileVal.equals(fileDir.getText()) || !oldFileIndvVal.equals(fileDirIndv.getText())
|| (oldProtectVal != protect.isSelected()) || saveActionsChanged;
return changed;
}

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 @@ -244,7 +269,6 @@ private void setValues() {
}

private void storeSettings() {

Charset oldEncoding = panel.getBibDatabaseContext().getMetaData().getEncoding()
.orElse(Globals.prefs.getDefaultEncoding());
Charset newEncoding = (Charset) encoding.getSelectedItem();
Expand All @@ -270,22 +294,11 @@ 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 = !getNewSaveOrderConfig().equals(oldSaveOrderConfig);

// See if any of the values have been modified:
if (saveOrderConfigChanged) {
if (newSaveOrderConfig.equals(SaveOrderConfig.getDefaultSaveOrder())) {
metaData.clearSaveOrderConfig();
Expand Down

0 comments on commit 504f7d8

Please sign in to comment.