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

Observable preferences A (Appearance and Importer) #8041

Merged
merged 10 commits into from
Sep 1, 2021
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private Node createToolbar() {
new HBox(
factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager)),
factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)),
factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)),
factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, prefs, stateManager)),
factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager))
),

Expand Down Expand Up @@ -753,7 +753,7 @@ private MenuBar createMenu() {
// @formatter:off
library.getItems().addAll(
factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)),
factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)),
factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, prefs, stateManager)),
factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager)),

new SeparatorMenuItem(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void applyPreferences(PreferencesService preferences) {
Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences());

// Build list of Import and Export formats
Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImportSettingsPreferences(), preferences.getImportFormatPreferences(),
Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImporterPreferences(), preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(), Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX),
preferences.getBibEntryTypes(BibDatabaseMode.BIBLATEX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public StringProperty inputTextProperty() {
}

public void startParsing() {
if (preferencesService.getImportSettingsPreferences().isGrobidEnabled()) {
if (preferencesService.getImporterPreferences().isGrobidEnabled()) {
parseUsingGrobid();
} else {
parseUsingBibtexExtractor();
Expand All @@ -76,7 +76,7 @@ private void parseUsingBibtexExtractor() {
}

private void parseUsingGrobid() {
GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getImportSettingsPreferences(), preferencesService.getImportFormatPreferences());
GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences());
BackgroundTask.wrap(() -> grobidCitationFetcher.performSearch(inputTextProperty.getValue()))
.onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed...")))
.onFailure((e) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.importer.GrobidOptInDialogHelper;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;

import static org.jabref.gui.actions.ActionHelper.needsDatabase;

public class ExtractBibtexAction extends SimpleCommand {

public ExtractBibtexAction(StateManager stateManager) {
PreferencesService preferencesService;
DialogService dialogService;

public ExtractBibtexAction(DialogService dialogService, PreferencesService preferencesService, StateManager stateManager) {
this.preferencesService = preferencesService;
this.dialogService = dialogService;
this.executable.bind(needsDatabase(stateManager));
}

@Override
public void execute() {
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService);
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences());
dialogService.showCustomDialogAndWait(new ExtractBibtexDialog());
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private void setupToolBar() {
// Add menu for fetching bibliographic information
ContextMenu fetcherMenu = new ContextMenu();
SortedSet<EntryBasedFetcher> entryBasedFetchers = WebFetchers.getEntryBasedFetchers(
preferencesService.getImportSettingsPreferences(),
preferencesService.getImporterPreferences(),
preferencesService.getImportFormatPreferences(),
preferencesService.getFilePreferences(),
databaseContext,
Expand All @@ -369,10 +369,10 @@ private void setupToolBar() {
if (fetcher instanceof PdfMergeMetadataImporter.EntryBasedFetcherWrapper) {
// Handle Grobid Opt-In in case of the PdfMergeMetadataImporter
fetcherMenuItem.setOnAction(event -> {
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService);
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences());
PdfMergeMetadataImporter.EntryBasedFetcherWrapper pdfMergeMetadataImporter =
new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(
preferencesService.getImportSettingsPreferences(),
preferencesService.getImporterPreferences(),
preferencesService.getImportFormatPreferences(),
preferencesService.getFilePreferences(),
databaseContext,
Expand All @@ -395,8 +395,8 @@ private void fetchAndMerge(EntryBasedFetcher fetcher) {
public void setFocusToField(Field field) {
DefaultTaskExecutor.runInJavaFXThread(() -> {
for (Tab tab : tabbed.getTabs()) {
if ((tab instanceof FieldsEditorTab) && ((FieldsEditorTab) tab).getShownFields().contains(field)) {
FieldsEditorTab fieldsEditorTab = (FieldsEditorTab) tab;
if ((tab instanceof FieldsEditorTab fieldsEditorTab) && fieldsEditorTab.getShownFields()
.contains(field)) {
tabbed.getSelectionModel().select(tab);
fieldsEditorTab.requestFocus(field);
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ImportHandler(BibDatabaseContext database,

this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database);
this.contentImporter = new ExternalFilesContentImporter(
preferencesService.getImportSettingsPreferences(),
preferencesService.getImporterPreferences(),
preferencesService.getImportFormatPreferences());
this.undoManager = undoManager;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public void importEntries(List<BibEntry> entries) {
preferencesService.getTimestampPreferences());

// Generate citation keys
if (preferencesService.getImportSettingsPreferences().generateNewKeyOnImport()) {
if (preferencesService.getImporterPreferences().isGenerateNewKeyOnImport()) {
generateKeys(entries);
}

Expand All @@ -185,8 +185,7 @@ public void importEntries(List<BibEntry> entries) {

private void addToGroups(List<BibEntry> entries, Collection<GroupTreeNode> groups) {
for (GroupTreeNode node : groups) {
if (node.getGroup() instanceof GroupEntryChanger) {
GroupEntryChanger entryChanger = (GroupEntryChanger) node.getGroup();
if (node.getGroup() instanceof GroupEntryChanger entryChanger) {
List<FieldChange> undo = entryChanger.add(entries);
// TODO: Add undo
// if (!undo.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public void parsePdfMetadataAndShowMergeDialog() {
dialog.addSource(Localization.lang("Entry"), entry);
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImportSettingsPreferences(), preferences.getImportFormatPreferences()), filePath));
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImporterPreferences(), preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferences.getXmpPreferences()), filePath));
dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(preferences.getImportFormatPreferences()), filePath));
dialog.showAndWait().ifPresent(newEntry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private Node createFileDisplay(LinkedFileViewModel linkedFile) {
parsePdfMetadata.setTooltip(new Tooltip(Localization.lang("Parse Metadata from PDF.")));
parsePdfMetadata.visibleProperty().bind(linkedFile.isOfflinePdfProperty());
parsePdfMetadata.setOnAction(event -> {
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService);
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences());
linkedFile.parsePdfMetadataAndShowMergeDialog();
});
parsePdfMetadata.getStyleClass().setAll("icon-button");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.jabref.gui.importer;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.PreferencesService;

/**
* Metadata extraction from PDFs and plaintext works very well using Grobid, but we do not want to enable it by default
Expand All @@ -18,21 +17,19 @@ public class GrobidOptInDialogHelper {
* @param dialogService the DialogService to use
* @return if the user enabled Grobid, either in the past or after being asked by the dialog.
*/
public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService) {
PreferencesService preferences = Globals.prefs;
if (preferences.getImportSettingsPreferences().isGrobidEnabled()) {
public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService, ImporterPreferences preferences) {
if (preferences.isGrobidEnabled()) {
return true;
}
if (preferences.getImportSettingsPreferences().isGrobidOptOut()) {
if (preferences.isGrobidOptOut()) {
return false;
}
boolean grobidEnabled = dialogService.showConfirmationDialogWithOptOutAndWait(
Localization.lang("Remote services"),
Localization.lang("Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results."),
Localization.lang("Do not ask again"),
(optOut) -> preferences.storeImportSettingsPreferences(preferences.getImportSettingsPreferences().withGrobidOptOut(optOut))
);
preferences.storeImportSettingsPreferences(preferences.getImportSettingsPreferences().withGrobidEnabled(grobidEnabled));
(optOut) -> preferences.grobidOptOutProperty().setValue(optOut));
preferences.grobidEnabledProperty().setValue(grobidEnabled);
return grobidEnabled;
}
}
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/importer/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ private List<ImportFormatReader.UnknownFormatImport> doImport(List<Path> files)
if (importer.isEmpty()) {
// Unknown format:
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> {
if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService())) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImportSettingsPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
}
frame.getDialogService().notify(Localization.lang("Importing in unknown format") + "...");
});
// This import method never throws an IOException:
imports.add(Globals.IMPORT_FORMAT_READER.importUnknownFormat(filename, Globals.getFileUpdateMonitor()));
} else {
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> {
if (importer.get() instanceof PdfGrobidImporter || importer.get() instanceof PdfMergeMetadataImporter && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService())) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImportSettingsPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
if (importer.get() instanceof PdfGrobidImporter || importer.get() instanceof PdfMergeMetadataImporter && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
}
frame.getDialogService().notify(Localization.lang("Importing in %0 format", importer.get().getName()) + "...");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AppearanceTabViewModel implements PreferenceTabViewModel {

private final DialogService dialogService;
private final PreferencesService preferences;
private final AppearancePreferences initialAppearancePreferences;
private final AppearancePreferences appearancePreferences;

private final Validator fontSizeValidator;
private final Validator customPathToThemeValidator;
Expand All @@ -51,7 +51,7 @@ public class AppearanceTabViewModel implements PreferenceTabViewModel {
public AppearanceTabViewModel(DialogService dialogService, PreferencesService preferences) {
this.dialogService = dialogService;
this.preferences = preferences;
this.initialAppearancePreferences = preferences.getAppearancePreferences();
this.appearancePreferences = preferences.getAppearancePreferences();

fontSizeValidator = new FunctionBasedValidator<>(
fontSizeProperty,
Expand All @@ -78,10 +78,10 @@ public AppearanceTabViewModel(DialogService dialogService, PreferencesService pr

@Override
public void setValues() {
fontOverrideProperty.setValue(initialAppearancePreferences.shouldOverrideDefaultFontSize());
fontSizeProperty.setValue(String.valueOf(initialAppearancePreferences.getMainFontSize()));
fontOverrideProperty.setValue(appearancePreferences.shouldOverrideDefaultFontSize());
fontSizeProperty.setValue(String.valueOf(appearancePreferences.getMainFontSize()));

Theme currentTheme = initialAppearancePreferences.getTheme();
Theme currentTheme = appearancePreferences.getTheme();
if (currentTheme.getType() == Theme.Type.LIGHT) {
themeLightProperty.setValue(true);
themeDarkProperty.setValue(false);
Expand All @@ -100,35 +100,34 @@ public void setValues() {

@Override
public void storeSettings() {
if (initialAppearancePreferences.shouldOverrideDefaultFontSize() != fontOverrideProperty.getValue()) {
if (appearancePreferences.shouldOverrideDefaultFontSize() != fontOverrideProperty.getValue()) {
restartWarnings.add(Localization.lang("Override font settings"));
}

int newFontSize = Integer.parseInt(fontSizeProperty.getValue());
if (initialAppearancePreferences.getMainFontSize() != newFontSize) {
if (appearancePreferences.getMainFontSize() != newFontSize) {
restartWarnings.add(Localization.lang("Override font size"));
}

Theme newTheme = initialAppearancePreferences.getTheme();
if (themeLightProperty.getValue() && initialAppearancePreferences.getTheme().getType() != Theme.Type.LIGHT) {
Theme newTheme = appearancePreferences.getTheme();
if (themeLightProperty.getValue() && appearancePreferences.getTheme().getType() != Theme.Type.LIGHT) {
restartWarnings.add(Localization.lang("Theme changed to light theme."));
newTheme = new Theme("", preferences);
} else if (themeDarkProperty.getValue() && initialAppearancePreferences.getTheme().getType() != Theme.Type.DARK) {
} else if (themeDarkProperty.getValue() && appearancePreferences.getTheme().getType() != Theme.Type.DARK) {
restartWarnings.add(Localization.lang("Theme changed to dark theme."));
newTheme = new Theme(EMBEDDED_DARK_THEME_CSS, preferences);
} else if (themeCustomProperty.getValue() &&
(!initialAppearancePreferences.getTheme().getCssPathString()
.equalsIgnoreCase(customPathToThemeProperty.getValue())
|| initialAppearancePreferences.getTheme().getType() != Theme.Type.CUSTOM)) {
(!appearancePreferences.getTheme().getCssPathString()
.equalsIgnoreCase(customPathToThemeProperty.getValue())
|| appearancePreferences.getTheme().getType() != Theme.Type.CUSTOM)) {
restartWarnings.add(Localization.lang("Theme changed to a custom theme:") + " "
+ customPathToThemeProperty().getValue());
newTheme = new Theme(customPathToThemeProperty.getValue(), preferences);
}

preferences.storeAppearancePreference(new AppearancePreferences(
fontOverrideProperty.getValue(),
newFontSize,
newTheme));
appearancePreferences.setShouldOverrideDefaultFontSize(fontOverrideProperty.getValue());
appearancePreferences.setMainFontSize(newFontSize);
appearancePreferences.setTheme(newTheme);

preferences.updateTheme();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void storeSettings() {
.map(ImporterViewModel::getLogic)
.collect(Collectors.toSet()));
Globals.IMPORT_FORMAT_READER.resetImportFormats(
preferences.getImportSettingsPreferences(),
preferences.getImporterPreferences(),
preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(),
Globals.getFileUpdateMonitor());
Expand Down
Loading