Skip to content

Commit b55db22

Browse files
committed
fix: update according to Subhramit and Carl's suggestion
1 parent b12af73 commit b55db22

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre
241241
private KeyBindingRepository keyBindingRepository;
242242
private CopyToPreferences copyToPreferences;
243243
private NewEntryPreferences newEntryPreferences;
244+
private DonationPreferences donationPreferences;
244245

245246
private JabRefGuiPreferences() {
246247
super();
@@ -1203,10 +1204,14 @@ public NewEntryPreferences getNewEntryPreferences() {
12031204
}
12041205

12051206
public DonationPreferences getDonationPreferences() {
1206-
DonationPreferences dp = new DonationPreferences(getBoolean(DONATION_NEVER_SHOW), getInt(DONATION_LAST_SHOWN_EPOCH_DAY));
1207-
EasyBind.listen(dp.neverShowAgainProperty(), (_, _, nv) -> putBoolean(DONATION_NEVER_SHOW, nv));
1208-
EasyBind.listen(dp.lastShownEpochDayProperty(), (_, _, nv) -> putInt(DONATION_LAST_SHOWN_EPOCH_DAY, nv.intValue()));
1209-
return dp;
1207+
if (donationPreferences != null) {
1208+
return donationPreferences;
1209+
}
1210+
1211+
donationPreferences = new DonationPreferences(getBoolean(DONATION_NEVER_SHOW), getInt(DONATION_LAST_SHOWN_EPOCH_DAY));
1212+
EasyBind.listen(donationPreferences.neverShowAgainProperty(), (_, _, newValue) -> putBoolean(DONATION_NEVER_SHOW, newValue));
1213+
EasyBind.listen(donationPreferences.lastShownEpochDayProperty(), (_, _, newValue) -> putInt(DONATION_LAST_SHOWN_EPOCH_DAY, newValue.intValue()));
1214+
return donationPreferences;
12101215
}
12111216

12121217
/**

jabgui/src/main/java/org/jabref/gui/walkthrough/WalkthroughAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.jabref.gui.fieldeditors.LinkedFilesEditor;
1616
import org.jabref.gui.icon.IconTheme;
1717
import org.jabref.gui.maintable.MainTable;
18+
import org.jabref.gui.preferences.GuiPreferences;
1819
import org.jabref.gui.preferences.PreferencesDialogView;
1920
import org.jabref.gui.search.GlobalSearchBar;
2021
import org.jabref.gui.util.URLs;
@@ -49,11 +50,13 @@ public class WalkthroughAction extends SimpleCommand {
4950
private final LibraryTabContainer frame;
5051
private final StateManager stateManager;
5152
private final Stage stage;
53+
private final GuiPreferences preferences;
5254

53-
public WalkthroughAction(Stage stage, LibraryTabContainer frame, StateManager stateManager, String name) {
55+
public WalkthroughAction(Stage stage, LibraryTabContainer frame, StateManager stateManager, GuiPreferences preferences, String name) {
5456
this.stage = stage;
5557
this.frame = frame;
5658
this.stateManager = stateManager;
59+
this.preferences = preferences;
5760
this.walkthrough = getWalkthrough(name);
5861
}
5962

@@ -456,7 +459,7 @@ private Walkthrough createSearchWalkthrough() {
456459
.sideEffect(new OpenLibrarySideEffect(frame, "SearchExamples.bib")))
457460
// Step 1b: Ensure initial search settings
458461
.addStep(WalkthroughStep.sideEffect(Localization.lang("Prepare search settings"))
459-
.sideEffect(new EnsureSearchSettingsSideEffect()))
462+
.sideEffect(new EnsureSearchSettingsSideEffect(preferences.getSearchPreferences())))
460463
// Step 2: Introduction
461464
.addStep(WalkthroughStep
462465
.panel(Localization.lang("Welcome to the search walkthrough"))

jabgui/src/main/java/org/jabref/gui/walkthrough/declarative/sideeffect/EnsureSearchSettingsSideEffect.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package org.jabref.gui.walkthrough.declarative.sideeffect;
22

3-
import org.jabref.gui.preferences.GuiPreferences;
43
import org.jabref.gui.walkthrough.Walkthrough;
54
import org.jabref.logic.l10n.Localization;
5+
import org.jabref.logic.search.SearchPreferences;
66
import org.jabref.model.search.SearchDisplayMode;
77
import org.jabref.model.search.SearchFlags;
88

9-
import com.airhacks.afterburner.injection.Injector;
109
import org.jspecify.annotations.NonNull;
1110

1211
/// Ensures the search bar starts with unfiltered mode and regex disabled, then restores
@@ -15,12 +14,13 @@ public class EnsureSearchSettingsSideEffect implements WalkthroughSideEffect {
1514
private final boolean previousRegex;
1615
private final boolean previousCaseSensitive;
1716
private final SearchDisplayMode previousDisplayMode;
17+
private final SearchPreferences searchPreferences;
1818

19-
public EnsureSearchSettingsSideEffect() {
20-
var preferences = Injector.instantiateModelOrService(GuiPreferences.class).getSearchPreferences();
21-
this.previousRegex = preferences.isRegularExpression();
22-
this.previousCaseSensitive = preferences.isCaseSensitive();
23-
this.previousDisplayMode = preferences.getSearchDisplayMode();
19+
public EnsureSearchSettingsSideEffect(SearchPreferences searchPreferences) {
20+
this.searchPreferences = searchPreferences;
21+
this.previousRegex = searchPreferences.isRegularExpression();
22+
this.previousCaseSensitive = searchPreferences.isCaseSensitive();
23+
this.previousDisplayMode = searchPreferences.getSearchDisplayMode();
2424
}
2525

2626
@Override
@@ -30,19 +30,17 @@ public EnsureSearchSettingsSideEffect() {
3030

3131
@Override
3232
public boolean forward(@NonNull Walkthrough walkthrough) {
33-
var preferences = Injector.instantiateModelOrService(GuiPreferences.class).getSearchPreferences();
34-
preferences.setSearchFlag(SearchFlags.REGULAR_EXPRESSION, false);
35-
preferences.setSearchFlag(SearchFlags.CASE_SENSITIVE, false);
36-
preferences.setSearchDisplayMode(SearchDisplayMode.FLOAT);
33+
searchPreferences.setSearchFlag(SearchFlags.REGULAR_EXPRESSION, false);
34+
searchPreferences.setSearchFlag(SearchFlags.CASE_SENSITIVE, false);
35+
searchPreferences.setSearchDisplayMode(SearchDisplayMode.FLOAT);
3736
return true;
3837
}
3938

4039
@Override
4140
public boolean backward(@NonNull Walkthrough walkthrough) {
42-
var preferences = Injector.instantiateModelOrService(GuiPreferences.class).getSearchPreferences();
43-
preferences.setSearchFlag(SearchFlags.REGULAR_EXPRESSION, previousRegex);
44-
preferences.setSearchFlag(SearchFlags.CASE_SENSITIVE, previousCaseSensitive);
45-
preferences.setSearchDisplayMode(previousDisplayMode);
41+
searchPreferences.setSearchFlag(SearchFlags.REGULAR_EXPRESSION, previousRegex);
42+
searchPreferences.setSearchFlag(SearchFlags.CASE_SENSITIVE, previousCaseSensitive);
43+
searchPreferences.setSearchDisplayMode(previousDisplayMode);
4644
return true;
4745
}
4846

jabgui/src/main/java/org/jabref/gui/welcome/WelcomeTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private VBox createLeftColumn() {
178178

179179
private VBox createRightColumn() {
180180
this.quickSettings = new QuickSettings(preferences, dialogService, taskExecutor, themeManager);
181-
this.walkthroughs = new Walkthroughs(stage, tabContainer, stateManager);
181+
this.walkthroughs = new Walkthroughs(stage, tabContainer, stateManager, preferences);
182182
VBox rightColumn = new VBox(quickSettings, walkthroughs);
183183
rightColumn.getStyleClass().add("welcome-content-column");
184184
VBox.setVgrow(quickSettings, Priority.ALWAYS);

jabgui/src/main/java/org/jabref/gui/welcome/components/Walkthroughs.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@
99
import org.jabref.gui.LibraryTabContainer;
1010
import org.jabref.gui.StateManager;
1111
import org.jabref.gui.icon.IconTheme;
12+
import org.jabref.gui.preferences.GuiPreferences;
1213
import org.jabref.gui.walkthrough.WalkthroughAction;
1314
import org.jabref.logic.l10n.Localization;
1415

1516
public class Walkthroughs extends VBox {
1617
private final Stage stage;
1718
private final LibraryTabContainer tabContainer;
1819
private final StateManager stateManager;
20+
private final GuiPreferences preferences;
1921

2022
private final Label header;
2123
private boolean isScrollEnabled = true;
2224

23-
public Walkthroughs(Stage stage, LibraryTabContainer tabContainer, StateManager stateManager) {
25+
public Walkthroughs(Stage stage, LibraryTabContainer tabContainer, StateManager stateManager, GuiPreferences preferences) {
2426
this.stage = stage;
2527
this.tabContainer = tabContainer;
2628
this.stateManager = stateManager;
29+
this.preferences = preferences;
2730

2831
getStyleClass().add("welcome-section");
2932

@@ -98,7 +101,7 @@ private Button createWalkthroughButton(String text, IconTheme.JabRefIcons icon,
98101
button.setGraphic(icon.getGraphicNode());
99102
button.getStyleClass().add("quick-settings-button");
100103
button.setMaxWidth(Double.MAX_VALUE);
101-
button.setOnAction(_ -> new WalkthroughAction(stage, tabContainer, stateManager, walkthroughId).execute());
104+
button.setOnAction(_ -> new WalkthroughAction(stage, tabContainer, stateManager, preferences, walkthroughId).execute());
102105
return button;
103106
}
104107
}

0 commit comments

Comments
 (0)