Skip to content

Commit 2a0ae53

Browse files
RakockiWpriyanshu16095
authored andcommitted
Implement reset for Name Display Preferences (JabRef#15136)
* Implement reset for NameDisplayPreferences * Fixed implemention of getNameDisplayPreferencesFromBackingStore method * refactor * deleted sout statements
1 parent faaf15d commit 2a0ae53

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

jabgui/src/main/java/org/jabref/gui/maintable/NameDisplayPreferences.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ public NameDisplayPreferences(DisplayStyle displayStyle,
2222
this.abbreviationStyle.set(abbreviationStyle);
2323
}
2424

25+
private NameDisplayPreferences() {
26+
this(
27+
DisplayStyle.NATBIB,
28+
AbbreviationStyle.FULL
29+
);
30+
}
31+
32+
public static NameDisplayPreferences getDefault() {
33+
return new NameDisplayPreferences();
34+
}
35+
36+
public void setAll(NameDisplayPreferences preferences) {
37+
this.displayStyle.set(preferences.displayStyle.get());
38+
this.abbreviationStyle.set(preferences.abbreviationStyle.get());
39+
}
40+
2541
public DisplayStyle getDisplayStyle() {
2642
return displayStyle.get();
2743
}

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

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,6 @@ private JabRefGuiPreferences() {
287287
"</font>__NEWLINE__");
288288
// endregion
289289

290-
// region NameDisplayPreferences
291-
defaults.put(NAMES_AS_IS, Boolean.FALSE); // "Show names unchanged"
292-
defaults.put(NAMES_FIRST_LAST, Boolean.FALSE); // "Show 'Firstname Lastname'"
293-
defaults.put(NAMES_NATBIB, Boolean.TRUE); // "Natbib style"
294-
defaults.put(ABBR_AUTHOR_NAMES, Boolean.TRUE); // "Abbreviate names"
295-
defaults.put(NAMES_LAST_ONLY, Boolean.TRUE); // "Show last names only"
296-
// endregion
297-
298290
// By default disable "Fit table horizontally on the screen"
299291
defaults.put(AUTO_RESIZE_MODE, Boolean.FALSE);
300292

@@ -352,6 +344,7 @@ public void clear() throws BackingStoreException {
352344
getWorkspacePreferences().setAll(WorkspacePreferences.getDefault());
353345
getAutoCompletePreferences().setAll(AutoCompletePreferences.getDefault());
354346
getSidePanePreferences().setAll(SidePanePreferences.getDefault());
347+
getNameDisplayPreferences().setAll(NameDisplayPreferences.getDefault());
355348
}
356349

357350
@Override
@@ -375,6 +368,7 @@ public void importPreferences(Path path) throws JabRefException {
375368
getWorkspacePreferences().setAll(getWorkspacePreferencesFromBackingStore(getWorkspacePreferences()));
376369
getAutoCompletePreferences().setAll(getAutoCompletePreferencesFromBackingStore(getAutoCompletePreferences()));
377370
getSidePanePreferences().setAll(getSidePanePreferencesFromBackingStore(getSidePanePreferences()));
371+
getNameDisplayPreferences().setAll(getNameDisplayPreferencesFromBackingStore(getNameDisplayPreferences()));
378372
}
379373

380374
// region EntryEditorPreferences
@@ -936,9 +930,7 @@ public NameDisplayPreferences getNameDisplayPreferences() {
936930
return nameDisplayPreferences;
937931
}
938932

939-
nameDisplayPreferences = new NameDisplayPreferences(
940-
getNameDisplayStyle(),
941-
getNameAbbreviationStyle());
933+
nameDisplayPreferences = getNameDisplayPreferencesFromBackingStore(NameDisplayPreferences.getDefault());
942934

943935
EasyBind.listen(nameDisplayPreferences.displayStyleProperty(), (obs, oldValue, newValue) -> {
944936
putBoolean(NAMES_NATBIB, newValue == NameDisplayPreferences.DisplayStyle.NATBIB);
@@ -953,28 +945,45 @@ public NameDisplayPreferences getNameDisplayPreferences() {
953945
return nameDisplayPreferences;
954946
}
955947

956-
private NameDisplayPreferences.AbbreviationStyle getNameAbbreviationStyle() {
957-
NameDisplayPreferences.AbbreviationStyle abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.NONE; // default
958-
if (getBoolean(ABBR_AUTHOR_NAMES)) {
959-
abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.FULL;
960-
} else if (getBoolean(NAMES_LAST_ONLY)) {
961-
abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.LASTNAME_ONLY;
962-
}
963-
return abbreviationStyle;
948+
private NameDisplayPreferences getNameDisplayPreferencesFromBackingStore(NameDisplayPreferences defaults) {
949+
return new NameDisplayPreferences(
950+
getNameDisplayStyleFromBackingStore(defaults),
951+
getNameAbbreviationStyleFromBackingStore(defaults)
952+
);
964953
}
965954

966-
private NameDisplayPreferences.DisplayStyle getNameDisplayStyle() {
967-
NameDisplayPreferences.DisplayStyle displayStyle = NameDisplayPreferences.DisplayStyle.LASTNAME_FIRSTNAME; // default
968-
if (getBoolean(NAMES_NATBIB)) {
969-
displayStyle = NameDisplayPreferences.DisplayStyle.NATBIB;
970-
} else if (getBoolean(NAMES_AS_IS)) {
971-
displayStyle = NameDisplayPreferences.DisplayStyle.AS_IS;
972-
} else if (getBoolean(NAMES_FIRST_LAST)) {
973-
displayStyle = NameDisplayPreferences.DisplayStyle.FIRSTNAME_LASTNAME;
955+
private NameDisplayPreferences.DisplayStyle getNameDisplayStyleFromBackingStore(NameDisplayPreferences defaults) {
956+
if (!hasKey(NAMES_NATBIB) && !hasKey(NAMES_AS_IS) && !hasKey(NAMES_FIRST_LAST)) {
957+
return defaults.getDisplayStyle();
958+
}
959+
960+
if (getBoolean(NAMES_NATBIB, false)) {
961+
return NameDisplayPreferences.DisplayStyle.NATBIB;
962+
}
963+
if (getBoolean(NAMES_AS_IS, false)) {
964+
return NameDisplayPreferences.DisplayStyle.AS_IS;
965+
}
966+
if (getBoolean(NAMES_FIRST_LAST, false)) {
967+
return NameDisplayPreferences.DisplayStyle.FIRSTNAME_LASTNAME;
974968
}
975-
return displayStyle;
969+
970+
return NameDisplayPreferences.DisplayStyle.LASTNAME_FIRSTNAME;
976971
}
977972

973+
private NameDisplayPreferences.AbbreviationStyle getNameAbbreviationStyleFromBackingStore(NameDisplayPreferences defaults) {
974+
if (!hasKey(ABBR_AUTHOR_NAMES) && !hasKey(NAMES_LAST_ONLY)) {
975+
return defaults.getAbbreviationStyle();
976+
}
977+
978+
if (getBoolean(ABBR_AUTHOR_NAMES, false)) {
979+
return NameDisplayPreferences.AbbreviationStyle.FULL;
980+
}
981+
if (getBoolean(NAMES_LAST_ONLY, false)) {
982+
return NameDisplayPreferences.AbbreviationStyle.LASTNAME_ONLY;
983+
}
984+
985+
return NameDisplayPreferences.AbbreviationStyle.NONE;
986+
}
978987
// endregion
979988

980989
// region: Main table, main table column, and search dialog column preferences

0 commit comments

Comments
 (0)