Skip to content

Commit 1d0a3d1

Browse files
adrosos89calixtus
andauthored
DonationPreferencesReset (#14439)
* DonationPreferences * Fix indentation for comments * Added new line for clearer separation --------- Co-authored-by: Carl Christian Snethlage <[email protected]>
1 parent 898bda6 commit 1d0a3d1

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

jabgui/src/main/java/org/jabref/gui/preferences/DonationPreferences.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ public DonationPreferences(boolean neverShowAgain, int lastShownEpochDay) {
1414
this.lastShownEpochDay.set(lastShownEpochDay);
1515
}
1616

17+
/// Creates object with default values
18+
private DonationPreferences() {
19+
this(
20+
false, // Donation never show again
21+
-1); // Donation last shown epoch day
22+
}
23+
24+
public static DonationPreferences getDefault() {
25+
return new DonationPreferences();
26+
}
27+
28+
public void setAll(DonationPreferences preferences) {
29+
this.neverShowAgain.set(preferences.isNeverShowAgain());
30+
this.lastShownEpochDay.set(preferences.getLastShownEpochDay());
31+
}
32+
1733
public boolean isNeverShowAgain() {
1834
return neverShowAgain.get();
1935
}

jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,6 @@ private JabRefGuiPreferences() {
363363
defaults.put(ASK_FOR_INCLUDING_CROSS_REFERENCES, Boolean.TRUE);
364364
defaults.put(INCLUDE_CROSS_REFERENCES, Boolean.FALSE);
365365

366-
// region donation defaults
367-
defaults.put(DONATION_NEVER_SHOW, Boolean.FALSE);
368-
defaults.put(DONATION_LAST_SHOWN_EPOCH_DAY, -1);
369-
// endregion
370-
371366
// region NewEntryUnifierPreferences
372367
defaults.put(CREATE_ENTRY_APPROACH, List.of(NewEntryDialogTab.values()).indexOf(NewEntryDialogTab.CHOOSE_ENTRY_TYPE));
373368
defaults.put(CREATE_ENTRY_EXPAND_RECOMMENDED, true);
@@ -414,6 +409,7 @@ public void clear() throws BackingStoreException {
414409

415410
getWorkspacePreferences().setAll(WorkspacePreferences.getDefault());
416411
getGuiPreferences().setAll(CoreGuiPreferences.getDefault());
412+
getDonationPreferences().setAll(DonationPreferences.getDefault());
417413
}
418414

419415
@Override
@@ -423,6 +419,7 @@ public void importPreferences(Path file) throws JabRefException {
423419
// in case of incomplete or corrupt xml fall back to current preferences
424420
getWorkspacePreferences().setAll(getWorkspacePreferencesFromBackingStore(getWorkspacePreferences()));
425421
getGuiPreferences().setAll(getCoreGuiPreferencesFromBackingStore(getGuiPreferences()));
422+
getDonationPreferences().setAll(getDonationPreferencesFromBackingStore(getDonationPreferences()));
426423
}
427424

428425
// region EntryEditorPreferences
@@ -1212,17 +1209,26 @@ public NewEntryPreferences getNewEntryPreferences() {
12121209
return newEntryPreferences;
12131210
}
12141211

1212+
// region Donation preferences
12151213
public DonationPreferences getDonationPreferences() {
12161214
if (donationPreferences != null) {
12171215
return donationPreferences;
12181216
}
12191217

1220-
donationPreferences = new DonationPreferences(getBoolean(DONATION_NEVER_SHOW), getInt(DONATION_LAST_SHOWN_EPOCH_DAY));
1218+
donationPreferences = getDonationPreferencesFromBackingStore(DonationPreferences.getDefault());
1219+
12211220
EasyBind.listen(donationPreferences.neverShowAgainProperty(), (_, _, newValue) -> putBoolean(DONATION_NEVER_SHOW, newValue));
12221221
EasyBind.listen(donationPreferences.lastShownEpochDayProperty(), (_, _, newValue) -> putInt(DONATION_LAST_SHOWN_EPOCH_DAY, newValue.intValue()));
12231222
return donationPreferences;
12241223
}
12251224

1225+
private DonationPreferences getDonationPreferencesFromBackingStore(DonationPreferences defaults) {
1226+
return new DonationPreferences(
1227+
getBoolean(DONATION_NEVER_SHOW, defaults.isNeverShowAgain()),
1228+
getInt(DONATION_LAST_SHOWN_EPOCH_DAY, defaults.getLastShownEpochDay()));
1229+
}
1230+
// endregion
1231+
12261232
/**
12271233
* In GUI mode, we can lookup the directory better
12281234
*/

0 commit comments

Comments
 (0)