Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.util.StringConverter;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
Expand All @@ -41,6 +42,7 @@
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.groups.GroupsFactory;
import org.jabref.logic.importer.PagedSearchBasedFetcher;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.SearchBasedFetcher;
Expand All @@ -53,6 +55,8 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.groups.AllEntriesGroup;
import org.jabref.model.groups.ExplicitGroup;
import org.jabref.model.groups.GroupHierarchyType;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.util.FileUpdateMonitor;

Expand Down Expand Up @@ -148,7 +152,6 @@ private void initialize() {
});

libraryListView.setEditable(false);
groupListView.setEditable(false);
libraryListView.getItems().addAll(stateManager.getOpenDatabases());
new ViewModelListCellFactory<BibDatabaseContext>()
.withText(database -> {
Expand Down Expand Up @@ -226,6 +229,18 @@ private void initialize() {

private void setupGroupListView() {
groupListView.setVisibleRowCount(5);
groupListView.setEditable(true);
groupListView.setConverter(new StringConverter<>() {
@Override
public String toString(GroupTreeNode node) {
return node != null ? node.getName() : "";
}

@Override
public GroupTreeNode fromString(String string) {
return findGroupByName(string).orElse(null);
}
});
updateGroupList();
libraryListView.getSelectionModel().selectedItemProperty()
.addListener((_, _, _) -> {
Expand Down Expand Up @@ -287,12 +302,13 @@ private void initializeDialog() {

setResultConverter(button -> {
if (button == importButton) {
if (groupListView.getItems().size() > 1) {
// 1 is the "All entries" group, so if more than 1, we have groups defined
GroupTreeNode prevSelectedGroup = stateManager.getSelectedGroups(stateManager.getActiveDatabase().orElse(null)).getFirst();
stateManager.setSelectedGroups(libraryListView.getSelectionModel().getSelectedItem(), List.of(groupListView.getSelectionModel().getSelectedItem()));
Optional<GroupTreeNode> groupToImportInto = getOrCreateSelectedGroup();
if (groupToImportInto.isPresent()) {
Optional<GroupTreeNode> prevSelectedGroup = stateManager.getSelectedGroups(stateManager.getActiveDatabase().orElse(null)).stream().findFirst();
stateManager.setSelectedGroups(libraryListView.getSelectionModel().getSelectedItem(), List.of(groupToImportInto.get()));
viewModel.importEntries(viewModel.getCheckedEntries().stream().toList(), downloadLinkedOnlineFiles.isSelected());
stateManager.setSelectedGroups(stateManager.getActiveDatabase().orElse(null), List.of(prevSelectedGroup));
prevSelectedGroup.ifPresent(group ->
stateManager.setSelectedGroups(stateManager.getActiveDatabase().orElse(null), List.of(group)));
} else {
viewModel.importEntries(viewModel.getCheckedEntries().stream().toList(), downloadLinkedOnlineFiles.isSelected());
}
Expand All @@ -304,6 +320,50 @@ private void initializeDialog() {
});
}

private Optional<GroupTreeNode> findGroupByName(String name) {
if (name == null || name.isBlank()) {
return Optional.empty();
}
return groupListView.getItems().stream()
.filter(node -> node != null && name.equals(node.getName()))
.findFirst();
}

private Optional<GroupTreeNode> getOrCreateSelectedGroup() {
BibDatabaseContext selectedDb = libraryListView.getSelectionModel().getSelectedItem();
if (selectedDb == null) {
return Optional.empty();
}

GroupTreeNode selected = groupListView.getValue();
if (selected != null) {
if (selected.getGroup() instanceof AllEntriesGroup) {
return Optional.empty();
}
return Optional.of(selected);
}

String typedName = groupListView.getEditor().getText();
if (typedName == null || typedName.isBlank()) {
return Optional.empty();
}

Optional<GroupTreeNode> existingGroup = findGroupByName(typedName);
if (existingGroup.isPresent()) {
return existingGroup;
}

ExplicitGroup newGroup = new ExplicitGroup(typedName, GroupHierarchyType.INDEPENDENT,
preferences.getBibEntryPreferences().getKeywordSeparator());
GroupTreeNode rootNode = selectedDb.getMetaData().getGroups()
.orElseGet(() -> {
GroupTreeNode newRoot = GroupTreeNode.fromGroup(GroupsFactory.createAllEntriesGroup());
selectedDb.getMetaData().setGroups(newRoot);
return newRoot;
});
return Optional.of(rootNode.addSubgroup(newGroup));
}

private void setupPaginationBindings() {
BooleanProperty loading = viewModel.loadingProperty();
BooleanProperty initialLoadComplete = viewModel.initialLoadCompleteProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<HBox spacing="4" alignment="CENTER_LEFT">
<Label text="%Library to import into"/>
<ComboBox fx:id="libraryListView" layoutX="16.0" layoutY="52.0"/>
<ComboBox fx:id="groupListView" layoutX="16.0" layoutY="52.0"/>
<Label text="%Add to group"/>
<ComboBox fx:id="groupListView" layoutX="16.0" layoutY="52.0" editable="true"/>
</HBox>
</VBox>
<HBox HBox.hgrow="ALWAYS"/>
Expand Down
1 change: 1 addition & 0 deletions jablib/src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2817,6 +2817,7 @@ This\ could\ indicate\ that\ JabRef\ did\ not\ shut\ down\ cleanly\ last\ time\
Use\ the\ field\ FJournal\ to\ store\ the\ full\ journal\ name\ for\ (un)abbreviations\ in\ the\ entry=Use the field FJournal to store the full journal name for (un)abbreviations in the entry

Library\ to\ import\ into=Library to import into
Add\ to\ group=Add to group

Enable\ web\ search=Enable web search
Web\ search\ disabled=Web search disabled
Expand Down