Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ public DonationPreferences(boolean neverShowAgain, int lastShownEpochDay) {
this.lastShownEpochDay.set(lastShownEpochDay);
}

/// Creates object with default values
private DonationPreferences() {
this(
false, // Donation never show again
-1); // Donation last shown epoch day
}

public static DonationPreferences getDefault() {
return new DonationPreferences();
}

public void setAll(DonationPreferences preferences) {
this.neverShowAgain.set(preferences.isNeverShowAgain());
this.lastShownEpochDay.set(preferences.getLastShownEpochDay());
}

public boolean isNeverShowAgain() {
return neverShowAgain.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,6 @@ private JabRefGuiPreferences() {
defaults.put(ASK_FOR_INCLUDING_CROSS_REFERENCES, Boolean.TRUE);
defaults.put(INCLUDE_CROSS_REFERENCES, Boolean.FALSE);

// region donation defaults
defaults.put(DONATION_NEVER_SHOW, Boolean.FALSE);
defaults.put(DONATION_LAST_SHOWN_EPOCH_DAY, -1);
// endregion

// region NewEntryUnifierPreferences
defaults.put(CREATE_ENTRY_APPROACH, List.of(NewEntryDialogTab.values()).indexOf(NewEntryDialogTab.CHOOSE_ENTRY_TYPE));
defaults.put(CREATE_ENTRY_EXPAND_RECOMMENDED, true);
Expand Down Expand Up @@ -414,6 +409,7 @@ public void clear() throws BackingStoreException {

getWorkspacePreferences().setAll(WorkspacePreferences.getDefault());
getGuiPreferences().setAll(CoreGuiPreferences.getDefault());
getDonationPreferences().setAll(DonationPreferences.getDefault());
}

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

// region EntryEditorPreferences
Expand Down Expand Up @@ -1212,17 +1209,26 @@ public NewEntryPreferences getNewEntryPreferences() {
return newEntryPreferences;
}

// region Donation preferences
public DonationPreferences getDonationPreferences() {
if (donationPreferences != null) {
return donationPreferences;
}

donationPreferences = new DonationPreferences(getBoolean(DONATION_NEVER_SHOW), getInt(DONATION_LAST_SHOWN_EPOCH_DAY));
donationPreferences = getDonationPreferencesFromBackingStore(DonationPreferences.getDefault());

EasyBind.listen(donationPreferences.neverShowAgainProperty(), (_, _, newValue) -> putBoolean(DONATION_NEVER_SHOW, newValue));
EasyBind.listen(donationPreferences.lastShownEpochDayProperty(), (_, _, newValue) -> putInt(DONATION_LAST_SHOWN_EPOCH_DAY, newValue.intValue()));
return donationPreferences;
}

private DonationPreferences getDonationPreferencesFromBackingStore(DonationPreferences defaults) {
return new DonationPreferences(
getBoolean(DONATION_NEVER_SHOW, defaults.isNeverShowAgain()),
getInt(DONATION_LAST_SHOWN_EPOCH_DAY, defaults.getLastShownEpochDay()));
}
// endregion

/**
* In GUI mode, we can lookup the directory better
*/
Expand Down
Loading