From 41a1999f82d06a36cdfef70bb77f963e2a1ff6d5 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 4 Sep 2022 20:12:28 +0200 Subject: [PATCH 1/2] Fix issue with empty fallback directory (#9134) --- src/main/java/org/jabref/preferences/JabRefPreferences.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index ef7f129a320..496e4face75 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2171,11 +2171,11 @@ public FieldWriterPreferences getFieldWriterPreferences() { * @param originalDirectory the directory as configured */ private String determineMainFileDirectory(String originalDirectory) { - if (!originalDirectory.isEmpty()) { + if ((originalDirectory != null) && !originalDirectory.isEmpty()) { // A non-empty directory is kept return originalDirectory; } - return Path.of(JabRefDesktop.getDefaultFileChooserDirectory(), "JabRef").toString(); + return JabRefDesktop.getDefaultFileChooserDirectory().toString(); } @Override From f240f6d8851b2c33411eca433c29212b4c2f043f Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 4 Sep 2022 21:01:59 +0200 Subject: [PATCH 2/2] Resimplify Action interface (#9133) * Resimplify Action interface * checkstyle * checkstyle * InfoButton --- .../java/org/jabref/gui/actions/Action.java | 68 ------------------- .../cell/sidebuttons/InfoButton.java | 34 +++++----- .../sidebuttons/ToggleMergeUnmergeButton.java | 39 ++++++++--- 3 files changed, 48 insertions(+), 93 deletions(-) diff --git a/src/main/java/org/jabref/gui/actions/Action.java b/src/main/java/org/jabref/gui/actions/Action.java index 28859e00225..e6ccfe487b2 100644 --- a/src/main/java/org/jabref/gui/actions/Action.java +++ b/src/main/java/org/jabref/gui/actions/Action.java @@ -1,6 +1,5 @@ package org.jabref.gui.actions; -import java.util.Objects; import java.util.Optional; import org.jabref.gui.icon.JabRefIcon; @@ -20,71 +19,4 @@ default Optional getKeyBinding() { default String getDescription() { return ""; } - - class Builder { - private final ActionImpl actionImpl; - - public Builder(String text) { - this.actionImpl = new ActionImpl(); - setText(text); - } - - public Builder() { - this(""); - } - - public Action setIcon(JabRefIcon icon) { - Objects.requireNonNull(icon); - actionImpl.icon = icon; - return actionImpl; - } - - public Action setText(String text) { - Objects.requireNonNull(text); - actionImpl.text = text; - return actionImpl; - } - - public Action setKeyBinding(KeyBinding keyBinding) { - Objects.requireNonNull(keyBinding); - actionImpl.keyBinding = keyBinding; - return actionImpl; - } - - public Action setDescription(String description) { - Objects.requireNonNull(description); - actionImpl.description = description; - return actionImpl; - } - } - - class ActionImpl implements Action { - private JabRefIcon icon; - private KeyBinding keyBinding; - private String text; - private String description; - - private ActionImpl() { - } - - @Override - public Optional getIcon() { - return Optional.ofNullable(icon); - } - - @Override - public Optional getKeyBinding() { - return Optional.ofNullable(keyBinding); - } - - @Override - public String getText() { - return text != null ? text : ""; - } - - @Override - public String getDescription() { - return description != null ? description : ""; - } - } } diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java index da37e2267ce..55bb2009bbf 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java @@ -1,5 +1,7 @@ package org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons; +import java.util.Optional; + import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.control.Button; @@ -9,6 +11,7 @@ import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.icon.JabRefIcon; import com.tobiasdiez.easybind.EasyBind; @@ -16,18 +19,27 @@ public class InfoButton extends Button { private final StringProperty infoMessage = new SimpleStringProperty(); private final ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); + private final Action mergeAction = new Action() { + @Override + public Optional getIcon() { + return Optional.of(IconTheme.JabRefIcons.INTEGRITY_INFO); + } + + @Override + public String getText() { + return infoMessage.get(); + } + }; + public InfoButton(String infoMessage) { - setInfoMessage(infoMessage); + this.infoMessage.setValue(infoMessage); configureButton(); - EasyBind.subscribe(infoMessageProperty(), newWarningMessage -> { - configureButton(); - }); + EasyBind.subscribe(this.infoMessage, newWarningMessage -> configureButton()); } private void configureButton() { setMaxHeight(Double.MAX_VALUE); setFocusTraversable(false); - Action mergeAction = new Action.Builder(getInfoMessage()).setIcon(IconTheme.JabRefIcons.INTEGRITY_INFO); actionFactory.configureIconButton(mergeAction, new SimpleCommand() { @Override @@ -36,16 +48,4 @@ public void execute() { } }, this); } - - private void setInfoMessage(String infoMessage) { - infoMessageProperty().set(infoMessage); - } - - public StringProperty infoMessageProperty() { - return infoMessage; - } - - public String getInfoMessage() { - return infoMessage.get(); - } } diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java index de958837778..4622918ec50 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java @@ -1,5 +1,7 @@ package org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons; +import java.util.Optional; + import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; @@ -11,6 +13,7 @@ import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.icon.JabRefIcon; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; @@ -32,16 +35,13 @@ public ToggleMergeUnmergeButton(Field field) { } private void configureMergeButton() { - Action mergeAction = new Action.Builder(Localization.lang("Merge %0", field.getDisplayName())) - .setIcon(IconTheme.JabRefIcons.MERGE_GROUPS); - - actionFactory.configureIconButton(mergeAction, new ToggleMergeUnmergeAction(), this); + ToggleMergeCommand mergeCommand = new ToggleMergeCommand(); + actionFactory.configureIconButton(mergeCommand.mergeAction, mergeCommand, this); } private void configureUnmergeButton() { - Action unmergeAction = new Action.Builder(Localization.lang("Unmerge %0", field.getDisplayName())) - .setIcon(IconTheme.JabRefIcons.UNDO); - actionFactory.configureIconButton(unmergeAction, new ToggleMergeUnmergeAction(), this); + ToggleMergeCommand unmergeCommand = new ToggleMergeCommand(); + actionFactory.configureIconButton(unmergeCommand.unmergeAction, unmergeCommand, this); } public ObjectProperty fieldStateProperty() { @@ -71,7 +71,30 @@ public void setCanMerge(boolean value) { canMergeProperty().set(value); } - private class ToggleMergeUnmergeAction extends SimpleCommand { + private class ToggleMergeCommand extends SimpleCommand { + private final Action mergeAction = new Action() { + @Override + public Optional getIcon() { + return Optional.of(IconTheme.JabRefIcons.MERGE_GROUPS); + } + + @Override + public String getText() { + return Localization.lang("Merge %0", field.getDisplayName()); + } + }; + + private final Action unmergeAction = new Action() { + @Override + public Optional getIcon() { + return Optional.of(IconTheme.JabRefIcons.UNDO); + } + + @Override + public String getText() { + return Localization.lang("Unmerge %0", field.getDisplayName()); + } + }; @Override public void execute() {