Skip to content

Commit

Permalink
Move generate key option to citation key preference tab (#12436)
Browse files Browse the repository at this point in the history
* Move 'Generate key on import' option from WebSearch tab to CitationKeyTab

* Takes preferences as arguments

* Add correct comment

* Fix javadoc link, shift `importerPreferences` declaration below

---------

Co-authored-by: Subhramit Basu Bhowmick <[email protected]>
  • Loading branch information
priyanshu16095 and subhramit authored Feb 6, 2025
1 parent 9e9b961 commit 4c9c821
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Changed

- We moved the "Generate a new key for imported entries" option from the "Web search" tab to the "Citation key generator" tab in preferences. [#12436](https://github.com/JabRef/jabref/pull/12436)
- We improved the offline parsing of BibTeX data from PDF-documents. [#12278](https://github.com/JabRef/jabref/issues/12278)
- The tab bar is now hidden when only one library is open. [#9971](https://github.com/JabRef/jabref/issues/9971)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private void addToGroups(List<BibEntry> entries, Collection<GroupTreeNode> group
* @param entries entries to generate keys for
*/
private void generateKeys(List<BibEntry> entries) {
if (!preferences.getImporterPreferences().isGenerateNewKeyOnImport()) {
if (!preferences.getImporterPreferences().shouldGenerateNewKeyOnImport()) {
return;
}
CitationKeyGenerator keyGenerator = new CitationKeyGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</padding>
</CheckBox>
<CheckBox fx:id="generateOnSave" text="%Generate keys before saving (for entries without a key)"/>
<CheckBox fx:id="generateNewKeyOnImport" text="%Generate a new key for imported entries (overwriting their default)"/>

<Label text="%Letters after duplicate generated keys"/>
<VBox spacing="10.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class CitationKeyPatternTab extends AbstractPreferenceTabView<CitationKey
@FXML private CheckBox overwriteAllow;
@FXML private CheckBox overwriteWarning;
@FXML private CheckBox generateOnSave;
@FXML private CheckBox generateNewKeyOnImport;
@FXML private RadioButton letterStartA;
@FXML private RadioButton letterStartB;
@FXML private RadioButton letterAlwaysAdd;
Expand All @@ -45,11 +46,12 @@ public String getTabName() {
}

public void initialize() {
this.viewModel = new CitationKeyPatternTabViewModel(preferences.getCitationKeyPatternPreferences());
this.viewModel = new CitationKeyPatternTabViewModel(preferences.getCitationKeyPatternPreferences(), preferences.getImporterPreferences());

overwriteAllow.selectedProperty().bindBidirectional(viewModel.overwriteAllowProperty());
overwriteWarning.selectedProperty().bindBidirectional(viewModel.overwriteWarningProperty());
generateOnSave.selectedProperty().bindBidirectional(viewModel.generateOnSaveProperty());
generateNewKeyOnImport.selectedProperty().bindBidirectional(viewModel.generateKeyOnImportProperty());
letterStartA.selectedProperty().bindBidirectional(viewModel.letterStartAProperty());
letterStartB.selectedProperty().bindBidirectional(viewModel.letterStartBProperty());
letterAlwaysAdd.selectedProperty().bindBidirectional(viewModel.letterAlwaysAddProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.citationkeypattern.GlobalCitationKeyPatterns;
import org.jabref.logic.importer.ImporterPreferences;

public class CitationKeyPatternTabViewModel implements PreferenceTabViewModel {

private final BooleanProperty overwriteAllowProperty = new SimpleBooleanProperty();
private final BooleanProperty overwriteWarningProperty = new SimpleBooleanProperty();
private final BooleanProperty generateOnSaveProperty = new SimpleBooleanProperty();
private final BooleanProperty generateKeyOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty letterStartAProperty = new SimpleBooleanProperty();
private final BooleanProperty letterStartBProperty = new SimpleBooleanProperty();
private final BooleanProperty letterAlwaysAddProperty = new SimpleBooleanProperty();
Expand All @@ -36,15 +38,25 @@ public class CitationKeyPatternTabViewModel implements PreferenceTabViewModel {

private final CitationKeyPatternPreferences keyPatternPreferences;

public CitationKeyPatternTabViewModel(CitationKeyPatternPreferences keyPatternPreferences) {
/**
* The preference for whether to use the key generator on import is different from how it is configured.
* In the UI, there is no better place to put the option than the Citation Key Generator tab.
* However, shifting the preference to {@link CitationKeyPatternPreferences} would break the abstraction or hierarchy.
* Hence, we keep the preference in {@link ImporterPreferences}, but for the UI, we initialize it here.
*/
private final ImporterPreferences importerPreferences;

public CitationKeyPatternTabViewModel(CitationKeyPatternPreferences keyPatternPreferences, ImporterPreferences importerPreferences) {
this.keyPatternPreferences = keyPatternPreferences;
this.importerPreferences = importerPreferences;
}

@Override
public void setValues() {
overwriteAllowProperty.setValue(!keyPatternPreferences.shouldAvoidOverwriteCiteKey());
overwriteWarningProperty.setValue(keyPatternPreferences.shouldWarnBeforeOverwriteCiteKey());
generateOnSaveProperty.setValue(keyPatternPreferences.shouldGenerateCiteKeysBeforeSaving());
generateKeyOnImportProperty.setValue(importerPreferences.shouldGenerateNewKeyOnImport());

if (keyPatternPreferences.getKeySuffix()
== CitationKeyPatternPreferences.KeySuffix.ALWAYS) {
Expand Down Expand Up @@ -97,6 +109,7 @@ public void storeSettings() {
keyPatternPreferences.setAvoidOverwriteCiteKey(!overwriteAllowProperty.getValue());
keyPatternPreferences.setWarnBeforeOverwriteCiteKey(overwriteWarningProperty.getValue());
keyPatternPreferences.setGenerateCiteKeysBeforeSaving(generateOnSaveProperty.getValue());
importerPreferences.setGenerateNewKeyOnImport(generateKeyOnImportProperty.getValue());
keyPatternPreferences.setKeySuffix(keySuffix);
keyPatternPreferences.setKeyPatternRegex(keyPatternRegexProperty.getValue());
keyPatternPreferences.setKeyPatternReplacement(keyPatternReplacementProperty.getValue());
Expand All @@ -116,6 +129,10 @@ public BooleanProperty generateOnSaveProperty() {
return generateOnSaveProperty;
}

public BooleanProperty generateKeyOnImportProperty() {
return generateKeyOnImportProperty;
}

public BooleanProperty letterStartAProperty() {
return letterStartAProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<Label styleClass="sectionHeader" text="%General"/>
<CheckBox fx:id="enableWebSearch" text="%Enable web search"/>
<CheckBox fx:id="generateNewKeyOnImport" text="%Generate a new key for imported entries (overwriting their default)"/>
<CheckBox fx:id="warnAboutDuplicatesOnImport" text="%Warn about duplicates on import"/>
<CheckBox fx:id="downloadLinkedOnlineFiles" text="%Download linked online files"/>
<CheckBox fx:id="keepDownloadUrl" text="%Store url for downloaded file" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class WebSearchTab extends AbstractPreferenceTabView<WebSearchTabViewModel> implements PreferencesTab {

@FXML private CheckBox enableWebSearch;
@FXML private CheckBox generateNewKeyOnImport;
@FXML private CheckBox warnAboutDuplicatesOnImport;
@FXML private CheckBox downloadLinkedOnlineFiles;
@FXML private CheckBox keepDownloadUrl;
Expand Down Expand Up @@ -73,7 +72,6 @@ public void initialize() {
this.viewModel = new WebSearchTabViewModel(preferences, dialogService, refAiEnabled);

enableWebSearch.selectedProperty().bindBidirectional(viewModel.enableWebSearchProperty());
generateNewKeyOnImport.selectedProperty().bindBidirectional(viewModel.generateKeyOnImportProperty());
warnAboutDuplicatesOnImport.selectedProperty().bindBidirectional(viewModel.warnAboutDuplicatesOnImportProperty());
downloadLinkedOnlineFiles.selectedProperty().bindBidirectional(viewModel.shouldDownloadLinkedOnlineFiles());
keepDownloadUrl.selectedProperty().bindBidirectional(viewModel.shouldKeepDownloadUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty enableWebSearchProperty = new SimpleBooleanProperty();
private final BooleanProperty generateKeyOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty warnAboutDuplicatesOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty shouldDownloadLinkedOnlineFiles = new SimpleBooleanProperty();
private final BooleanProperty shouldkeepDownloadUrl = new SimpleBooleanProperty();
Expand Down Expand Up @@ -126,7 +125,6 @@ private void setupPlainCitationParsers(CliPreferences preferences) {
@Override
public void setValues() {
enableWebSearchProperty.setValue(importerPreferences.areImporterEnabled());
generateKeyOnImportProperty.setValue(importerPreferences.isGenerateNewKeyOnImport());
warnAboutDuplicatesOnImportProperty.setValue(importerPreferences.shouldWarnAboutDuplicatesOnImport());
shouldDownloadLinkedOnlineFiles.setValue(filePreferences.shouldDownloadLinkedFiles());
shouldkeepDownloadUrl.setValue(filePreferences.shouldKeepDownloadUrl());
Expand Down Expand Up @@ -158,7 +156,6 @@ public void setValues() {
@Override
public void storeSettings() {
importerPreferences.setImporterEnabled(enableWebSearchProperty.getValue());
importerPreferences.setGenerateNewKeyOnImport(generateKeyOnImportProperty.getValue());
importerPreferences.setWarnAboutDuplicatesOnImport(warnAboutDuplicatesOnImportProperty.getValue());
filePreferences.setDownloadLinkedFiles(shouldDownloadLinkedOnlineFiles.getValue());
filePreferences.setKeepDownloadUrl(shouldkeepDownloadUrl.getValue());
Expand All @@ -184,10 +181,6 @@ public BooleanProperty enableWebSearchProperty() {
return enableWebSearchProperty;
}

public BooleanProperty generateKeyOnImportProperty() {
return generateKeyOnImportProperty;
}

public ListProperty<PlainCitationParserChoice> plainCitationParsers() {
return plainCitationParsers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void setImporterEnabled(boolean importerEnabled) {
this.importerEnabled.set(importerEnabled);
}

public boolean isGenerateNewKeyOnImport() {
public boolean shouldGenerateNewKeyOnImport() {
return generateNewKeyOnImport.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setUp() {
when(preferences.getImportFormatPreferences()).thenReturn(importFormatPreferences);

ImporterPreferences importerPreferences = mock(ImporterPreferences.class, Answers.RETURNS_DEEP_STUBS);
when(importerPreferences.isGenerateNewKeyOnImport()).thenReturn(false);
when(importerPreferences.shouldGenerateNewKeyOnImport()).thenReturn(false);
when(preferences.getImporterPreferences()).thenReturn(importerPreferences);

FieldPreferences fieldPreferences = mock(FieldPreferences.class);
Expand Down

0 comments on commit 4c9c821

Please sign in to comment.