Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add switch to change from biblatex to bibtex and vice versa (fi… #5565

Merged
merged 5 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- The entry editor is now open by default when JabRef starts up. [#5460](https://github.com/JabRef/jabref/issues/5460)
- We added a new ADS fetcher to use the new ADS API [#4949](https://github.com/JabRef/jabref/issues/4949)
- We added support of the [X11 primary selection](https://unix.stackexchange.com/a/139193/18033) [#2389](https://github.com/JabRef/jabref/issues/2389)
- We added support to switch between biblatex and bibtex library types. [#5550](https://github.com/JabRef/jabref/issues/5550)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void buildLayout() {

BibDatabaseContext databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext();

recommendButton = new Button(Localization.lang("Recommended for %0", databaseContext.getMode().getFormattedName()));
recommendButton = new Button(Localization.lang("Reset to recommended", databaseContext.getMode().getFormattedName()));
boolean isBiblatex = databaseContext.isBiblatexMode();
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved

recommendButton.setOnAction(e -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<DialogPane minHeight="-Infinity" prefHeight="784.0" prefWidth="921.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.libraryproperties.LibraryPropertiesDialogView">
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<DialogPane minHeight="-Infinity" prefHeight="784.0" prefWidth="921.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.libraryproperties.LibraryPropertiesDialogView">
<content>
<VBox fx:id="contentVbox" minHeight="-Infinity" prefHeight="200.0" prefWidth="100.0">
<children>
Expand All @@ -22,7 +14,7 @@
<ColumnConstraints hgrow="SOMETIMES" maxWidth="797.0" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" prefHeight="65.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="-Infinity" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
Expand All @@ -32,8 +24,26 @@
<RowConstraints minHeight="-Infinity" prefHeight="50.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="%Library encoding" />
<ComboBox fx:id="encoding" prefWidth="250.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" />
<GridPane vgap="5.0" GridPane.columnSpan="3" GridPane.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="218.0" minWidth="10.0" prefWidth="200.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="797.0" minWidth="10.0" prefWidth="529.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="797.0" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<Label text="%Library encoding" />
<ComboBox fx:id="encoding" prefWidth="250.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" />
<Label text="%Database mode" GridPane.rowIndex="2" />
<ComboBox fx:id="databaseMode" prefWidth="250.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" />
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
<RowConstraints />
</rowConstraints>
</GridPane>
<Label text="%General file directory" GridPane.rowIndex="2" />
<TextField fx:id="generalFileDirectory" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Button fx:id="browseGeneralFileDir" mnemonicParsing="false" onAction="#browseGeneralFileDirectory" text="%Browse" GridPane.columnIndex="2" GridPane.rowIndex="2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.cleanup.Cleanups;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.metadata.MetaData;
import org.jabref.model.metadata.SaveOrderConfig;
import org.jabref.preferences.PreferencesService;
Expand All @@ -33,6 +34,7 @@ public class LibraryPropertiesDialogView extends BaseDialog<Void> {

@FXML private VBox contentVbox;
@FXML private ComboBox<Charset> encoding;
@FXML private ComboBox<String> databaseMode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use ComboBox<BibDatabaseMode> here (and propagate the change), then you don't have to constantly convert between formatted values and parsed modes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do so, the names are not formatted anymore. Also, the view would have knowledge about the model.
I normally always try to avoid that by converting the model to non model datatypes. So I would suggest to leave it this way, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the proper display quite easily using similar code as the one below:

new ViewModelListCellFactory<Formatter>()
.withText(Formatter::getName)
.withStringTooltip(Formatter::getDescription)
.install(formattersCombobox);

You are right, one should usually not use model classes directly in the ui. So here the "correct" solution would be to wrap the DatabaseMode in a DatabaseModeViewModel which exposes the getFormattedName method. I feel like this is however overkill for this particular situation.

@FXML private TextField generalFileDirectory;
@FXML private Button browseGeneralFileDir;
@FXML private TextField userSpecificFileDirectory;
Expand Down Expand Up @@ -79,6 +81,9 @@ private void initialize() {
encoding.disableProperty().bind(viewModel.encodingDisableProperty());
protect.disableProperty().bind(viewModel.protectDisableProperty());

databaseMode.itemsProperty().bind(viewModel.databaseModesProperty());
databaseMode.valueProperty().bindBidirectional(viewModel.selectedDatabaseModeProperty());

saveOrderConfigDisplayView = new SaveOrderConfigDisplayView();
Optional<SaveOrderConfig> storedSaveOrderConfig = panel.getBibDatabaseContext().getMetaData().getSaveOrderConfig();
oldSaveOrderConfig = storedSaveOrderConfig.orElseGet(preferencesService::loadExportSaveOrder);
Expand Down Expand Up @@ -124,6 +129,13 @@ private void storeSettings() {
Charset newEncoding = viewModel.selectedEncodingProperty().getValue();
metaData.setEncoding(newEncoding);

BibDatabaseMode newMode = BibDatabaseMode.parse(viewModel.selectedDatabaseModeProperty().getValue());
BibDatabaseMode oldMode = metaData.getMode().orElse(null);
if (newMode != null && oldMode != newMode) {
Ka0o0 marked this conversation as resolved.
Show resolved Hide resolved
// Only set, when mode really has changed to avoid propagation of change events
metaData.setMode(newMode);
}

String text = viewModel.generalFileDirectoryPropertyProperty().getValue().trim();
if (text.isEmpty()) {
metaData.clearDefaultFileDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
Expand All @@ -18,6 +20,7 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.l10n.Encodings;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.metadata.MetaData;
import org.jabref.preferences.PreferencesService;
Expand All @@ -29,6 +32,7 @@ public class LibraryPropertiesDialogViewModel {
private final StringProperty laTexFileDirectoryProperty = new SimpleStringProperty("");
private final ListProperty<Charset> encodingsProperty = new SimpleListProperty<>(FXCollections.observableArrayList(Encodings.getCharsets()));
private final ObjectProperty<Charset> selectedEncodingPropety = new SimpleObjectProperty<>(Encodings.getCharsets().get(0));
private final SimpleStringProperty selectedDatabaseModeProperty = new SimpleStringProperty(BibDatabaseMode.BIBLATEX.getFormattedName());
private final BooleanProperty libraryProtectedProperty = new SimpleBooleanProperty();
private final BooleanProperty encodingDisableProperty = new SimpleBooleanProperty();
private final BooleanProperty protectDisableProperty = new SimpleBooleanProperty();
Expand All @@ -55,6 +59,7 @@ public LibraryPropertiesDialogViewModel(BasePanel panel, DialogService dialogSer

Optional<Charset> charset = metaData.getEncoding();
selectedEncodingPropety.setValue(charset.orElse(preferencesService.getDefaultEncoding()));
selectedDatabaseModeProperty.setValue(metaData.getMode().orElse(BibDatabaseMode.BIBLATEX).getFormattedName());

Optional<String> fileD = metaData.getDefaultFileDirectory();
fileD.ifPresent(path -> generalFileDirectoryProperty.setValue(path.trim()));
Expand Down Expand Up @@ -88,6 +93,18 @@ public ListProperty<Charset> encodingsProperty() {
return this.encodingsProperty;
}

public ListProperty<String> databaseModesProperty() {
return new SimpleListProperty<>(FXCollections.observableArrayList(
Arrays.stream(BibDatabaseMode.values())
.map(BibDatabaseMode::getFormattedName)
.collect(Collectors.toList())
));
}

public SimpleStringProperty selectedDatabaseModeProperty() {
return this.selectedDatabaseModeProperty;
}

public ObjectProperty<Charset> selectedEncodingProperty() {
return this.selectedEncodingPropety;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,6 @@ A\ backup\ file\ for\ '%0'\ was\ found.=A backup file for '%0' was found.
This\ could\ indicate\ that\ JabRef\ did\ not\ shut\ down\ cleanly\ last\ time\ the\ file\ was\ used.=This could indicate that JabRef did not shut down cleanly last time the file was used.
Do\ you\ want\ to\ recover\ the\ library\ from\ the\ backup\ file?=Do you want to recover the library from the backup file?

Recommended\ for\ %0=Recommended for %0
Show\ 'Related\ Articles'\ tab=Show 'Related Articles' tab
This\ might\ be\ caused\ by\ reaching\ the\ traffic\ limitation\ of\ Google\ Scholar\ (see\ 'Help'\ for\ details).=This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details).

Expand Down Expand Up @@ -2126,3 +2125,5 @@ Start\ on\ second\ duplicate\ key\ with\ letter\ B\ (b,\ c,\ ...)=Start on secon
Always\ add\ letter\ (a,\ b,\ ...)\ to\ generated\ keys=Always add letter (a, b, ...) to generated keys
Default\ pattern=Default pattern
Reset\ %s\ to\ default\ value=Reset %s to default value
Database\ mode=Database mode
Reset\ to\ recommended=Reset to recommended