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

Draft Pull Request about #10615 Copy cite command should respect preferences #10690

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
4 changes: 2 additions & 2 deletions src/jmh/java/org/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.jabref.gui.Globals;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyGenerationPreferences;
import org.jabref.logic.exporter.BibWriter;
import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
Expand Down Expand Up @@ -84,7 +84,7 @@ private StringWriter getOutputWriter() throws IOException {
bibWriter,
mock(SelfContainedSaveConfiguration.class),
mock(FieldPreferences.class),
mock(CitationKeyPatternPreferences.class),
mock(CitationKeyGenerationPreferences.class),
new BibEntryTypesManager());
databaseWriter.savePartOfDatabase(new BibDatabaseContext(database, new MetaData()), database.getEntries());
return outputWriter;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ private void saveDatabase(BibDatabase newBase, String subName) {
bibWriter,
saveConfiguration,
preferencesService.getFieldPreferences(),
preferencesService.getCitationKeyPatternPreferences(),
preferencesService.getCitationKeyGenerationPreferences(),
entryTypesManager);
databaseWriter.saveDatabase(new BibDatabaseContext(newBase));

Expand Down Expand Up @@ -717,7 +717,7 @@ private void regenerateCitationKeys(List<ParserResult> loaded) {

CitationKeyGenerator keyGenerator = new CitationKeyGenerator(
parserResult.getDatabaseContext(),
preferencesService.getCitationKeyPatternPreferences());
preferencesService.getCitationKeyGenerationPreferences());
for (BibEntry entry : database.getEntries()) {
keyGenerator.generateAndSetKey(entry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void performBackup(Path backupPath) {
bibWriter,
saveConfiguration,
preferences.getFieldPreferences(),
preferences.getCitationKeyPatternPreferences(),
preferences.getCitationKeyGenerationPreferences(),
entryTypesManager)
.saveDatabase(bibDatabaseContext);
backupFilesQueue.add(backupPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public void execute() {
}

public static boolean confirmOverwriteKeys(DialogService dialogService, PreferencesService preferencesService) {
if (preferencesService.getCitationKeyPatternPreferences().shouldWarnBeforeOverwriteCiteKey()) {
if (preferencesService.getCitationKeyGenerationPreferences().shouldWarnBeforeOverwriteCiteKey()) {
return dialogService.showConfirmationDialogWithOptOutAndWait(
Localization.lang("Overwrite keys"),
Localization.lang("One or more keys will be overwritten. Continue?"),
Localization.lang("Overwrite keys"),
Localization.lang("Cancel"),
Localization.lang("Do not ask again"),
optOut -> preferencesService.getCitationKeyPatternPreferences().setWarnBeforeOverwriteCiteKey(!optOut));
optOut -> preferencesService.getCitationKeyGenerationPreferences().setWarnBeforeOverwriteCiteKey(!optOut));
} else {
// Always overwrite keys by default
return true;
Expand All @@ -80,7 +80,7 @@ public static boolean confirmOverwriteKeys(DialogService dialogService, Preferen

private void checkOverwriteKeysChosen() {
// We don't want to generate keys for entries which already have one thus remove the entries
if (this.preferencesService.getCitationKeyPatternPreferences().shouldAvoidOverwriteCiteKey()) {
if (this.preferencesService.getCitationKeyGenerationPreferences().shouldAvoidOverwriteCiteKey()) {
entries.removeIf(BibEntry::hasCitationKey);
// if we're going to override some citation keys warn the user about it
} else if (entries.parallelStream().anyMatch(BibEntry::hasCitationKey)) {
Expand Down Expand Up @@ -110,7 +110,7 @@ protected Void call() {
// generate the new citation keys for each entry
compound = new NamedCompound(Localization.lang("Autogenerate citation keys"));
CitationKeyGenerator keyGenerator =
new CitationKeyGenerator(databaseContext, preferencesService.getCitationKeyPatternPreferences());
new CitationKeyGenerator(databaseContext, preferencesService.getCitationKeyGenerationPreferences());
int entriesDone = 0;
for (BibEntry entry : entries) {
keyGenerator.generateAndSetKey(entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public GenerateCitationKeySingleAction(BibEntry entry, BibDatabaseContext databa
this.preferencesService = preferencesService;
this.undoManager = undoManager;

if (preferencesService.getCitationKeyPatternPreferences().shouldAvoidOverwriteCiteKey()) {
if (preferencesService.getCitationKeyGenerationPreferences().shouldAvoidOverwriteCiteKey()) {
this.executable.bind(entry.getCiteKeyBinding().isEmpty());
}
}

@Override
public void execute() {
if (!entry.hasCitationKey() || GenerateCitationKeyAction.confirmOverwriteKeys(dialogService, preferencesService)) {
new CitationKeyGenerator(databaseContext, preferencesService.getCitationKeyPatternPreferences())
new CitationKeyGenerator(databaseContext, preferencesService.getCitationKeyGenerationPreferences())
.generateAndSetKey(entry)
.ifPresent(change -> undoManager.addEdit(new UndoableKeyChange(change)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CitationKeyPatternPanel() {

@FXML
private void initialize() {
viewModel = new CitationKeyPatternPanelViewModel(preferences.getCitationKeyPatternPreferences());
viewModel = new CitationKeyPatternPanelViewModel(preferences.getCitationKeyGenerationPreferences());

this.setEditable(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import javafx.collections.FXCollections;

import org.jabref.logic.citationkeypattern.AbstractCitationKeyPattern;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyGenerationPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.types.EntryType;
Expand All @@ -37,9 +37,9 @@ public class CitationKeyPatternPanelViewModel {
private final ListProperty<CitationKeyPatternPanelItemModel> patternListProperty = new SimpleListProperty<>();
private final ObjectProperty<CitationKeyPatternPanelItemModel> defaultItemProperty = new SimpleObjectProperty<>();

private final CitationKeyPatternPreferences keyPatternPreferences;
private final CitationKeyGenerationPreferences keyPatternPreferences;

public CitationKeyPatternPanelViewModel(CitationKeyPatternPreferences keyPatternPreferences) {
public CitationKeyPatternPanelViewModel(CitationKeyGenerationPreferences keyPatternPreferences) {
this.keyPatternPreferences = keyPatternPreferences;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/edit/CopyMoreAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void copyCiteKey() {
return;
}

String citeCommand = Optional.ofNullable(preferencesService.getExternalApplicationsPreferences().getCiteCommand())
String citeCommand = Optional.ofNullable(preferencesService.getExternalApplicationsPreferences().getCiteCommand().toString())
.filter(cite -> cite.contains("\\")) // must contain \
.orElse("\\cite");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private boolean saveDatabase(Path file, boolean selectedOnly, Charset encoding,
bibWriter,
saveConfiguration,
preferences.getFieldPreferences(),
preferences.getCitationKeyPatternPreferences(),
preferences.getCitationKeyGenerationPreferences(),
entryTypesManager);

if (selectedOnly) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ private void generateKeys(List<BibEntry> entries) {
return;
}
CitationKeyGenerator keyGenerator = new CitationKeyGenerator(
bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences()
bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyGenerationPreferences()
.getKeyPattern()),
bibDatabaseContext.getDatabase(),
preferencesService.getCitationKeyPatternPreferences());
preferencesService.getCitationKeyGenerationPreferences());
entries.forEach(keyGenerator::generateAndSetKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void execute() {
BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null"));
IntegrityCheck check = new IntegrityCheck(database,
preferencesService.getFilePreferences(),
preferencesService.getCitationKeyPatternPreferences(),
preferencesService.getCitationKeyGenerationPreferences(),
abbreviationRepository,
preferencesService.getEntryEditorPreferences().shouldAllowIntegerEditionBibtex());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setValues() {
bibEntryTypesManager.getAllTypes(databaseContext.getMetaData().getMode()
.orElse(preferencesService.getLibraryPreferences()
.getDefaultBibDatabaseMode())),
databaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences().getKeyPattern()));
databaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyGenerationPreferences().getKeyPattern()));
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setValues() {

@Override
public void storeSettings() {
DatabaseCitationKeyPattern newKeyPattern = new DatabaseCitationKeyPattern(preferencesService.getCitationKeyPatternPreferences().getKeyPattern());
DatabaseCitationKeyPattern newKeyPattern = new DatabaseCitationKeyPattern(preferencesService.getCitationKeyGenerationPreferences().getKeyPattern());

patternListProperty.forEach(item -> {
String patternString = item.getPattern();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyGenerationPreferences;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -545,7 +545,7 @@ private boolean checkThatEntriesHaveKeys(List<BibEntry> entries) {
Optional<BibDatabaseContext> databaseContext = stateManager.getActiveDatabase();
if (citePressed && databaseContext.isPresent()) {
// Generate keys
CitationKeyPatternPreferences prefs = preferencesService.getCitationKeyPatternPreferences();
CitationKeyGenerationPreferences prefs = preferencesService.getCitationKeyGenerationPreferences();
NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite"));
for (BibEntry entry : entries) {
if (entry.getCitationKey().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String getTabName() {
}

public void initialize() {
this.viewModel = new CitationKeyPatternTabViewModel(preferencesService.getCitationKeyPatternPreferences());
this.viewModel = new CitationKeyPatternTabViewModel(preferencesService.getCitationKeyGenerationPreferences());

overwriteAllow.selectedProperty().bindBidirectional(viewModel.overwriteAllowProperty());
overwriteWarning.selectedProperty().bindBidirectional(viewModel.overwriteWarningProperty());
Expand All @@ -68,7 +68,7 @@ public void setValues() {
viewModel.setValues();
bibtexKeyPatternTable.setValues(
Globals.entryTypesManager.getAllTypes(preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode()),
preferencesService.getCitationKeyPatternPreferences().getKeyPattern());
preferencesService.getCitationKeyGenerationPreferences().getKeyPattern());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.jabref.gui.commonfxcontrols.CitationKeyPatternPanelItemModel;
import org.jabref.gui.commonfxcontrols.CitationKeyPatternPanelViewModel;
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyGenerationPreferences;
import org.jabref.logic.citationkeypattern.GlobalCitationKeyPattern;

public class CitationKeyPatternTabViewModel implements PreferenceTabViewModel {
Expand All @@ -34,9 +34,9 @@ public class CitationKeyPatternTabViewModel implements PreferenceTabViewModel {
private final ObjectProperty<CitationKeyPatternPanelItemModel> defaultKeyPatternProperty = new SimpleObjectProperty<>(
new CitationKeyPatternPanelItemModel(new CitationKeyPatternPanelViewModel.DefaultEntryType(), ""));

private final CitationKeyPatternPreferences keyPatternPreferences;
private final CitationKeyGenerationPreferences keyPatternPreferences;

public CitationKeyPatternTabViewModel(CitationKeyPatternPreferences keyPatternPreferences) {
public CitationKeyPatternTabViewModel(CitationKeyGenerationPreferences keyPatternPreferences) {
this.keyPatternPreferences = keyPatternPreferences;
}

Expand All @@ -47,12 +47,12 @@ public void setValues() {
generateOnSaveProperty.setValue(keyPatternPreferences.shouldGenerateCiteKeysBeforeSaving());

if (keyPatternPreferences.getKeySuffix()
== CitationKeyPatternPreferences.KeySuffix.ALWAYS) {
== CitationKeyGenerationPreferences.KeySuffix.ALWAYS) {
letterAlwaysAddProperty.setValue(true);
letterStartAProperty.setValue(false);
letterStartBProperty.setValue(false);
} else if (keyPatternPreferences.getKeySuffix()
== CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_A) {
== CitationKeyGenerationPreferences.KeySuffix.SECOND_WITH_A) {
letterAlwaysAddProperty.setValue(false);
letterStartAProperty.setValue(true);
letterStartBProperty.setValue(false);
Expand Down Expand Up @@ -86,12 +86,12 @@ public void storeSettings() {
newKeyPattern.setDefaultValue(defaultKeyPatternProperty.getValue().getPattern());
}

CitationKeyPatternPreferences.KeySuffix keySuffix = CitationKeyPatternPreferences.KeySuffix.ALWAYS;
CitationKeyGenerationPreferences.KeySuffix keySuffix = CitationKeyGenerationPreferences.KeySuffix.ALWAYS;

if (letterStartAProperty.getValue()) {
keySuffix = CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_A;
keySuffix = CitationKeyGenerationPreferences.KeySuffix.SECOND_WITH_A;
} else if (letterStartBProperty.getValue()) {
keySuffix = CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_B;
keySuffix = CitationKeyGenerationPreferences.KeySuffix.SECOND_WITH_B;
}

keyPatternPreferences.setAvoidOverwriteCiteKey(!overwriteAllowProperty.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setValues() {
PushToApplications.getApplicationByName(initialPushToApplicationPreferences.getActiveApplicationName(), dialogService, preferences)
.orElse(new PushToEmacs(dialogService, preferences)));

citeCommandProperty.setValue(initialExternalApplicationPreferences.getCiteCommand());
citeCommandProperty.setValue(initialExternalApplicationPreferences.getCiteCommand().toString());
useCustomTerminalProperty.setValue(initialExternalApplicationPreferences.useCustomTerminal());
customTerminalCommandProperty.setValue(initialExternalApplicationPreferences.getCustomTerminalCommand());
useCustomFileBrowserProperty.setValue(initialExternalApplicationPreferences.useCustomFileBrowser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public AbstractPushToApplication(DialogService dialogService, PreferencesService
}

private void dissectCiteCommand() {
String preferencesCiteCommand = preferencesService.getExternalApplicationsPreferences().getCiteCommand();
System.out.println(preferencesService.getExternalApplicationsPreferences().getCiteCommand());
String preferencesCiteCommand = preferencesService.getExternalApplicationsPreferences().getCiteCommand().toString();

if (preferencesCiteCommand != null && preferencesCiteCommand.equals(cachedCiteCommand)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public LibraryTab openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnecti
DBMSSynchronizer synchronizer = new DBMSSynchronizer(
bibDatabaseContext,
preferencesService.getBibEntryPreferences().getKeywordSeparator(),
preferencesService.getCitationKeyPatternPreferences().getKeyPattern(),
preferencesService.getCitationKeyGenerationPreferences().getKeyPattern(),
fileUpdateMonitor);
bibDatabaseContext.convertToSharedDatabase(synchronizer);

Expand Down Expand Up @@ -203,7 +203,7 @@ public void openSharedDatabaseFromParserResult(ParserResult parserResult)
DBMSSynchronizer synchronizer = new DBMSSynchronizer(
bibDatabaseContext,
preferencesService.getBibEntryPreferences().getKeywordSeparator(),
preferencesService.getCitationKeyPatternPreferences().getKeyPattern(),
preferencesService.getCitationKeyGenerationPreferences().getKeyPattern(),
fileUpdateMonitor);
bibDatabaseContext.convertToSharedDatabase(synchronizer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public List<Difference> getDifferences(PreferencesService preferences) {
addToListIfDiff(changes, DifferenceType.ENCODING, originalMetaData.getEncoding(), newMetaData.getEncoding());
addToListIfDiff(changes, DifferenceType.SAVE_SORT_ORDER, originalMetaData.getSaveOrder(), newMetaData.getSaveOrder());
addToListIfDiff(changes, DifferenceType.KEY_PATTERNS,
originalMetaData.getCiteKeyPattern(preferences.getCitationKeyPatternPreferences().getKeyPattern()),
newMetaData.getCiteKeyPattern(preferences.getCitationKeyPatternPreferences().getKeyPattern()));
originalMetaData.getCiteKeyPattern(preferences.getCitationKeyGenerationPreferences().getKeyPattern()),
newMetaData.getCiteKeyPattern(preferences.getCitationKeyGenerationPreferences().getKeyPattern()));
addToListIfDiff(changes, DifferenceType.USER_FILE_DIRECTORY, originalMetaData.getUserFileDirectories(), newMetaData.getUserFileDirectories());
addToListIfDiff(changes, DifferenceType.LATEX_FILE_DIRECTORY, originalMetaData.getLatexFileDirectories(), newMetaData.getLatexFileDirectories());
addToListIfDiff(changes, DifferenceType.DEFAULT_KEY_PATTERN, originalMetaData.getDefaultCiteKeyPattern(), newMetaData.getDefaultCiteKeyPattern());
Expand Down
Loading
Loading