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 for issue 9091 - store merge entries toolbar configuration #9712

Merged
merged 23 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d0cd71e
Refactor out PlainTextOrDiff Enum(?); Use guiPreferences; add mergePl…
dragos222 Mar 26, 2023
998ac47
Update preference; remove guiPreference redundant objects
dragos222 Mar 26, 2023
1e52e74
Update jabrefPreferences and GuiPreferences for all mergeentries thre…
dragos222 Mar 26, 2023
6a2222f
Stop using record ShowDiffConfig; use preferences for diffViewComboBox
dragos222 Mar 26, 2023
9bda40b
Remove redundant call functions; add easybind listener to guipreferen…
dragos222 Mar 26, 2023
a137fe4
Default value for highlight words TRUE; set the values for highlight …
dragos222 Mar 26, 2023
8722fa1
Remove redundant method & method call; remove unused var
dragos222 Mar 26, 2023
369104f
Only save merge toolbar config when merge entries button is pressed
dragos222 Mar 28, 2023
2f832e7
Readd deletions; fix typo in GuiPreferences
dragos222 Mar 28, 2023
062d727
Fix typo
dragos222 Mar 28, 2023
92feafe
Add change to the changelog
dragos222 Mar 28, 2023
98ddc4a
MergeEntriesDialog does not need toolbar object; delegate save gui pr…
dragos222 Mar 29, 2023
5e60321
Merge branch 'main' into fix-for-issue-9091-group3
Siedlerchr Mar 29, 2023
974b9ec
Enum parse using getIfPresent to prevent exception being thrown
dragos222 Mar 29, 2023
afeea04
Merge branch 'fix-for-issue-9091-group3' of https://github.com/dragos…
dragos222 Mar 29, 2023
fcfa16f
Store preference as boolean instead of enum
dragos222 Apr 1, 2023
cfc5830
Save three way merge view toolbar preferences in duplicateslverdialog
dragos222 Apr 1, 2023
db6d569
Fix typo
dragos222 Apr 1, 2023
7b636bf
Refactor
dragos222 Apr 1, 2023
9994c57
Refactor ThreeWayMergeToolbar
HoussemNasri Apr 1, 2023
b382d39
Save configuration regardless of the action performed (cancel included)
HoussemNasri Apr 1, 2023
98255f0
Merge remote-tracking branch 'upstream/main' into fix-for-issue-9091-…
HoussemNasri Apr 1, 2023
193aebe
Fix CitationStyleTest#testDefaultCitation test
HoussemNasri Apr 2, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the command line export using `--exportMatches` flag does not create an output bib file [#9581](https://github.com/JabRef/jabref/issues/9581)
- We fixed an issue where custom field in the custom entry types could not be set to mulitline [#9609](https://github.com/JabRef/jabref/issues/9609)
- We fixed an issue where the Office XML exporter did not resolve BibTeX-Strings when exporting entries [forum#3741](https://discourse.jabref.org/t/exporting-bibtex-constant-strings-to-ms-office-2007-xml/3741)
- We fixed an issue where the Merge Entries Toolbar configuration was not saved after hitting 'Merge Entries' button [#9091](https://github.com/JabRef/jabref/issues/9091)
- We fixed an issue where the password is saved locally if user wants to use proxy with authentication [#8055](https://github.com/JabRef/jabref/issues/8055)
- JabRef is now more relaxed when parsing field content: In case a field content ended with `\`, the combination `\}` was treated as plain `}`. [#9668](https://github.com/JabRef/jabref/issues/9668)
- We resolved an issue that cut off the number of group entries when it exceedet four digits. [#8797](https://github.com/JabRef/jabref/issues/8797)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
this.setResultConverter(button -> {
// Updates the window state on button press
stateManager.setDialogWindowState(getClass().getSimpleName(), new DialogWindowState(this.getX(), this.getY(), this.getDialogPane().getHeight(), this.getDialogPane().getWidth()));
threeWayMerge.saveConfiguration();

if (button.equals(first)) {
return DuplicateResolverResult.KEEP_LEFT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private void init() {
ButtonType replaceEntries = new ButtonType(Localization.lang("Merge entries"), ButtonBar.ButtonData.OK_DONE);
this.getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, replaceEntries);
this.setResultConverter(buttonType -> {
threeWayMergeView.saveConfiguration();
if (buttonType.equals(replaceEntries)) {
return new EntriesMergeResult(one, two, threeWayMergeView.getLeftEntry(), threeWayMergeView.getRightEntry(), threeWayMergeView.getMergedEntry());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ public BibEntry getLeftEntry() {
public BibEntry getRightEntry() {
return viewModel.getRightEntry();
}

public void saveConfiguration() {
toolbar.saveToolbarConfiguration();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.jabref.gui.mergeentries.newmergedialog.DiffMethod;
import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.DiffHighlighter.BasicDiffMethod;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.GuiPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import com.google.common.base.Enums;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.EasyBinding;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -66,7 +68,7 @@ public ThreeWayMergeToolbar() {
public void initialize() {
showDiff = EasyBind.map(plainTextOrDiffComboBox.valueProperty(), plainTextOrDiff -> plainTextOrDiff == PlainTextOrDiff.Diff);
plainTextOrDiffComboBox.getItems().addAll(PlainTextOrDiff.values());
plainTextOrDiffComboBox.getSelectionModel().select(PlainTextOrDiff.Diff);

plainTextOrDiffComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(PlainTextOrDiff plainTextOrDiff) {
Expand All @@ -81,7 +83,7 @@ public PlainTextOrDiff fromString(String string) {

diffViewComboBox.disableProperty().bind(notShowDiffProperty());
diffViewComboBox.getItems().addAll(DiffView.values());
diffViewComboBox.getSelectionModel().select(DiffView.UNIFIED);

diffViewComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(DiffView diffView) {
Expand All @@ -105,11 +107,30 @@ public DiffView fromString(String string) {
}
}));

diffHighlightingMethodToggleGroup.selectToggle(highlightWordsRadioButton);
plainTextOrDiffComboBox.valueProperty().set(PlainTextOrDiff.Diff);

onlyShowChangedFieldsCheck.selectedProperty().bindBidirectional(preferencesService.getGuiPreferences().mergeShowChangedFieldOnlyProperty());
onlyShowChangedFields.bind(onlyShowChangedFieldsCheck.selectedProperty());

loadSavedConfiguration();
}

private void loadSavedConfiguration() {
GuiPreferences guiPreferences = preferencesService.getGuiPreferences();

PlainTextOrDiff plainTextOrDiffPreference = guiPreferences.getMergeShouldShowDiff() ? PlainTextOrDiff.Diff : PlainTextOrDiff.PLAIN_TEXT;
plainTextOrDiffComboBox.getSelectionModel().select(plainTextOrDiffPreference);

DiffView diffViewPreference = guiPreferences.getMergeShouldShowUnifiedDiff() ? DiffView.UNIFIED : DiffView.SPLIT;
diffViewComboBox.getSelectionModel().select(diffViewPreference);

diffHighlightingMethodToggleGroup.selectToggle(guiPreferences.getMergeHighlightWords() ? highlightWordsRadioButton : highlightCharactersRadioButtons);
}

public void saveToolbarConfiguration() {
preferencesService.getGuiPreferences().setMergeShouldShowDiff(plainTextOrDiffComboBox.getValue() == PlainTextOrDiff.Diff);
preferencesService.getGuiPreferences().setMergeShouldShowUnifiedDiff(diffViewComboBox.getValue() == DiffView.UNIFIED);

boolean highlightWordsRadioButtonValue = diffHighlightingMethodToggleGroup.getSelectedToggle().equals(highlightWordsRadioButton);
preferencesService.getGuiPreferences().setMergeHighlightWords(highlightWordsRadioButtonValue);
}

public ObjectProperty<DiffView> diffViewProperty() {
Expand Down Expand Up @@ -185,6 +206,10 @@ public enum PlainTextOrDiff {
this.value = value;
}

public static PlainTextOrDiff parse(String name) {
return Enums.getIfPresent(PlainTextOrDiff.class, name).or(Diff);
}

public String getValue() {
return value;
}
Expand All @@ -203,6 +228,10 @@ public enum DiffView {
this.value = value;
}

public static DiffView parse(String name) {
return Enums.getIfPresent(DiffView.class, name).or(UNIFIED);
}

public String getValue() {
return value;
}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/org/jabref/preferences/GuiPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class GuiPreferences {

private final StringProperty lastSelectedIdBasedFetcher;
private final ObjectProperty<DiffMode> mergeDiffMode;
private final BooleanProperty mergeShouldShowDiff;
private final BooleanProperty mergeShouldShowUnifiedDiff;
private final BooleanProperty mergeHighlightWords;
private final BooleanProperty mergeShowChangedFieldsOnly;
private final DoubleProperty sidePaneWidth;

Expand All @@ -46,6 +49,9 @@ public GuiPreferences(double positionX,
FileHistory fileHistory,
String lastSelectedIdBasedFetcher,
DiffMode mergeDiffMode,
boolean mergeShouldShowDiff,
boolean mergeShouldShowUnifiedDiff,
boolean mergeHighlightWords,
double sidePaneWidth,
boolean mergeShowChangedFieldsOnly) {
this.positionX = new SimpleDoubleProperty(positionX);
Expand All @@ -57,6 +63,10 @@ public GuiPreferences(double positionX,
this.lastFocusedFile = new SimpleObjectProperty<>(lastFocusedFile);
this.lastSelectedIdBasedFetcher = new SimpleStringProperty(lastSelectedIdBasedFetcher);
this.mergeDiffMode = new SimpleObjectProperty<>(mergeDiffMode);
this.mergeShouldShowDiff = new SimpleBooleanProperty(mergeShouldShowDiff);
this.mergeShouldShowUnifiedDiff = new SimpleBooleanProperty(mergeShouldShowUnifiedDiff);
this.mergeHighlightWords = new SimpleBooleanProperty(mergeHighlightWords);

this.sidePaneWidth = new SimpleDoubleProperty(sidePaneWidth);
this.fileHistory = fileHistory;
this.mergeShowChangedFieldsOnly = new SimpleBooleanProperty(mergeShowChangedFieldsOnly);
Expand Down Expand Up @@ -170,6 +180,42 @@ public void setMergeDiffMode(DiffMode mergeDiffMode) {
this.mergeDiffMode.set(mergeDiffMode);
}

public boolean getMergeShouldShowDiff() {
return mergeShouldShowDiff.get();
}

public BooleanProperty mergeShouldShowDiffProperty() {
return mergeShouldShowDiff;
}

public void setMergeShouldShowDiff(boolean mergeShouldShowDiff) {
this.mergeShouldShowDiff.set(mergeShouldShowDiff);
}

public boolean getMergeShouldShowUnifiedDiff() {
return mergeShouldShowUnifiedDiff.get();
}

public BooleanProperty mergeShouldShowUnifiedDiffProperty() {
return mergeShouldShowUnifiedDiff;
}

public void setMergeShouldShowUnifiedDiff(boolean mergeShouldShowUnifiedDiff) {
this.mergeShouldShowUnifiedDiff.set(mergeShouldShowUnifiedDiff);
}

public boolean getMergeHighlightWords() {
return mergeHighlightWords.get();
}

public BooleanProperty mergeHighlightWordsProperty() {
return mergeHighlightWords;
}

public void setMergeHighlightWords(boolean mergeHighlightsWords) {
this.mergeHighlightWords.set(mergeHighlightsWords);
}

public double getSidePaneWidth() {
return sidePaneWidth.get();
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ public class JabRefPreferences implements PreferencesService {

// merge related
public static final String MERGE_ENTRIES_DIFF_MODE = "mergeEntriesDiffMode";
public static final String MERGE_ENTRIES_SHOULD_SHOW_DIFF = "mergeEntriesShouldShowDiff";
public static final String MERGE_ENTRIES_SHOULD_SHOW_UNIFIED_DIFF = "mergeEntriesShouldShowUnifiedDiff";
public static final String MERGE_ENTRIES_HIGHLIGHT_WORDS = "mergeEntriesHighlightWords";


public static final String MERGE_SHOW_ONLY_CHANGED_FIELDS = "mergeShowOnlyChangedFields";

public static final String CUSTOM_EXPORT_FORMAT = "customExportFormat";
Expand Down Expand Up @@ -587,6 +592,9 @@ private JabRefPreferences() {
defaults.put(DEFAULT_SHOW_SOURCE, Boolean.FALSE);

defaults.put(MERGE_ENTRIES_DIFF_MODE, DiffMode.WORD.name());
defaults.put(MERGE_ENTRIES_SHOULD_SHOW_DIFF, Boolean.TRUE);
defaults.put(MERGE_ENTRIES_SHOULD_SHOW_UNIFIED_DIFF, Boolean.TRUE);
defaults.put(MERGE_ENTRIES_HIGHLIGHT_WORDS, Boolean.TRUE);
defaults.put(MERGE_SHOW_ONLY_CHANGED_FIELDS, Boolean.FALSE);

defaults.put(SHOW_RECOMMENDATIONS, Boolean.TRUE);
Expand Down Expand Up @@ -2510,6 +2518,9 @@ public GuiPreferences getGuiPreferences() {
getFileHistory(),
get(ID_ENTRY_GENERATOR),
DiffMode.parse(get(MERGE_ENTRIES_DIFF_MODE)),
getBoolean(MERGE_ENTRIES_SHOULD_SHOW_DIFF),
getBoolean(MERGE_ENTRIES_SHOULD_SHOW_UNIFIED_DIFF),
getBoolean(MERGE_ENTRIES_HIGHLIGHT_WORDS),
getDouble(SIDE_PANE_WIDTH),
getBoolean(MERGE_SHOW_ONLY_CHANGED_FIELDS));

Expand All @@ -2535,6 +2546,9 @@ public GuiPreferences getGuiPreferences() {
guiPreferences.getFileHistory().addListener((InvalidationListener) change -> storeFileHistory(guiPreferences.getFileHistory()));
EasyBind.listen(guiPreferences.lastSelectedIdBasedFetcherProperty(), (obs, oldValue, newValue) -> put(ID_ENTRY_GENERATOR, newValue));
EasyBind.listen(guiPreferences.mergeDiffModeProperty(), (obs, oldValue, newValue) -> put(MERGE_ENTRIES_DIFF_MODE, newValue.name()));
EasyBind.listen(guiPreferences.mergeShouldShowDiffProperty(), (obs, oldValue, newValue) -> putBoolean(MERGE_ENTRIES_SHOULD_SHOW_DIFF, newValue));
EasyBind.listen(guiPreferences.mergeShouldShowUnifiedDiffProperty(), (obs, oldValue, newValue) -> putBoolean(MERGE_ENTRIES_SHOULD_SHOW_UNIFIED_DIFF, newValue));
EasyBind.listen(guiPreferences.mergeHighlightWordsProperty(), (obs, oldValue, newValue) -> putBoolean(MERGE_ENTRIES_HIGHLIGHT_WORDS, newValue));
EasyBind.listen(guiPreferences.sidePaneWidthProperty(), (obs, oldValue, newValue) -> putDouble(SIDE_PANE_WIDTH, newValue.doubleValue()));
EasyBind.listen(guiPreferences.mergeShowChangedFieldOnlyProperty(), (obs, oldValue, newValue) -> putBoolean(MERGE_SHOW_ONLY_CHANGED_FIELDS, newValue));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void testDefaultCitation() {
String citation = CitationStyleGenerator.generateCitation(TestEntry.getTestEntry(), CitationStyle.getDefault().getSource(), CitationStyleOutputFormat.HTML, context, new BibEntryTypesManager());

// if the default citation style changes this has to be modified
String expected = " <div class=\"csl-entry\">\n"
+ " <div class=\"csl-left-margin\">[1]</div><div class=\"csl-right-inline\">B. Smith, B. Jones, and J. Williams, &ldquo;Title of the test entry,&rdquo; <span style=\"font-style: italic\">BibTeX Journal</span>, vol. 34, no. 3, pp. 45&ndash;67, 2016-07, doi: 10.1001/bla.blubb.</div>\n"
+ " </div>\n"
+ "";
String expected = """
<div class="csl-entry">
<div class="csl-left-margin">[1]</div><div class="csl-right-inline">B. Smith, B. Jones, and J. Williams, &ldquo;Title of the test entry,&rdquo; <span style="font-style: italic">BibTeX Journal</span>, vol. 34, no. 3, pp. 45&ndash;67, Jul. 2016, doi: 10.1001/bla.blubb.</div>
</div>
""";

assertEquals(expected, citation);
}
Expand Down