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

Fix-11102 by giving user option to add a bst style preview to available #11229

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<CheckBox fx:id="showAsTabCheckBox" text="%Show preview as a tab in entry editor"/>
<CheckBox fx:id="showPreviewTooltipCheckBox" text="Show preview in entry table tooltip"/>
<HBox spacing="4.0">
<Button fx:id="bstFileButton" text="Select BST File" onAction="#selectBstFile" />
<VBox spacing="4.0" HBox.hgrow="ALWAYS">
<Label text="%Available" styleClass="sectionHeader"/>
<CustomTextField fx:id="searchBox" promptText="%Filter" VBox.vgrow="NEVER" prefHeight="20.0"/>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.jabref.gui.preferences.preview;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import javafx.application.Platform;
import javafx.beans.property.ListProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
Expand All @@ -18,6 +21,7 @@
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.stage.FileChooser;

import org.jabref.gui.Globals;
import org.jabref.gui.StateManager;
Expand All @@ -32,6 +36,7 @@
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.bst.BstPreviewLayout;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preview.PreviewLayout;
import org.jabref.logic.util.TestEntry;
Expand Down Expand Up @@ -104,6 +109,21 @@ public String getTabName() {
return Localization.lang("Entry preview");
}

@FXML
private void selectBstFile(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select BST File");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("BST Files", "*.bst"));

File selectedFile = fileChooser.showOpenDialog(null);
if (selectedFile != null) {
String filePath = selectedFile.getAbsolutePath();
BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(filePath));
viewModel.availableListProperty().add(bstPreviewLayout);
previewViewer.setEntry(TestEntry.getTestEntry());
}
}

public void initialize() {
this.viewModel = new PreviewTabViewModel(dialogService, preferencesService.getPreviewPreferences(), taskExecutor, stateManager);
lastKeyPressTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ public void setPreviewLayout(PreviewLayout selectedLayout) {
sourceTextProperty.setValue(layout.getText().replace("__NEWLINE__", "\n"));
selectedIsEditableProperty.setValue(true);
} else {
sourceTextProperty.setValue(((CitationStylePreviewLayout) selectedLayout).getSource());
selectedIsEditableProperty.setValue(false);
if (selectedLayout instanceof CitationStylePreviewLayout) {
sourceTextProperty.setValue(((CitationStylePreviewLayout) selectedLayout).getSource());
selectedIsEditableProperty.setValue(false);
}
}
}

Expand Down
Loading