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 allowing users to add local bst files to preview layout list #11234

Merged
merged 31 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
070e687
Update PreviewTab.fxml
sahilsekr42 Apr 21, 2024
dbfc138
Update PreviewTab.java
sahilsekr42 Apr 21, 2024
293b777
Update PreviewTabViewModel.java
sahilsekr42 Apr 21, 2024
a46bee8
fix undeclared variable
sahilsekr42 Apr 21, 2024
0126f39
Update CHANGELOG.md for committed changes for issue 11102
sahilsekr42 Apr 21, 2024
5a5be03
Update CHANGELOG.md for fixing markdown spacing error
sahilsekr42 Apr 21, 2024
589eb1c
build.gradle openrewrite
sahilsekr42 Apr 21, 2024
cdabc1f
fix gradle errors
sahilsekr42 Apr 21, 2024
a54ecc2
Update PreviewTabViewModel.java for bstlayout getsource() case handling
sahilsekr42 Apr 22, 2024
d782e04
fix import errors
sahilsekr42 Apr 22, 2024
212f7ef
better architecture
Siedlerchr Apr 22, 2024
2a4db3b
test ieeetran with test entry
Siedlerchr Apr 22, 2024
1412d89
fix
Siedlerchr Apr 22, 2024
41d357d
Fix path to IEEEtran.bst
koppor Apr 25, 2024
730fbc7
Streamline conversion to BstEntry
koppor Apr 25, 2024
7a131e7
refactor file chooser
Siedlerchr Apr 25, 2024
8b04f6f
checkstyle
Siedlerchr Apr 25, 2024
04969c3
Somre more traces
koppor Apr 25, 2024
e82de74
Merge branch 'fix-11102' of https://github.com/sahilsekr42/jabref int…
koppor Apr 25, 2024
995856d
Add ''
koppor Apr 25, 2024
d1499b0
Merge branch 'main' into fix-11102
koppor May 19, 2024
efb9e19
checkstyle
Siedlerchr May 19, 2024
773faa4
checkstyle
Siedlerchr May 19, 2024
b1ece3b
Merge remote-tracking branch 'upstream/main' into fix-11102
Siedlerchr May 20, 2024
1a0a23a
move button up
Siedlerchr May 20, 2024
83b4cbb
Fix storing of style in Preferences
Siedlerchr May 20, 2024
380aa6b
wording of changelog
Siedlerchr May 20, 2024
a3aaf3f
cehckstyle
Siedlerchr May 20, 2024
574c87d
checkstyle
Siedlerchr May 20, 2024
57aa305
fix line break
Siedlerchr May 20, 2024
225dab0
damn style
Siedlerchr May 20, 2024
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 @@ -34,7 +34,7 @@
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.bst.BstPreviewLayout;

Check failure on line 37 in src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[reviewdog] reported by reviewdog 🐶 Unused import - org.jabref.logic.bst.BstPreviewLayout. Raw Output: /github/workspace/./src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java:37:8: error: Unused import - org.jabref.logic.bst.BstPreviewLayout. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preview.PreviewLayout;
import org.jabref.logic.util.StandardFileType;
Expand Down Expand Up @@ -121,10 +121,9 @@
.withInitialDirectory(preferencesService.getFilePreferences().getWorkingDirectory())
.build();


dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(bstFile -> {

Check failure on line 125 in src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[reviewdog] reported by reviewdog 🐶 There is more than 1 empty line after this line. Raw Output: /github/workspace/./src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java:125:66: error: There is more than 1 empty line after this line. (com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck)
BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(bstFile);
viewModel.availableListProperty().add(bstPreviewLayout);
viewModel.chosenListProperty().add(bstPreviewLayout);
viewModel.addBstStyle(bstFile);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.preferences.preview;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -11,6 +12,7 @@
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;

Check failure on line 15 in src/main/java/org/jabref/gui/preferences/preview/PreviewTabViewModel.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[reviewdog] reported by reviewdog 🐶 Unused import - javafx.beans.property.Property. Raw Output: /github/workspace/./src/main/java/org/jabref/gui/preferences/preview/PreviewTabViewModel.java:15:8: error: Unused import - javafx.beans.property.Property. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
Expand All @@ -33,6 +35,7 @@
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.bst.BstPreviewLayout;
import org.jabref.logic.citationstyle.CitationStyle;
import org.jabref.logic.citationstyle.CitationStylePreviewLayout;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -70,6 +73,8 @@
private final ListProperty<PreviewLayout> chosenListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ObjectProperty<MultipleSelectionModel<PreviewLayout>> chosenSelectionModelProperty = new SimpleObjectProperty<>(new NoSelectionModel<>());

private final ListProperty<Path> bstStylesPaths = new SimpleListProperty<>(FXCollections.observableArrayList());

private final BooleanProperty selectedIsEditableProperty = new SimpleBooleanProperty(false);
private final ObjectProperty<PreviewLayout> selectedLayoutProperty = new SimpleObjectProperty<>();
private final StringProperty sourceTextProperty = new SimpleStringProperty("");
Expand Down Expand Up @@ -123,6 +128,7 @@
availableListProperty.getValue().add(previewPreferences.getCustomPreviewLayout());
}


BackgroundTask.wrap(CitationStyle::discoverCitationStyles)
.onSuccess(styles -> styles.stream()
.map(style -> new CitationStylePreviewLayout(style, Globals.entryTypesManager))
Expand All @@ -135,6 +141,12 @@
dialogService.showErrorDialogAndWait(Localization.lang("Error adding discovered CitationStyles"), ex);
})
.executeWith(taskExecutor);
bstStylesPaths.clear();
bstStylesPaths.addAll(previewPreferences.getBstPreviewLayoutPaths());
bstStylesPaths.forEach(path -> {
BstPreviewLayout layout = new BstPreviewLayout(path);
availableListProperty.add(layout);
});
}

public void setPreviewLayout(PreviewLayout selectedLayout) {
Expand Down Expand Up @@ -194,10 +206,11 @@
previewPreferences.setShowPreviewAsExtraTab(showAsExtraTabProperty.getValue());
previewPreferences.setShowPreviewEntryTableTooltip(showPreviewInEntryTableTooltip.getValue());
previewPreferences.setCustomPreviewLayout((TextBasedPreviewLayout) customLayout);
previewPreferences.setBstPreviewLayoutPaths(bstStylesPaths);

if (!chosenSelectionModelProperty.getValue().getSelectedItems().isEmpty()) {
previewPreferences.setLayoutCyclePosition(chosenListProperty.getValue().indexOf(
chosenSelectionModelProperty.getValue().getSelectedItems().get(0)));
chosenSelectionModelProperty.getValue().getSelectedItems().getFirst()));
}
}

Expand Down Expand Up @@ -483,4 +496,11 @@
public StringProperty sourceTextProperty() {
return sourceTextProperty;
}

public void addBstStyle(Path bstFile) {
BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(bstFile);
bstStylesPaths.add(bstFile);
availableListProperty().add(bstPreviewLayout);
chosenListProperty().add(bstPreviewLayout);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/bst/BstFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void bstAddPeriod(BstVMVisitor visitor, ParserRuleContext ctx) {
}

/**
* Executes the function whose name is the entry type of an entry.
* Executes the function whose name is the entry type of entry.
* For example if an entry is of type book, this function executes
* the book function. When given as an argument to the ITERATE
* command, call.type$ actually produces the output for the entries.
Expand Down Expand Up @@ -447,7 +447,7 @@ private void bstEmpty(BstVMVisitor visitor, ParserRuleContext ctx) {
throw new BstVMException("Operand does not match function empty$ (line %d)".formatted(ctx.start.getLine()));
}

boolean result = "".equals(s.trim());
boolean result = s.trim().isEmpty();
LOGGER.trace("empty$({}) result: {}", s, result);
stack.push(result ? BstVM.TRUE : BstVM.FALSE);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/logic/bst/BstPreviewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter;
import org.jabref.logic.layout.format.RemoveTilde;
import org.jabref.logic.preview.PreviewLayout;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

Expand Down Expand Up @@ -98,4 +99,11 @@ public String getName() {
public String getText() {
return source;
}

/**
* Checks if the given style file is a BST file by checking the extension
*/
public static boolean isBstStyleFile(String styleFile) {
return StandardFileType.BST.getExtensions().stream().anyMatch(styleFile::endsWith);
}
}
42 changes: 30 additions & 12 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.jabref.gui.theme.Theme;
import org.jabref.logic.JabRefException;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.bst.BstPreviewLayout;
import org.jabref.logic.citationkeypattern.CitationKeyPattern;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.citationkeypattern.GlobalCitationKeyPatterns;
Expand Down Expand Up @@ -386,6 +387,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String CYCLE_PREVIEW = "cyclePreview";
public static final String PREVIEW_AS_TAB = "previewAsTab";
public static final String PREVIEW_IN_ENTRY_TABLE_TOOLTIP = "previewInEntryTableTooltip";
public static final String PREVIEW_BST_LAYOUT_PATHS = "previewBstLayoutPaths";

// UI
private static final String FONT_FAMILY = "fontFamily";
Expand Down Expand Up @@ -515,7 +517,7 @@ private JabRefPreferences() {
importPreferences(Path.of("jabref.xml"));
}
} catch (JabRefException e) {
LOGGER.warn("Could not import preferences from jabref.xml: " + e.getMessage(), e);
LOGGER.warn("Could not import preferences from jabref.xml: {}", e.getMessage(), e);
}

// load user preferences
Expand Down Expand Up @@ -1088,7 +1090,7 @@ public void flush() {
try {
exportPreferences(Path.of("jabref.xml"));
} catch (JabRefException e) {
LOGGER.warn("Could not export preferences for memory stick mode: " + e.getMessage(), e);
LOGGER.warn("Could not export preferences for memory stick mode: {}", e.getMessage(), e);
}
}
try {
Expand Down Expand Up @@ -1643,7 +1645,7 @@ private String getProxyPassword() {
} catch (PasswordAccessException ex) {
LOGGER.warn("JabRef uses proxy password from key store but no password is stored");
} catch (Exception ex) {
LOGGER.warn("JabRef could not open the key store");
LOGGER.warn("JabRef could not open the key store", ex);
}
}
return (String) defaults.get(PROXY_PASSWORD);
Expand Down Expand Up @@ -2110,7 +2112,8 @@ public InternalPreferences getInternalPreferences() {
if (!newValue) {
try {
Files.deleteIfExists(Path.of("jabref.xml"));
} catch (IOException e) {
} catch (
IOException e) {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.warn("Error accessing filesystem", e);
}
}
Expand Down Expand Up @@ -2431,17 +2434,25 @@ public PreviewPreferences getPreviewPreferences() {
new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(), Globals.journalAbbreviationRepository),
(String) defaults.get(PREVIEW_STYLE),
getBoolean(PREVIEW_AS_TAB),
getBoolean(PREVIEW_IN_ENTRY_TABLE_TOOLTIP));
getBoolean(PREVIEW_IN_ENTRY_TABLE_TOOLTIP),
getStringList(PREVIEW_BST_LAYOUT_PATHS).stream()
.map(Path::of)
.collect(Collectors.toList())
);

previewPreferences.getLayoutCycle().addListener((InvalidationListener) c -> storePreviewLayouts(previewPreferences.getLayoutCycle()));
EasyBind.listen(previewPreferences.layoutCyclePositionProperty(), (obs, oldValue, newValue) -> putInt(CYCLE_PREVIEW_POS, newValue));
EasyBind.listen(previewPreferences.customPreviewLayoutProperty(), (obs, oldValue, newValue) -> put(PREVIEW_STYLE, newValue.getText()));
EasyBind.listen(previewPreferences.showPreviewAsExtraTabProperty(), (obs, oldValue, newValue) -> putBoolean(PREVIEW_AS_TAB, newValue));
EasyBind.listen(previewPreferences.showPreviewEntryTableTooltip(), (obs, oldValue, newValue) -> putBoolean(PREVIEW_IN_ENTRY_TABLE_TOOLTIP, newValue));

previewPreferences.getBstPreviewLayoutPaths().addListener((InvalidationListener) c -> storeBstPaths(previewPreferences.getBstPreviewLayoutPaths()));
return this.previewPreferences;
}

private void storeBstPaths(List<Path> bstPaths) {
putStringList(PREVIEW_BST_LAYOUT_PATHS, bstPaths.stream().map(Path::toAbsolutePath).map(Path::toString).toList());
}

private List<PreviewLayout> getPreviewLayouts(String style) {
List<String> cycle = getStringList(CYCLE_PREVIEW);

Expand All @@ -2456,11 +2467,17 @@ private List<PreviewLayout> getPreviewLayouts(String style) {
return CitationStyle.createCitationStyleFromFile(layout)
.map(file -> (PreviewLayout) new CitationStylePreviewLayout(file, Globals.entryTypesManager))
.orElse(null);
}
if (BstPreviewLayout.isBstStyleFile(layout)) {
return getStringList(PREVIEW_BST_LAYOUT_PATHS).stream()
.filter(path -> path.endsWith(layout)).map(Path::of)
.map(file -> (BstPreviewLayout) new BstPreviewLayout(file))
.findFirst()
.orElse(null);
} else {
return new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(), Globals.journalAbbreviationRepository);
}
})
.filter(Objects::nonNull)
}).filter(Objects::nonNull)
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -2541,9 +2558,9 @@ private Map<SidePaneType, Integer> getSidePanePreferredPositions() {
SidePaneType type = Enum.valueOf(SidePaneType.class, name);
preferredPositions.put(type, Integer.parseInt(componentPositions.get(i)));
} catch (NumberFormatException e) {
LOGGER.debug("Invalid number format for side pane component '" + name + "'", e);
LOGGER.debug("Invalid number format for side pane component '{}'", name, e);
} catch (IllegalArgumentException e) {
LOGGER.debug("Following component is not a side pane: '" + name + "'", e);
LOGGER.debug("Following component is not a side pane: '{}'", name, e);
}
}

Expand Down Expand Up @@ -3016,7 +3033,8 @@ private void storeFetcherKeysToKeyring(List<String> names, List<String> keys) {
if (StringUtil.isNullOrEmpty(keys.get(i))) {
try {
keyring.deletePassword("org.jabref.customapikeys", names.get(i));
} catch (PasswordAccessException ex) {
} catch (
PasswordAccessException ex) {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
// Already removed
}
} else {
Expand All @@ -3027,7 +3045,7 @@ private void storeFetcherKeysToKeyring(List<String> names, List<String> keys) {
}
}
} catch (Exception ex) {
LOGGER.error("Unable to open key store");
LOGGER.error("Unable to open key store", ex);
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/jabref/preferences/PreviewPreferences.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.preferences;

import java.nio.file.Path;
import java.util.List;

import javafx.beans.property.BooleanProperty;
Expand All @@ -24,19 +25,22 @@ public class PreviewPreferences {
private final StringProperty defaultCustomPreviewLayout;
private final BooleanProperty showPreviewAsExtraTab;
private final BooleanProperty showPreviewEntryTableTooltip;
private final ObservableList<Path> bstPreviewLayoutPaths;

public PreviewPreferences(List<PreviewLayout> layoutCycle,
int layoutCyclePosition,
TextBasedPreviewLayout customPreviewLayout,
String defaultCustomPreviewLayout,
boolean showPreviewAsExtraTab,
boolean showPreviewEntryTableTooltip) {
boolean showPreviewEntryTableTooltip,
List<Path> bstPreviewLayoutPaths) {
this.layoutCycle = FXCollections.observableArrayList(layoutCycle);
this.layoutCyclePosition = new SimpleIntegerProperty(layoutCyclePosition);
this.customPreviewLayout = new SimpleObjectProperty<>(customPreviewLayout);
this.defaultCustomPreviewLayout = new SimpleStringProperty(defaultCustomPreviewLayout);
this.showPreviewAsExtraTab = new SimpleBooleanProperty(showPreviewAsExtraTab);
this.showPreviewEntryTableTooltip = new SimpleBooleanProperty(showPreviewEntryTableTooltip);
this.bstPreviewLayoutPaths = FXCollections.observableList(bstPreviewLayoutPaths);
}

public ObservableList<PreviewLayout> getLayoutCycle() {
Expand Down Expand Up @@ -112,4 +116,12 @@ public void setShowPreviewEntryTableTooltip(boolean showPreviewEntryTableTooltip
public BooleanProperty showPreviewEntryTableTooltip() {
return showPreviewEntryTableTooltip;
}

public ObservableList<Path> getBstPreviewLayoutPaths() {
return bstPreviewLayoutPaths;
}

public void setBstPreviewLayoutPaths(List<Path> bstPreviewLayoutPaths) {
this.bstPreviewLayoutPaths.setAll(bstPreviewLayoutPaths);
}
}
Loading