Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraction of Globals.prefs.put and .get #7121

Merged
merged 31 commits into from
Dec 14, 2020
Merged
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
87c0da9
Extracted Globals.prefs from SidePaneManager
calixtus Nov 21, 2020
c0566c4
Merge remote-tracking branch 'upstream/master' into refactor-globals-…
calixtus Nov 21, 2020
fd83cfe
Fixed failing tests
calixtus Nov 21, 2020
064e773
Extracted Globals.prefs from ClipBoardManager
calixtus Nov 21, 2020
edc04c6
Introduced GuiPreferences
calixtus Nov 21, 2020
1051c2c
Extracted prefs.get and put from ImportCommand and ExportCommand
calixtus Nov 22, 2020
eafc356
Extracted prefs.get and put from ExternalFileTypes
calixtus Nov 22, 2020
0f9301b
Extracted more prefs.get and put
calixtus Nov 22, 2020
ddfb805
Extracted more prefs.get and put from MergeEntries
calixtus Nov 22, 2020
bf36959
Extracted Globals.prefs.get and .put out of push package
calixtus Nov 29, 2020
0d03690
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
Siedlerchr Dec 5, 2020
0d19091
Extrract calls to JabRefPreferences.getInstance()
Siedlerchr Dec 5, 2020
fb7e499
Extracted MrDlibPreferences, Fixed CrawlerTest, Removed some unnecess…
calixtus Dec 5, 2020
9f57e38
Fixed tests
calixtus Dec 7, 2020
9ee60c7
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
calixtus Dec 7, 2020
85d0a6a
Fixed more tests
calixtus Dec 7, 2020
f2a62fd
Fixed NPEs in tests and checkstyle
calixtus Dec 7, 2020
426532b
l10n
calixtus Dec 7, 2020
ac6d4b5
Fixed NPE in CrawlerTest
calixtus Dec 7, 2020
9e85f9c
Cleanups
calixtus Dec 7, 2020
de26c7d
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
calixtus Dec 7, 2020
eeb679b
Extracted TelemetryPreferences
calixtus Dec 7, 2020
43ced4c
Extracted calls to JabRefPreferences out of CustomImportList
calixtus Dec 8, 2020
7b56a94
Made storing of ProtectedTermsPreferences consistent
calixtus Dec 9, 2020
5a11a64
Extracted JabRefPreferences out ouf EntryEditor, reduced unnecessary …
calixtus Dec 9, 2020
2d15f61
Finished extracting unnecessary calls to JabRefPreferences
calixtus Dec 9, 2020
95882e5
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
calixtus Dec 9, 2020
14d509d
l10n
calixtus Dec 9, 2020
465b180
Merge branch 'master' into refactor-prefs-calls
tobiasdiez Dec 13, 2020
abe7f4f
Fixed merge error
calixtus Dec 14, 2020
f1b16ce
Fix checkstyle
Siedlerchr Dec 14, 2020
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
16 changes: 10 additions & 6 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.util.OptionalUtil;
import org.jabref.preferences.PreferencesService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,15 +48,18 @@ public class ClipBoardManager {
private static Clipboard clipboard;
private static java.awt.datatransfer.Clipboard primary;
private static ImportFormatReader importFormatReader;
private final PreferencesService preferencesService;

public ClipBoardManager() {
this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), Globals.IMPORT_FORMAT_READER);
public ClipBoardManager(PreferencesService preferencesService) {
this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), Globals.IMPORT_FORMAT_READER, preferencesService);
}

public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard primary, ImportFormatReader importFormatReader) {
public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard primary, ImportFormatReader importFormatReader, PreferencesService preferencesService) {
ClipBoardManager.clipboard = clipboard;
ClipBoardManager.primary = primary;
ClipBoardManager.importFormatReader = importFormatReader;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guees Tobi or Olli will complain about the empty space ;)

Suggested change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No here it's fine...just don't add empty lines at the beginning or end of a method

this.preferencesService = preferencesService;
}

/**
@@ -154,7 +158,7 @@ public void setContent(String string) {

public void setContent(List<BibEntry> entries) throws IOException {
final ClipboardContent content = new ClipboardContent();
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(Globals.prefs.getFieldWriterPreferences()), Globals.entryTypesManager);
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldWriterPreferences()), Globals.entryTypesManager);
String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX);
content.put(DragAndDropDataFormats.ENTRIES, serializedEntries);
content.putString(serializedEntries);
@@ -172,7 +176,7 @@ public List<BibEntry> extractData() {
}

private List<BibEntry> handleBibTeXData(String entries) {
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
try {
return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8)));
} catch (ParseException ex) {
@@ -206,7 +210,7 @@ private List<BibEntry> tryImportFormats(String data) {
private List<BibEntry> fetchByDOI(DOI doi) {
LOGGER.info("Found DOI in clipboard");
try {
Optional<BibEntry> entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(doi.getDOI());
Optional<BibEntry> entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI());
return OptionalUtil.toList(entry);
} catch (FetcherException ex) {
LOGGER.error("Error while fetching", ex);
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/Globals.java
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ public class Globals {
public static ExporterFactory exportFactory;
public static CountingUndoManager undoManager = new CountingUndoManager();
public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager();
public static ClipBoardManager clipboardManager = new ClipBoardManager();
public static ClipBoardManager clipboardManager = new ClipBoardManager(prefs);

// Key binding preferences
private static KeyBindingRepository keyBindingRepository;
48 changes: 26 additions & 22 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@
import org.jabref.gui.undo.UndoRedoAction;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.autosaveandbackup.AutosaveManager;
import org.jabref.logic.autosaveandbackup.BackupManager;
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
@@ -137,7 +138,6 @@
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.LastFocusedTabPreferences;

import com.google.common.eventbus.Subscribe;
import com.tobiasdiez.easybind.EasyBind;
@@ -175,13 +175,16 @@ public class JabRefFrame extends BorderPane {
private SidePane sidePane;
private PopOver progressViewPopOver;

private final TaskExecutor taskExecutor;

public JabRefFrame(Stage mainStage) {
this.mainStage = mainStage;
this.dialogService = new JabRefDialogService(mainStage, this, prefs);
this.stateManager = Globals.stateManager;
this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager, prefs);
this.undoManager = Globals.undoManager;
this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction());
this.taskExecutor = Globals.TASK_EXECUTOR;
this.setOnKeyTyped(key -> {
if (this.fileHistory.isShowing()) {
if (this.fileHistory.openFileByKey(key)) {
@@ -342,18 +345,18 @@ public JabRefPreferences prefs() {
* set to true
*/
private void tearDownJabRef(List<String> filenames) {
// prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, getExtendedState() == Frame.MAXIMIZED_BOTH);

if (prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
// Here we store the names of all current files. If
// there is no current file, we remove any
if (prefs.getGuiPreferences().shouldOpenLastEdited()) {
// Here we store the names of all current files. If there is no current file, we remove any
// previously stored filename.
if (filenames.isEmpty()) {
prefs.remove(JabRefPreferences.LAST_EDITED);
prefs.clearEditedFiles();
} else {
prefs.putStringList(JabRefPreferences.LAST_EDITED, filenames);
Path focusedDatabase = getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath().orElse(null);
new LastFocusedTabPreferences(prefs).setLastFocusedTab(focusedDatabase);
Path focusedDatabase = getCurrentLibraryTab().getBibDatabaseContext()
.getDatabasePath()
.orElse(null);
prefs.storeGuiPreferences(prefs.getGuiPreferences()
.withLastFilesOpened(filenames)
.withLastFocusedFile(focusedDatabase));
}
}

@@ -489,8 +492,8 @@ private Node createToolbar() {
rightSpacer,

new HBox(
factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, Globals.prefs, stateManager)),
factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs, stateManager)),
factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager)),
factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)),
factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)),
factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager))
),
@@ -566,7 +569,7 @@ public void showLibraryTab(LibraryTab libraryTab) {
}

public void init() {
sidePaneManager = new SidePaneManager(Globals.prefs, this);
sidePaneManager = new SidePaneManager(prefs, this, dialogService, stateManager);
sidePane = sidePaneManager.getPane();

tabbedPane = new TabPane();
@@ -683,12 +686,12 @@ private MenuBar createMenu() {
new SeparatorMenuItem(),

factory.createSubMenu(StandardActions.IMPORT,
factory.createMenuItem(StandardActions.IMPORT_INTO_CURRENT_LIBRARY, new ImportCommand(this, false, stateManager)),
factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, true, stateManager))),
factory.createMenuItem(StandardActions.IMPORT_INTO_CURRENT_LIBRARY, new ImportCommand(this, false, prefs, stateManager)),
factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, true, prefs, stateManager))),

factory.createSubMenu(StandardActions.EXPORT,
factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(this, false, Globals.prefs)),
factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(this, true, Globals.prefs)),
factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(this, false, prefs)),
factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(this, true, prefs)),
factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, this, stateManager))),

new SeparatorMenuItem(),
@@ -735,7 +738,7 @@ private MenuBar createMenu() {
factory.createMenuItem(StandardActions.MASS_SET_FIELDS, new MassSetFieldsAction(stateManager, dialogService, undoManager))
);

if (Globals.prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) {
if (prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) {
edit.getItems().addAll(
new SeparatorMenuItem(),
// ToDo: SpecialField needs the active BasePanel to mark it as changed.
@@ -784,7 +787,7 @@ private MenuBar createMenu() {
);

Menu lookupIdentifiers = factory.createSubMenu(StandardActions.LOOKUP_DOC_IDENTIFIER);
for (IdFetcher<?> fetcher : WebFetchers.getIdFetchers(Globals.prefs.getImportFormatPreferences())) {
for (IdFetcher<?> fetcher : WebFetchers.getIdFetchers(prefs.getImportFormatPreferences())) {
LookupIdentifierAction<?> identifierAction = new LookupIdentifierAction<>(this, fetcher, stateManager, undoManager);
lookupIdentifiers.getItems().add(factory.createMenuItem(identifierAction.getAction(), identifierAction));
}
@@ -814,10 +817,11 @@ private MenuBar createMenu() {

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsEMailAction(dialogService, stateManager)),
factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsEMailAction(dialogService, prefs, stateManager)),
pushToApplicationMenuItem,
new SeparatorMenuItem(),
factory.createMenuItem(StandardActions.START_SYSTEMATIC_LITERATURE_REVIEW, new StartLiteratureReviewAction(this, Globals.getFileUpdateMonitor(), Globals.prefs.getWorkingDir(), Globals.TASK_EXECUTOR))
factory.createMenuItem(StandardActions.START_SYSTEMATIC_LITERATURE_REVIEW,
new StartLiteratureReviewAction(this, Globals.getFileUpdateMonitor(), prefs.getWorkingDir(), taskExecutor, prefs.getImportFormatPreferences(), prefs.getSavePreferences()))
);

SidePaneComponent webSearch = sidePaneManager.getComponent(SidePaneType.WEB_SEARCH);
@@ -1114,7 +1118,7 @@ private boolean confirmClose(LibraryTab libraryTab) {
if (response.isPresent() && response.get().equals(saveChanges)) {
// The user wants to save.
try {
SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager);
SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab, prefs, Globals.entryTypesManager);
if (saveAction.save()) {
return true;
}
43 changes: 27 additions & 16 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
import org.jabref.logic.shared.DatabaseNotSupportedException;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.GuiPreferences;

import impl.org.controlsfx.skin.DecorationPane;
import org.slf4j.Logger;
@@ -62,8 +62,9 @@ private void openWindow(Stage mainStage) {
LOGGER.debug("Initializing frame");
mainFrame.init();

GuiPreferences guiPreferences = Globals.prefs.getGuiPreferences();
// Restore window location and/or maximised state
if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
if (guiPreferences.isWindowMaximised()) {
mainStage.setMaximized(true);
} else if (Screen.getScreens().size() == 1 && isWindowPositionOutOfBounds()) {
// corrects the Window, if its outside of the mainscreen
@@ -74,10 +75,10 @@ private void openWindow(Stage mainStage) {
mainStage.setHeight(768);
correctedWindowPos = true;
} else {
mainStage.setX(Globals.prefs.getDouble(JabRefPreferences.POS_X));
mainStage.setY(Globals.prefs.getDouble(JabRefPreferences.POS_Y));
mainStage.setWidth(Globals.prefs.getDouble(JabRefPreferences.SIZE_X));
mainStage.setHeight(Globals.prefs.getDouble(JabRefPreferences.SIZE_Y));
mainStage.setX(guiPreferences.getPositionX());
mainStage.setY(guiPreferences.getPositionY());
mainStage.setWidth(guiPreferences.getSizeX());
mainStage.setHeight(guiPreferences.getSizeY());
}
debugLogWindowState(mainStage);

@@ -120,7 +121,7 @@ private void openWindow(Stage mainStage) {

private void openDatabases() {
// If the option is enabled, open the last edited libraries, if any.
if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
if (!isBlank && Globals.prefs.getGuiPreferences().shouldOpenLastEdited()) {
openLastEditedDatabases();
}

@@ -136,7 +137,10 @@ private void openDatabases() {
.findFirst()
.flatMap(ParserResult::getFile)
.map(File::getAbsolutePath)
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));
.orElse(Globals.prefs.getGuiPreferences()
.getLastFocusedFile()
.toAbsolutePath()
.toString());

// Add all bibDatabases databases to the frame:
boolean first = false;
@@ -210,11 +214,16 @@ private void openDatabases() {
}

private void saveWindowState(Stage mainStage) {
Globals.prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, mainStage.isMaximized());
Globals.prefs.putDouble(JabRefPreferences.POS_X, mainStage.getX());
Globals.prefs.putDouble(JabRefPreferences.POS_Y, mainStage.getY());
Globals.prefs.putDouble(JabRefPreferences.SIZE_X, mainStage.getWidth());
Globals.prefs.putDouble(JabRefPreferences.SIZE_Y, mainStage.getHeight());
GuiPreferences preferences = Globals.prefs.getGuiPreferences();
Globals.prefs.storeGuiPreferences(new GuiPreferences(
mainStage.getX(),
mainStage.getY(),
mainStage.getWidth(),
mainStage.getHeight(),
mainStage.isMaximized(),
preferences.shouldOpenLastEdited(),
preferences.getLastFilesOpened(),
preferences.getLastFocusedFile()));
debugLogWindowState(mainStage);
}

@@ -241,14 +250,16 @@ private void debugLogWindowState(Stage mainStage) {
* @return outbounds
*/
private boolean isWindowPositionOutOfBounds() {
return !Screen.getPrimary().getBounds().contains(Globals.prefs.getDouble(JabRefPreferences.POS_X), Globals.prefs.getDouble(JabRefPreferences.POS_Y));
return !Screen.getPrimary().getBounds().contains(
Globals.prefs.getGuiPreferences().getPositionX(),
Globals.prefs.getGuiPreferences().getPositionY());
}

private void openLastEditedDatabases() {
if (Globals.prefs.get(JabRefPreferences.LAST_EDITED) == null) {
List<String> lastFiles = Globals.prefs.getGuiPreferences().getLastFilesOpened();
if (lastFiles.isEmpty()) {
return;
}
List<String> lastFiles = Globals.prefs.getStringList(JabRefPreferences.LAST_EDITED);

for (String fileName : lastFiles) {
File dbFile = new File(fileName);
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ private static void applyPreferences(JabRefPreferences preferences) {

// Override used newline character with the one stored in the preferences
// The preferences return the system newline character sequence as default
OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE);
OS.NEWLINE = Globals.prefs.getNewLineSeparator().toString();
}

private static void configureProxy(ProxyPreferences proxyPreferences) {
Loading