Skip to content

Commit

Permalink
Add library mode setting to library properties pane (fix #5550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ka0o0 committed Nov 6, 2019
1 parent 7e98453 commit f7e6f77
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
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();

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;
@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) {
// 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

0 comments on commit f7e6f77

Please # to comment.