Skip to content

Commit

Permalink
Merge commit 'aa130' into fix-arch2
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/jabref/gui/LibraryTab.java
  • Loading branch information
koppor committed Sep 8, 2024
2 parents ba790b2 + aa13053 commit 4de1c33
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 315 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where search result highlighting was broken at complex searches. [#8067](https://github.com/JabRef/jabref/issues/8067)
- We fixed an exception when searching for unlinked files.
- We fixed an issue where unescaped braces in the arXiv fetcher were not treated [#11704](https://github.com/JabRef/jabref/issues/11704)
- We fixed an issue where two contradicting notifications were shown when cutting an entry in the main table. [#11724](https://github.com/JabRef/jabref/pull/11724)
- We fixed an issue where unescaped braces in the arXiv fetcher were not treated. [#11704](https://github.com/JabRef/jabref/issues/11704)

### Removed

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.ai.AiApiKeyProvider;

import com.airhacks.afterburner.injection.Injector;
import org.apache.commons.cli.ParseException;
Expand Down Expand Up @@ -64,7 +63,6 @@ public static void main(String[] args) {
// Initialize preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();
Injector.setModelOrService(PreferencesService.class, preferences);
Injector.setModelOrService(AiApiKeyProvider.class, preferences);

// Early exit in case another instance is already running
if (!handleMultipleAppInstances(args, preferences.getRemotePreferences())) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.GuiPreferences;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.ai.AiApiKeyProvider;

import com.airhacks.afterburner.injection.Injector;
import com.tobiasdiez.easybind.EasyBind;
Expand Down Expand Up @@ -162,7 +161,6 @@ public void initialize() {
preferencesService.getAiPreferences(),
preferencesService.getFilePreferences(),
preferencesService.getCitationKeyPatternPreferences(),
Injector.instantiateModelOrService(AiApiKeyProvider.class),
dialogService,
taskExecutor);
Injector.setModelOrService(AiService.class, aiService);
Expand Down
254 changes: 155 additions & 99 deletions src/main/java/org/jabref/gui/LibraryTab.java

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public void execute() {
// Not sure what is selected -> copy/paste/cut selected entries except for Preview and CodeArea

switch (action) {
case COPY -> tabSupplier.get().copy();
case CUT -> tabSupplier.get().cut();
case PASTE -> tabSupplier.get().paste();
case DELETE_ENTRY -> tabSupplier.get().delete(StandardActions.DELETE_ENTRY);
case COPY -> tabSupplier.get().copyEntry();
case CUT -> tabSupplier.get().cutEntry();
case PASTE -> tabSupplier.get().pasteEntry();
case DELETE_ENTRY -> tabSupplier.get().deleteEntry();
case UNDO -> {
if (undoManager.canUndo()) {
undoManager.undo();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.jabref.model.util.DirectoryMonitorManager;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.ai.AiApiKeyProvider;

import com.airhacks.afterburner.views.ViewLoader;
import com.tobiasdiez.easybind.EasyBind;
Expand Down Expand Up @@ -111,7 +110,6 @@ public class EntryEditor extends BorderPane {
@Inject private DialogService dialogService;
@Inject private TaskExecutor taskExecutor;
@Inject private PreferencesService preferencesService;
@Inject private AiApiKeyProvider aiApiKeyProvider;
@Inject private StateManager stateManager;
@Inject private ThemeManager themeManager;
@Inject private FileUpdateMonitor fileMonitor;
Expand Down Expand Up @@ -249,7 +247,7 @@ public void close() {

@FXML
private void deleteEntry() {
libraryTab.delete(currentlyEditedEntry);
libraryTab.deleteEntry(currentlyEditedEntry);
}

@FXML
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ public void addTab(@NonNull BibDatabaseContext databaseContext, boolean raisePan
this,
dialogService,
prefs,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/importer/NewEntryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public NewEntryAction(Supplier<LibraryTab> tabSupplier, DialogService dialogServ

public NewEntryAction(Supplier<LibraryTab> tabSupplier, EntryType type, DialogService dialogService, PreferencesService preferences, StateManager stateManager) {
this(tabSupplier, dialogService, preferences, stateManager);
this.type = Optional.of(type);
this.type = Optional.ofNullable(type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ private void openTheFile(Path file) {
file,
dialogService,
preferencesService,
aiService,
stateManager,
tabContainer,
fileUpdateMonitor,
Expand Down
88 changes: 3 additions & 85 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.gui.maintable;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -45,17 +44,11 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.importer.FetcherClientException;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.FetcherServerException;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.event.EntriesAddedEvent;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.BibtexString;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

Expand All @@ -74,18 +67,14 @@ public class MainTable extends TableView<BibEntryTableViewModel> {
private static final PseudoClass NOT_MATCHING_SEARCH_AND_GROUPS = PseudoClass.getPseudoClass("not-matching-search-and-groups");

private final LibraryTab libraryTab;
private final DialogService dialogService;
private final StateManager stateManager;
private final BibDatabaseContext database;
private final MainTableDataModel model;

private final ImportHandler importHandler;
private final CustomLocalDragboard localDragboard;
private final ClipBoardManager clipBoardManager;
private final BibEntryTypesManager entryTypesManager;
private final TaskExecutor taskExecutor;
private final UndoManager undoManager;
private final FilePreferences filePreferences;
private final ImportHandler importHandler;
private long lastKeyPressTime;
private String columnSearchTerm;

Expand All @@ -100,31 +89,20 @@ public MainTable(MainTableDataModel model,
ClipBoardManager clipBoardManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
FileUpdateMonitor fileUpdateMonitor) {
ImportHandler importHandler) {
super();

this.libraryTab = libraryTab;
this.dialogService = dialogService;
this.stateManager = stateManager;
this.database = Objects.requireNonNull(database);
this.model = model;
this.clipBoardManager = clipBoardManager;
this.entryTypesManager = entryTypesManager;
this.taskExecutor = taskExecutor;
this.undoManager = libraryTab.getUndoManager();
this.filePreferences = preferencesService.getFilePreferences();
this.importHandler = importHandler;

MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences();

importHandler = new ImportHandler(
database,
preferencesService,
fileUpdateMonitor,
undoManager,
stateManager,
dialogService,
taskExecutor);

localDragboard = stateManager.getLocalDragboard();

this.setOnDragOver(this::handleOnDragOverTableView);
Expand Down Expand Up @@ -272,29 +250,6 @@ public void clearAndSelect(BibEntry bibEntry) {
});
}

public void copy() {
List<BibEntry> selectedEntries = getSelectedEntries();

if (!selectedEntries.isEmpty()) {
List<BibtexString> stringConstants = getUsedStringValues(selectedEntries);
try {
if (stringConstants.isEmpty()) {
clipBoardManager.setContent(selectedEntries, entryTypesManager);
} else {
clipBoardManager.setContent(selectedEntries, entryTypesManager, stringConstants);
}
dialogService.notify(Localization.lang("Copied %0 entry(ies)", selectedEntries.size()));
} catch (IOException e) {
LOGGER.error("Error while copying selected entries to clipboard.", e);
}
}
}

public void cut() {
copy();
libraryTab.delete(StandardActions.CUT);
}

private void scrollToNextMatchCategory() {
BibEntryTableViewModel selectedEntry = getSelectionModel().getSelectedItem();
if (selectedEntry == null) {
Expand Down Expand Up @@ -403,39 +358,6 @@ private void clearAndSelectLast() {
scrollTo(getItems().size() - 1);
}

public void paste() {
List<BibEntry> entriesToAdd;
String content = ClipBoardManager.getContents();
entriesToAdd = importHandler.handleBibTeXData(content);
if (entriesToAdd.isEmpty()) {
entriesToAdd = handleNonBibTeXStringData(content);
}
if (entriesToAdd.isEmpty()) {
return;
}

importHandler.importEntriesWithDuplicateCheck(database, entriesToAdd);
}

private List<BibEntry> handleNonBibTeXStringData(String data) {
try {
return this.importHandler.handleStringData(data);
} catch (FetcherException exception) {
if (exception instanceof FetcherClientException) {
dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("No data was found for the identifier"));
} else if (exception instanceof FetcherServerException) {
dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("Server not available"));
} else {
dialogService.showErrorDialogAndWait(exception);
}
return List.of();
}
}

public void dropEntry(List<BibEntry> entriesToAdd) {
importHandler.importEntriesWithDuplicateCheck(database, entriesToAdd);
}

private void handleOnDragOver(TableRow<BibEntryTableViewModel> row, BibEntryTableViewModel item, DragEvent event) {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.ANY);
Expand Down Expand Up @@ -558,8 +480,4 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
.filter(viewModel -> viewModel.getEntry().equals(entry))
.findFirst();
}

private List<BibtexString> getUsedStringValues(List<BibEntry> entries) {
return database.getDatabase().getUsedStrings(entries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ private void exportEntries() {
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/jabref/gui/preferences/ai/AiTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.ai.AiApiKeyProvider;
import org.jabref.preferences.ai.AiProvider;
import org.jabref.preferences.ai.EmbeddingModel;

import com.airhacks.afterburner.views.ViewLoader;
import com.dlsc.gemsfx.ResizableTextArea;
import com.dlsc.unitfx.IntegerInputField;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
import jakarta.inject.Inject;
import org.controlsfx.control.SearchableComboBox;
import org.controlsfx.control.textfield.CustomPasswordField;

public class AiTab extends AbstractPreferenceTabView<AiTabViewModel> implements PreferencesTab {
private static final String HUGGING_FACE_CHAT_MODEL_PROMPT = "TinyLlama/TinyLlama_v1.1 (or any other model name)";

@Inject private AiApiKeyProvider aiApiKeyProvider;

@FXML private CheckBox enableAi;

@FXML private ComboBox<AiProvider> aiProviderComboBox;
Expand Down Expand Up @@ -73,7 +69,7 @@ public AiTab() {
}

public void initialize() {
this.viewModel = new AiTabViewModel(preferencesService, aiApiKeyProvider);
this.viewModel = new AiTabViewModel(preferencesService);

enableAi.selectedProperty().bindBidirectional(viewModel.enableAi());

Expand Down
21 changes: 7 additions & 14 deletions src/main/java/org/jabref/gui/preferences/ai/AiTabViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.jabref.logic.util.LocalizedNumbers;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.ai.AiApiKeyProvider;
import org.jabref.preferences.ai.AiPreferences;
import org.jabref.preferences.ai.AiProvider;
import org.jabref.preferences.ai.EmbeddingModel;
Expand Down Expand Up @@ -83,7 +82,6 @@ public class AiTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty disableExpertSettings = new SimpleBooleanProperty(true);

private final AiPreferences aiPreferences;
private final AiApiKeyProvider aiApiKeyProvider;

private final Validator apiKeyValidator;
private final Validator chatModelValidator;
Expand All @@ -99,11 +97,10 @@ public class AiTabViewModel implements PreferenceTabViewModel {
private final Validator ragMinScoreTypeValidator;
private final Validator ragMinScoreRangeValidator;

public AiTabViewModel(PreferencesService preferencesService, AiApiKeyProvider aiApiKeyProvider) {
public AiTabViewModel(PreferencesService preferencesService) {
this.oldLocale = Locale.getDefault();

this.aiPreferences = preferencesService.getAiPreferences();
this.aiApiKeyProvider = aiApiKeyProvider;

this.enableAi.addListener((observable, oldValue, newValue) -> {
disableBasicSettings.set(!newValue);
Expand Down Expand Up @@ -266,9 +263,9 @@ public AiTabViewModel(PreferencesService preferencesService, AiApiKeyProvider ai

@Override
public void setValues() {
openAiApiKey.setValue(aiApiKeyProvider.getApiKeyForAiProvider(AiProvider.OPEN_AI));
mistralAiApiKey.setValue(aiApiKeyProvider.getApiKeyForAiProvider(AiProvider.MISTRAL_AI));
huggingFaceApiKey.setValue(aiApiKeyProvider.getApiKeyForAiProvider(AiProvider.HUGGING_FACE));
openAiApiKey.setValue(aiPreferences.getApiKeyForAiProvider(AiProvider.OPEN_AI));
mistralAiApiKey.setValue(aiPreferences.getApiKeyForAiProvider(AiProvider.MISTRAL_AI));
huggingFaceApiKey.setValue(aiPreferences.getApiKeyForAiProvider(AiProvider.HUGGING_FACE));

openAiApiBaseUrl.setValue(aiPreferences.getOpenAiApiBaseUrl());
mistralAiApiBaseUrl.setValue(aiPreferences.getMistralAiApiBaseUrl());
Expand Down Expand Up @@ -305,9 +302,9 @@ public void storeSettings() {
aiPreferences.setMistralAiChatModel(mistralAiChatModel.get() == null ? "" : mistralAiChatModel.get());
aiPreferences.setHuggingFaceChatModel(huggingFaceChatModel.get() == null ? "" : huggingFaceChatModel.get());

aiApiKeyProvider.storeAiApiKeyInKeyring(AiProvider.OPEN_AI, openAiApiKey.get() == null ? "" : openAiApiKey.get());
aiApiKeyProvider.storeAiApiKeyInKeyring(AiProvider.MISTRAL_AI, mistralAiApiKey.get() == null ? "" : mistralAiApiKey.get());
aiApiKeyProvider.storeAiApiKeyInKeyring(AiProvider.HUGGING_FACE, huggingFaceApiKey.get() == null ? "" : huggingFaceApiKey.get());
aiPreferences.storeAiApiKeyInKeyring(AiProvider.OPEN_AI, openAiApiKey.get() == null ? "" : openAiApiKey.get());
aiPreferences.storeAiApiKeyInKeyring(AiProvider.MISTRAL_AI, mistralAiApiKey.get() == null ? "" : mistralAiApiKey.get());
aiPreferences.storeAiApiKeyInKeyring(AiProvider.HUGGING_FACE, huggingFaceApiKey.get() == null ? "" : huggingFaceApiKey.get());
// We notify in all cases without a real check if something was changed
aiPreferences.apiKeyUpdated();

Expand Down Expand Up @@ -389,10 +386,6 @@ public BooleanProperty enableAi() {
return enableAi;
}

public boolean getEnableAi() {
return enableAi.get();
}

public ReadOnlyListProperty<AiProvider> aiProvidersProperty() {
return aiProvidersList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ public LibraryTab openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnecti
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
Loading

0 comments on commit 4de1c33

Please sign in to comment.