Skip to content

Commit

Permalink
Migrate ProtectedTermsLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed May 24, 2024
1 parent 7ec1dbc commit 4b5b72e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static void initGlobals(PreferencesService preferences) {
Globals.journalAbbreviationRepository = JournalAbbreviationLoader
.loadRepository(preferences.getJournalAbbreviationPreferences());
Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository());
Globals.protectedTermsLoader = new ProtectedTermsLoader(preferences.getProtectedTermsPreferences());
Injector.setModelOrService(ProtectedTermsLoader.class, new ProtectedTermsLoader(preferences.getProtectedTermsPreferences()));
}

private static void configureProxy(ProxyPreferences proxyPreferences) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.function.Function;

import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.util.FileUpdateMonitor;

import com.airhacks.afterburner.injection.Injector;
Expand All @@ -25,8 +24,6 @@ private static Object createDependency(Class<?> clazz) {
return Globals.journalAbbreviationRepository;
} else if (clazz == FileUpdateMonitor.class) {
return Globals.getFileUpdateMonitor();
} else if (clazz == ProtectedTermsLoader.class) {
return Globals.protectedTermsLoader;
} else if (clazz == ClipBoardManager.class) {
return Globals.getClipboardManager();
} else {
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/org/jabref/gui/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.jabref.gui.util.DefaultDirectoryMonitor;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.server.RemoteListenerServerManager;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.util.DirectoryMonitor;
Expand All @@ -30,15 +29,8 @@ public class Globals {
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static JournalAbbreviationRepository journalAbbreviationRepository;
/**
* This field is initialized upon startup.
* <p>
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static ProtectedTermsLoader protectedTermsLoader;

private static ClipBoardManager clipBoardManager = null;

private static DefaultFileUpdateMonitor fileUpdateMonitor;
private static DefaultDirectoryMonitor directoryMonitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextInputControl;

import org.jabref.gui.Globals;
import org.jabref.gui.actions.Action;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
Expand All @@ -19,10 +18,13 @@
import org.jabref.logic.formatter.casechanger.UnprotectTermsFormatter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.protectedterms.ProtectedTermsList;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;

import com.airhacks.afterburner.injection.Injector;

class ProtectedTermsMenu extends Menu {

private static final Formatter FORMATTER = new ProtectTermsFormatter(Globals.protectedTermsLoader);
private static Formatter FORMATTER;
private final TextInputControl textInputControl;
private final ActionFactory factory = new ActionFactory();

Expand Down Expand Up @@ -137,6 +139,7 @@ public void execute() {
public ProtectedTermsMenu(final TextInputControl textInputControl) {
super(Localization.lang("Protect terms"));
this.textInputControl = textInputControl;
FORMATTER = new ProtectTermsFormatter(Injector.instantiateModelOrService(ProtectedTermsLoader.class));

getItems().addAll(factory.createMenuItem(protectSelectionActionInformation, new ProtectSelectionAction()),
getExternalFilesMenu(),
Expand All @@ -147,11 +150,11 @@ public ProtectedTermsMenu(final TextInputControl textInputControl) {

private Menu getExternalFilesMenu() {
Menu protectedTermsMenu = factory.createSubMenu(() -> Localization.lang("Add selected text to list"));

Globals.protectedTermsLoader.getProtectedTermsLists().stream()
.filter(list -> !list.isInternalList())
.forEach(list -> protectedTermsMenu.getItems().add(
factory.createMenuItem(list::getDescription, new AddToProtectedTermsAction(list))));
ProtectedTermsLoader loader = Injector.instantiateModelOrService(ProtectedTermsLoader.class);
loader.getProtectedTermsLists().stream()
.filter(list -> !list.isInternalList())
.forEach(list -> protectedTermsMenu.getItems().add(
factory.createMenuItem(list::getDescription, new AddToProtectedTermsAction(list))));

if (protectedTermsMenu.getItems().isEmpty()) {
MenuItem emptyItem = new MenuItem(Localization.lang("No list enabled"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private static void upgradeKeyBindingsToJavaFX(JabRefPreferences prefs) {
return result;
};

List<String> keys = prefs.getStringList(JabRefPreferences.BINDINGS);
List<String> keys = new ArrayList<>(prefs.getStringList(JabRefPreferences.BINDINGS));
keys.replaceAll(replaceKeys);
prefs.putStringList(JabRefPreferences.BINDINGS, keys);
}
Expand Down

0 comments on commit 4b5b72e

Please sign in to comment.