Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into luceneSearchBackend
Browse files Browse the repository at this point in the history
* upstream/main:
  Resimplify Action interface (#9133)
  Fix issue with empty fallback directory (#9134)
  • Loading branch information
Siedlerchr committed Sep 4, 2022
2 parents b0cf627 + f240f6d commit 85445bd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 95 deletions.
68 changes: 0 additions & 68 deletions src/main/java/org/jabref/gui/actions/Action.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui.actions;

import java.util.Objects;
import java.util.Optional;

import org.jabref.gui.icon.JabRefIcon;
Expand All @@ -20,71 +19,4 @@ default Optional<KeyBinding> 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<JabRefIcon> getIcon() {
return Optional.ofNullable(icon);
}

@Override
public Optional<KeyBinding> getKeyBinding() {
return Optional.ofNullable(keyBinding);
}

@Override
public String getText() {
return text != null ? text : "";
}

@Override
public String getDescription() {
return description != null ? description : "";
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,25 +11,35 @@
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;

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<JabRefIcon> 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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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<FieldState> fieldStateProperty() {
Expand Down Expand Up @@ -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<JabRefIcon> 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<JabRefIcon> getIcon() {
return Optional.of(IconTheme.JabRefIcons.UNDO);
}

@Override
public String getText() {
return Localization.lang("Unmerge %0", field.getDisplayName());
}
};

@Override
public void execute() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 85445bd

Please sign in to comment.