Skip to content

Commit 5772d68

Browse files
authored
Fix PushToPreferences reset and import (#15395)
* Initial cleanups * Adapt PushToApplicationPreferences * Fix artifact * Cleanup in WorkspacePreferences * Fix import * Fix and simplify Map of command paths * Fix duplicate VSCode application * Stylistic changes * Fix empty strings in prefs * Fix resetting of application settings * Fix checkstyle --------- Co-authored-by: Carl Christian Snethlage <calixtus@users.noreply.github.com>
1 parent 98ee51e commit 5772d68

File tree

11 files changed

+169
-189
lines changed

11 files changed

+169
-189
lines changed

jabgui/src/main/java/org/jabref/gui/WorkspacePreferences.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class WorkspacePreferences {
1919
private final ObjectProperty<Language> language;
2020
private final BooleanProperty shouldOverrideDefaultFontSize;
2121
private final IntegerProperty mainFontSize;
22-
private final IntegerProperty defaultFontSize;
2322
private final ObjectProperty<Theme> theme;
2423
private final BooleanProperty themeSyncOs;
2524
private final BooleanProperty shouldOpenLastEdited;
@@ -31,7 +30,6 @@ public class WorkspacePreferences {
3130
public WorkspacePreferences(Language language,
3231
boolean shouldOverrideDefaultFontSize,
3332
int mainFontSize,
34-
int defaultFontSize,
3533
Theme theme,
3634
boolean themeSyncOs,
3735
boolean shouldOpenLastEdited,
@@ -42,7 +40,6 @@ public WorkspacePreferences(Language language,
4240
this.language = new SimpleObjectProperty<>(language);
4341
this.shouldOverrideDefaultFontSize = new SimpleBooleanProperty(shouldOverrideDefaultFontSize);
4442
this.mainFontSize = new SimpleIntegerProperty(mainFontSize);
45-
this.defaultFontSize = new SimpleIntegerProperty(defaultFontSize);
4643
this.theme = new SimpleObjectProperty<>(theme);
4744
this.themeSyncOs = new SimpleBooleanProperty(themeSyncOs);
4845
this.shouldOpenLastEdited = new SimpleBooleanProperty(shouldOpenLastEdited);
@@ -58,7 +55,6 @@ private WorkspacePreferences() {
5855
Language.getLanguageFor(Locale.getDefault().getLanguage()), // Default language
5956
false, // Default font size override
6057
9, // Default font size
61-
9, // FixMe: main default and default default is weird
6258
new Theme(Theme.BASE_CSS), // Default theme
6359
false, // Default theme sync with OS
6460
true, // Default open last edited
@@ -77,7 +73,6 @@ public void setAll(WorkspacePreferences preferences) {
7773
this.language.set(preferences.getLanguage());
7874
this.shouldOverrideDefaultFontSize.set(preferences.shouldOverrideDefaultFontSize());
7975
this.mainFontSize.set(preferences.getMainFontSize());
80-
this.defaultFontSize.set(preferences.getDefaultFontSize());
8176
this.theme.set(preferences.getTheme());
8277
this.themeSyncOs.set(preferences.shouldThemeSyncOs());
8378
this.shouldOpenLastEdited.set(preferences.shouldOpenLastEdited());
@@ -115,10 +110,6 @@ public int getMainFontSize() {
115110
return mainFontSize.get();
116111
}
117112

118-
public int getDefaultFontSize() {
119-
return defaultFontSize.get();
120-
}
121-
122113
public void setMainFontSize(int mainFontSize) {
123114
this.mainFontSize.set(mainFontSize);
124115
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ private WorkspacePreferences getWorkspacePreferencesFromBackingStore(WorkspacePr
583583
getLanguage(),
584584
getBoolean(OVERRIDE_DEFAULT_FONT_SIZE, defaults.shouldOverrideDefaultFontSize()),
585585
getInt(MAIN_FONT_SIZE, defaults.getMainFontSize()),
586-
defaults.getDefaultFontSize(), // FixMe
587586
new Theme(get(THEME, Theme.BASE_CSS)),
588587
getBoolean(THEME_SYNC_OS, defaults.shouldThemeSyncOs()),
589588
getBoolean(OPEN_LAST_EDITED, defaults.shouldOpenLastEdited()),

jabgui/src/main/java/org/jabref/gui/preferences/external/ExternalTabViewModel.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.jabref.gui.preferences.external;
22

3-
import java.util.HashMap;
4-
53
import javafx.beans.property.BooleanProperty;
64
import javafx.beans.property.ListProperty;
75
import javafx.beans.property.ObjectProperty;
@@ -63,16 +61,10 @@ public class ExternalTabViewModel implements PreferenceTabViewModel {
6361
public ExternalTabViewModel(DialogService dialogService, GuiPreferences preferences) {
6462
this.dialogService = dialogService;
6563
this.preferences = preferences;
66-
this.initialExternalApplicationPreferences = this.preferences.getExternalApplicationsPreferences();
67-
this.initialPushToApplicationPreferences = this.preferences.getPushToApplicationPreferences();
68-
this.workingPushToApplicationPreferences = new PushToApplicationPreferences(
69-
initialPushToApplicationPreferences.getActiveApplicationName(),
70-
new HashMap<>(initialPushToApplicationPreferences.getCommandPaths()),
71-
initialPushToApplicationPreferences.getEmacsArguments(),
72-
initialPushToApplicationPreferences.getVimServer(),
73-
initialPushToApplicationPreferences.getCiteCommand(),
74-
initialPushToApplicationPreferences.getDefaultCiteCommand()
75-
);
64+
this.initialExternalApplicationPreferences = preferences.getExternalApplicationsPreferences();
65+
this.initialPushToApplicationPreferences = preferences.getPushToApplicationPreferences();
66+
this.workingPushToApplicationPreferences = PushToApplicationPreferences.getDefault();
67+
this.workingPushToApplicationPreferences.setAll(initialPushToApplicationPreferences);
7668

7769
terminalCommandValidator = new FunctionBasedValidator<>(
7870
customTerminalCommandProperty,
@@ -102,6 +94,8 @@ public ExternalTabViewModel(DialogService dialogService, GuiPreferences preferen
10294

10395
@Override
10496
public void setValues() {
97+
workingPushToApplicationPreferences.setAll(preferences.getPushToApplicationPreferences());
98+
10599
eMailReferenceSubjectProperty.setValue(initialExternalApplicationPreferences.getEmailSubject());
106100
autoOpenAttachedFoldersProperty.setValue(initialExternalApplicationPreferences.shouldAutoOpenEmailAttachmentsFolder());
107101

@@ -176,7 +170,11 @@ public boolean validateSettings() {
176170

177171
public void pushToApplicationSettings() {
178172
GuiPushToApplication selectedApplication = selectedPushToApplicationProperty.getValue();
179-
GuiPushToApplicationSettings settings = selectedApplication.getSettings(selectedApplication, dialogService, preferences.getFilePreferences(), workingPushToApplicationPreferences);
173+
GuiPushToApplicationSettings settings = selectedApplication.getSettings(
174+
selectedApplication,
175+
dialogService,
176+
preferences.getFilePreferences(),
177+
workingPushToApplicationPreferences);
180178

181179
DialogPane dialogPane = new DialogPane();
182180
dialogPane.setContent(settings.getSettingsPane());
@@ -250,6 +248,6 @@ public StringProperty customFileBrowserCommandProperty() {
250248
}
251249

252250
public void resetCiteCommandToDefault() {
253-
this.citeCommandProperty.setValue(preferences.getPushToApplicationPreferences().getDefaultCiteCommand().toString());
251+
this.citeCommandProperty.setValue(PushToApplicationPreferences.getDefault().getCiteCommand().toString());
254252
}
255253
}

jabgui/src/main/java/org/jabref/gui/push/GuiPushToApplication.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ default Action getAction() {
2424
return new GuiPushToApplicationAction(getDisplayName(), getApplicationIcon());
2525
}
2626

27-
default GuiPushToApplicationSettings getSettings(PushToApplication application, DialogService dialogService, FilePreferences filePreferences, PushToApplicationPreferences pushToApplicationPreferences) {
27+
default GuiPushToApplicationSettings getSettings(PushToApplication application,
28+
DialogService dialogService,
29+
FilePreferences filePreferences,
30+
PushToApplicationPreferences pushToApplicationPreferences) {
2831
return new GuiPushToApplicationSettings(application, dialogService, filePreferences, pushToApplicationPreferences);
2932
}
3033
}

jabgui/src/main/java/org/jabref/gui/push/GuiPushToApplicationSettings.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.jabref.gui.push;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
63
import javafx.scene.control.Button;
74
import javafx.scene.control.Label;
85
import javafx.scene.control.TextField;
@@ -77,12 +74,9 @@ public GuiPushToApplicationSettings(PushToApplication application,
7774
}
7875

7976
/// This method is called to indicate that the settings panel returned from the getSettingsPanel() method has been
80-
/// shown to the user and that the user has indicated that the settings should be stored. This method must store the
81-
/// state of the widgets in the settings panel to Globals.prefs.
77+
/// shown to the user and that the user has indicated that the settings should be stored.
8278
public void storeSettings() {
83-
Map<String, String> commandPaths = new HashMap<>(preferences.getCommandPaths());
84-
commandPaths.put(application.getDisplayName(), path.getText());
85-
preferences.setCommandPaths(commandPaths);
79+
preferences.getCommandPaths().put(application.getDisplayName(), path.getText());
8680
}
8781

8882
public GridPane getSettingsPane() {

jabgui/src/main/java/org/jabref/gui/push/GuiPushToApplications.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public static List<GuiPushToApplication> getAllGUIApplications(DialogService dia
3232
new GuiPushToTeXworks(dialogService, preferences),
3333
new GuiPushToVim(dialogService, preferences),
3434
new GuiPushToVScode(dialogService, preferences),
35-
new GuiPushToWinEdt(dialogService, preferences),
36-
new GuiPushToVScode(dialogService, preferences)));
35+
new GuiPushToWinEdt(dialogService, preferences)));
3736

3837
APPLICATIONS.sort(Comparator.comparing(PushToApplication::getDisplayName, String.CASE_INSENSITIVE_ORDER));
3938

jabgui/src/main/java/org/jabref/gui/theme/ThemeManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ private void updateFontStyle(@NonNull Scene scene) {
148148
LOGGER.debug("Overriding font size with user preference to {}pt", workspacePreferences.getMainFontSize());
149149
scene.getRoot().setStyle("-fx-font-size: " + workspacePreferences.getMainFontSize() + "pt;");
150150
} else {
151-
LOGGER.debug("Using default font size of {}pt", workspacePreferences.getDefaultFontSize());
152-
scene.getRoot().setStyle("-fx-font-size: " + workspacePreferences.getDefaultFontSize() + "pt;");
151+
int mainFontSize = WorkspacePreferences.getDefault().getMainFontSize();
152+
LOGGER.debug("Using default font size of {}pt", mainFontSize);
153+
scene.getRoot().setStyle("-fx-font-size: " + mainFontSize + "pt;");
153154
}
154155
}
155156

jabgui/src/main/resources/org/jabref/gui/preferences/external/ExternalTab.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</rowConstraints>
4343
<Label text="%Application to push entries to"/>
4444
<SearchableComboBox fx:id="pushToApplicationCombo"
45-
prefWidth="200.0" GridPane.columnIndex="1" editable="false"/>
45+
prefWidth="200.0" GridPane.columnIndex="1"/>
4646
<Button styleClass="icon-button,narrow" onAction="#pushToApplicationSettings"
4747
prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2">
4848
<graphic>

jablib/src/main/java/org/jabref/logic/preferences/CliPreferences.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public interface CliPreferences {
6060

6161
Map<String, Object> getDefaults();
6262

63-
LayoutFormatterPreferences getLayoutFormatterPreferences();
64-
65-
ImportFormatPreferences getImportFormatPreferences();
66-
6763
/// Returns the export configuration. The contained SaveConfiguration is a {@link org.jabref.model.metadata.SelfContainedSaveOrder}
6864
SelfContainedSaveConfiguration getSelfContainedExportConfiguration();
6965

@@ -118,4 +114,22 @@ public interface CliPreferences {
118114
PushToApplicationPreferences getPushToApplicationPreferences();
119115

120116
GitPreferences getGitPreferences();
117+
118+
default ImportFormatPreferences getImportFormatPreferences() {
119+
return new ImportFormatPreferences(
120+
getBibEntryPreferences(),
121+
getCitationKeyPatternPreferences(),
122+
getFieldPreferences(),
123+
getXmpPreferences(),
124+
getDOIPreferences(),
125+
getGrobidPreferences(),
126+
getFilePreferences());
127+
}
128+
129+
default LayoutFormatterPreferences getLayoutFormatterPreferences() {
130+
return new LayoutFormatterPreferences(
131+
getNameFormatterPreferences(),
132+
getDOIPreferences(),
133+
getFilePreferences().mainFileDirectoryProperty());
134+
}
121135
}

0 commit comments

Comments
 (0)