Skip to content

Commit

Permalink
Merge pull request #8213 from JabRef/searchprefs
Browse files Browse the repository at this point in the history
 Observable preferences G (Search, AutoLink, ImportExport)
  • Loading branch information
Siedlerchr committed Nov 8, 2021
2 parents 1eaaf50 + 38c9f48 commit 583bf6f
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 205 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public void init() {
// Subscribe to the search
EasyBind.subscribe(stateManager.activeSearchQueryProperty(),
query -> {
if (prefs.getSearchPreferences().isKeepSearchString()) {
if (prefs.getSearchPreferences().shouldKeepSearchString()) {
for (LibraryTab tab : getLibraryTabs()) {
tab.setCurrentSearchQuery(query);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/cleanup/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void execute() {
Localization.lang("Autogenerate PDF Names"),
Localization.lang("Cancel"),
Localization.lang("Do not ask again"),
optOut -> preferences.storeAutoLinkPreferences(preferences.getAutoLinkPreferences()
.withAskAutoNamingPdfs(!optOut)));
optOut -> preferences.getAutoLinkPreferences().setAskAutoNamingPdfs(!optOut));
if (!confirmed) {
isCanceled = true;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public CreateModifyExporterDialogViewModel(ExporterViewModel exporter, DialogSer
public ExporterViewModel saveExporter() {
Path layoutFileDir = Path.of(layoutFile.get()).getParent();
if (layoutFileDir != null) {
String layoutFileDirString = layoutFileDir.toString();
preferences.storeImportExportPreferences(
preferences.getImportExportPreferences().withExportWorkingDirectory(Path.of(layoutFileDirString)));
preferences.getImportExportPreferences().setExportWorkingDirectory(layoutFileDir);
}

// Check that there are no empty strings.
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt

// Make sure we remember which filter was used, to set
// the default for next time:
preferences.storeImportExportPreferences(preferences.getImportExportPreferences()
.withLastExportExtension(format.getName())
.withExportWorkingDirectory(file.getParent()));
preferences.getImportExportPreferences().setLastExportExtension(format.getName());
preferences.getImportExportPreferences().setExportWorkingDirectory(file.getParent());

final List<BibEntry> finEntries = entries;
BackgroundTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private ExportResult exportToClipboard(Exporter exporter) throws Exception {
.getFileDirectories(preferences.getFilePreferences()));

// Add chosen export type to last used preference, to become default
preferences.storeImportExportPreferences(
preferences.getImportExportPreferences().withLastExportExtension(exporter.getName()));
preferences.getImportExportPreferences().setLastExportExtension(exporter.getName());

Path tmp = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/importer/ImportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ private void doImport(Path file, SortedSet<Importer> importers, FileChooser.Exte
ImportAction importMenu = new ImportAction(frame, openInNew, format.orElse(null), preferences);
importMenu.automatedImport(Collections.singletonList(file.toString()));
// Set last working dir for import
preferences.storeImportExportPreferences(preferences.getImportExportPreferences().withImportWorkingDirectory(file.getParent()));
preferences.getImportExportPreferences().setImportWorkingDirectory(file.getParent());
}
}
35 changes: 16 additions & 19 deletions src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public class FileTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty autosaveLocalLibraries = new SimpleBooleanProperty();

private final PreferencesService preferences;
private final ImportExportPreferences initialImportExportPreferences;
private final ImportExportPreferences importExportPreferences;

FileTabViewModel(PreferencesService preferences) {
this.preferences = preferences;
this.initialImportExportPreferences = preferences.getImportExportPreferences();
this.importExportPreferences = preferences.getImportExportPreferences();
}

@Override
public void setValues() {
openLastStartupProperty.setValue(preferences.shouldOpenLastFilesOnStartup());

noWrapFilesProperty.setValue(initialImportExportPreferences.getNonWrappableFields());
resolveStringsAllProperty.setValue(initialImportExportPreferences.shouldResolveStringsForAllStrings()); // Flipped around
resolveStringsBibTexProperty.setValue(initialImportExportPreferences.shouldResolveStringsForStandardBibtexFields());
resolveStringsExceptProperty.setValue(initialImportExportPreferences.getNonResolvableFields());
noWrapFilesProperty.setValue(importExportPreferences.getNonWrappableFields());
resolveStringsAllProperty.setValue(importExportPreferences.shouldResolveStringsForAllStrings()); // Flipped around
resolveStringsBibTexProperty.setValue(importExportPreferences.shouldResolveStringsForStandardBibtexFields());
resolveStringsExceptProperty.setValue(importExportPreferences.getNonResolvableFields());
newLineSeparatorListProperty.setValue(FXCollections.observableArrayList(NewLineSeparator.values()));
selectedNewLineSeparatorProperty.setValue(initialImportExportPreferences.getNewLineSeparator());
selectedNewLineSeparatorProperty.setValue(importExportPreferences.getNewLineSeparator());

alwaysReformatBibProperty.setValue(initialImportExportPreferences.shouldAlwaysReformatOnSave());
alwaysReformatBibProperty.setValue(importExportPreferences.shouldAlwaysReformatOnSave());

autosaveLocalLibraries.setValue(preferences.shouldAutosave());
}
Expand All @@ -55,17 +55,12 @@ public void setValues() {
public void storeSettings() {
preferences.storeOpenLastFilesOnStartup(openLastStartupProperty.getValue());

ImportExportPreferences newImportExportPreferences = new ImportExportPreferences(
noWrapFilesProperty.getValue().trim(),
resolveStringsBibTexProperty.getValue(),
resolveStringsAllProperty.getValue(),
resolveStringsExceptProperty.getValue().trim(),
selectedNewLineSeparatorProperty.getValue(),
alwaysReformatBibProperty.getValue(),
initialImportExportPreferences.getImportWorkingDirectory(),
initialImportExportPreferences.getLastExportExtension(),
initialImportExportPreferences.getExportWorkingDirectory());
preferences.storeImportExportPreferences(newImportExportPreferences);
importExportPreferences.setNonWrappableFields(noWrapFilesProperty.getValue().trim());
importExportPreferences.setResolveStringsForStandardBibtexFields(resolveStringsBibTexProperty.getValue());
importExportPreferences.setResolveStringsForAllStrings(resolveStringsAllProperty.getValue());
importExportPreferences.setNonResolvableFields(resolveStringsExceptProperty.getValue().trim());
importExportPreferences.setNewLineSeparator(selectedNewLineSeparatorProperty.getValue());
importExportPreferences.setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue());

preferences.storeShouldAutosave(autosaveLocalLibraries.getValue());
}
Expand All @@ -76,6 +71,8 @@ public BooleanProperty openLastStartupProperty() {
return openLastStartupProperty;
}

// ImportExport

public StringProperty noWrapFilesProperty() {
return noWrapFilesProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,15 @@ public void storeSettings() {
filePreferences.setDownloadLinkedFiles(filePreferences.shouldDownloadLinkedFiles()); // set in ImportEntriesViewModel

// Autolink preferences
AutoLinkPreferences.CitationKeyDependency citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.START;
if (autolinkFileExactBibtexProperty.getValue()) {
citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.EXACT;
if (autolinkFileStartsBibtexProperty.getValue()) {
preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.START);
} else if (autolinkFileExactBibtexProperty.getValue()) {
preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.EXACT);
} else if (autolinkUseRegexProperty.getValue()) {
citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.REGEX;
preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.REGEX);
}

preferences.storeAutoLinkPreferences(new AutoLinkPreferences(
citationKeyDependency,
autolinkRegexKeyProperty.getValue(),
initialAutoLinkPreferences.shouldAskAutoNamingPdfs(),
preferences.getKeywordDelimiter()));
preferences.getAutoLinkPreferences().setRegularExpression(autolinkRegexKeyProperty.getValue());
}

ValidationStatus mainFileDirValidationStatus() {
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Field;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
Expand Down Expand Up @@ -59,6 +60,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.SearchQuery;
import org.jabref.model.entry.Author;
import org.jabref.model.search.rules.SearchRules;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.SearchPreferences;

Expand Down Expand Up @@ -99,7 +101,7 @@ public class GlobalSearchBar extends HBox {
private final Validator regexValidator;
private final UndoManager undoManager;

private SearchPreferences searchPreferences;
private final SearchPreferences searchPreferences;

private final BooleanProperty globalSearchActive = new SimpleBooleanProperty(false);
private GlobalSearchResultDialog globalSearchResultDialog;
Expand Down Expand Up @@ -204,35 +206,31 @@ private void initSearchModifierButtons() {
regularExpressionButton.setTooltip(new Tooltip(Localization.lang("regular expression")));
initSearchModifierButton(regularExpressionButton);
regularExpressionButton.setOnAction(event -> {
searchPreferences = searchPreferences.withRegularExpression(regularExpressionButton.isSelected());
preferencesService.storeSearchPreferences(searchPreferences);
searchPreferences.setSearchFlag(SearchRules.SearchFlags.REGULAR_EXPRESSION, regularExpressionButton.isSelected());
performSearch();
});

caseSensitiveButton.setSelected(searchPreferences.isCaseSensitive());
caseSensitiveButton.setTooltip(new Tooltip(Localization.lang("Case sensitive")));
initSearchModifierButton(caseSensitiveButton);
caseSensitiveButton.setOnAction(event -> {
searchPreferences = searchPreferences.withCaseSensitive(caseSensitiveButton.isSelected());
preferencesService.storeSearchPreferences(searchPreferences);
searchPreferences.setSearchFlag(SearchRules.SearchFlags.CASE_SENSITIVE, caseSensitiveButton.isSelected());
performSearch();
});

fulltextButton.setSelected(searchPreferences.isFulltext());
fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search")));
initSearchModifierButton(fulltextButton);
fulltextButton.setOnAction(event -> {
searchPreferences = searchPreferences.withFulltext(fulltextButton.isSelected());
preferencesService.storeSearchPreferences(searchPreferences);
searchPreferences.setSearchFlag(SearchRules.SearchFlags.FULLTEXT, fulltextButton.isSelected());
performSearch();
});

keepSearchString.setSelected(searchPreferences.isKeepSearchString());
keepSearchString.setSelected(searchPreferences.shouldKeepSearchString());
keepSearchString.setTooltip(new Tooltip(Localization.lang("Keep search string across libraries")));
initSearchModifierButton(keepSearchString);
keepSearchString.setOnAction(evt -> {
searchPreferences = searchPreferences.withKeepSearchString(keepSearchString.isSelected());
preferencesService.storeSearchPreferences(searchPreferences);
searchPreferences.setSearchFlag(SearchRules.SearchFlags.KEEP_SEARCH_STRING, keepSearchString.isSelected());
performSearch();
});

Expand Down Expand Up @@ -390,7 +388,7 @@ public void setSearchTerm(String searchTerm) {
DefaultTaskExecutor.runInJavaFXThread(() -> searchField.setText(searchTerm));
}

private class SearchPopupSkin<T> implements Skin<AutoCompletePopup<T>> {
private static class SearchPopupSkin<T> implements Skin<AutoCompletePopup<T>> {

private final AutoCompletePopup<T> control;
private final ListView<T> suggestionList;
Expand All @@ -400,7 +398,7 @@ public SearchPopupSkin(AutoCompletePopup<T> control) {
this.control = control;
this.suggestionList = new ListView<>(control.getSuggestions());
this.suggestionList.getStyleClass().add("auto-complete-popup");
this.suggestionList.getStylesheets().add(AutoCompletionBinding.class.getResource("autocompletion.css").toExternalForm());
this.suggestionList.getStylesheets().add(Objects.requireNonNull(AutoCompletionBinding.class.getResource("autocompletion.css")).toExternalForm());
this.suggestionList.prefHeightProperty().bind(Bindings.min(control.visibleRowCountProperty(), Bindings.size(this.suggestionList.getItems())).multiply(24).add(18));
this.suggestionList.setCellFactory(TextFieldListCell.forListView(control.getConverter()));
this.suggestionList.prefWidthProperty().bind(control.prefWidthProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ public class GlobalSearchResultDialogViewModel {

private final BibDatabaseContext searchDatabaseContext = new BibDatabaseContext();
private final BooleanProperty keepOnTop = new SimpleBooleanProperty();
private SearchPreferences searchPreferences;

public GlobalSearchResultDialogViewModel(PreferencesService preferencesService) {
searchPreferences = preferencesService.getSearchPreferences();
SearchPreferences searchPreferences = preferencesService.getSearchPreferences();

keepOnTop.set(searchPreferences.isKeepWindowOnTop());
keepOnTop.set(searchPreferences.shouldKeepWindowOnTop());

EasyBind.subscribe(this.keepOnTop, selected -> {
searchPreferences = searchPreferences.withKeepGlobalSearchDialogOnTop(selected);
preferencesService.storeSearchPreferences(searchPreferences);
});
EasyBind.subscribe(this.keepOnTop, searchPreferences::setKeepWindowOnTop);
}

public BibDatabaseContext getSearchDatabaseContext() {
Expand Down
56 changes: 45 additions & 11 deletions src/main/java/org/jabref/logic/util/io/AutoLinkPreferences.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package org.jabref.logic.util.io;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class AutoLinkPreferences {

public enum CitationKeyDependency {
Expand All @@ -8,39 +15,66 @@ public enum CitationKeyDependency {
REGEX // Filenames matching a regular expression pattern
}

private final CitationKeyDependency citationKeyDependency;
private final String regularExpression;
private boolean askAutoNamingPdfs;
private final Character keywordDelimiter;
private final ObjectProperty<CitationKeyDependency> citationKeyDependency;
private final StringProperty regularExpression;
private final BooleanProperty askAutoNamingPdfs;
private final SimpleObjectProperty<Character> keywordDelimiter;

public AutoLinkPreferences(CitationKeyDependency citationKeyDependency,
String regularExpression,
boolean askAutoNamingPdfs,
Character keywordDelimiter) {
this.citationKeyDependency = citationKeyDependency;
this.regularExpression = regularExpression;
this.askAutoNamingPdfs = askAutoNamingPdfs;
this.keywordDelimiter = keywordDelimiter;
this.citationKeyDependency = new SimpleObjectProperty<>(citationKeyDependency);
this.regularExpression = new SimpleStringProperty(regularExpression);
this.askAutoNamingPdfs = new SimpleBooleanProperty(askAutoNamingPdfs);
this.keywordDelimiter = new SimpleObjectProperty<>(keywordDelimiter);
}

public CitationKeyDependency getCitationKeyDependency() {
return citationKeyDependency.getValue();
}

public ObjectProperty<CitationKeyDependency> citationKeyDependencyProperty() {
return citationKeyDependency;
}

public void setCitationKeyDependency(CitationKeyDependency citationKeyDependency) {
this.citationKeyDependency.set(citationKeyDependency);
}

public String getRegularExpression() {
return regularExpression.getValue();
}

public StringProperty regularExpressionProperty() {
return regularExpression;
}

public void setRegularExpression(String regularExpression) {
this.regularExpression.set(regularExpression);
}

public boolean shouldAskAutoNamingPdfs() {
return askAutoNamingPdfs.getValue();
}

public BooleanProperty askAutoNamingPdfsProperty() {
return askAutoNamingPdfs;
}

public AutoLinkPreferences withAskAutoNamingPdfs(boolean shouldAskAutoNamingPdfs) {
this.askAutoNamingPdfs = shouldAskAutoNamingPdfs;
return this;
public void setAskAutoNamingPdfs(boolean askAutoNamingPdfs) {
this.askAutoNamingPdfs.set(askAutoNamingPdfs);
}

public Character getKeywordDelimiter() {
return keywordDelimiter.getValue();
}

public SimpleObjectProperty<Character> keywordDelimiterProperty() {
return keywordDelimiter;
}

public void setKeywordDelimiter(Character keywordDelimiter) {
this.keywordDelimiter.set(keywordDelimiter);
}
}
Loading

0 comments on commit 583bf6f

Please sign in to comment.