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

Implemented "Current selection" group option #11455

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added an exporter and improved the importer for Endnote XML format. [#11137](https://github.com/JabRef/jabref/issues/11137)
- We added support for using BibTeX Style files (BST) in the Preview. [#11102](https://github.com/JabRef/jabref/issues/11102)
- We added support for automatically update LaTeX citations when a LaTeX file is created, removed, or modified. [#10585](https://github.com/JabRef/jabref/issues/10585)
- We added the ability to add the current selection to a newly created group. [#11449](https://github.com/JabRef/jabref/issues/11449)

### Changed

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<Tooltip text="%Group containing entries cited in a given TeX file"/>
</tooltip>
</RadioButton>
<RadioButton fx:id="selectionRadioButton" toggleGroup="$type" wrapText="true"
text="%Current selection">
<tooltip>
<Tooltip text="%Group all entries currently selected"/>
</tooltip>
</RadioButton>
</VBox>
<Separator orientation="VERTICAL"/>
<StackPane HBox.hgrow="ALWAYS">
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.groups.AbstractGroup;
import org.jabref.model.groups.GroupHierarchyType;
import org.jabref.model.groups.GroupTreeNode;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class GroupDialogView extends BaseDialog<AbstractGroup> {
@FXML private RadioButton searchRadioButton;
@FXML private RadioButton autoRadioButton;
@FXML private RadioButton texRadioButton;
@FXML private RadioButton selectionRadioButton;

// Option Groups
@FXML private TextField keywordGroupSearchTerm;
Expand Down Expand Up @@ -109,6 +111,7 @@ public class GroupDialogView extends BaseDialog<AbstractGroup> {
private final BibDatabaseContext currentDatabase;
private final @Nullable GroupTreeNode parentNode;
private final @Nullable AbstractGroup editedGroup;
private final List<BibEntry> selectedEntries;

private GroupDialogViewModel viewModel;

Expand All @@ -119,10 +122,12 @@ public class GroupDialogView extends BaseDialog<AbstractGroup> {
public GroupDialogView(BibDatabaseContext currentDatabase,
@Nullable GroupTreeNode parentNode,
@Nullable AbstractGroup editedGroup,
GroupDialogHeader groupDialogHeader) {
GroupDialogHeader groupDialogHeader,
List<BibEntry> selectedEntries) {
this.currentDatabase = currentDatabase;
this.parentNode = parentNode;
this.editedGroup = editedGroup;
this.selectedEntries = selectedEntries;

ViewLoader.view(this)
.load()
Expand Down Expand Up @@ -172,7 +177,7 @@ public GroupDialogView(BibDatabaseContext currentDatabase,

@FXML
public void initialize() {
viewModel = new GroupDialogViewModel(dialogService, currentDatabase, preferencesService, editedGroup, parentNode, fileUpdateMonitor);
viewModel = new GroupDialogViewModel(dialogService, currentDatabase, preferencesService, editedGroup, parentNode, fileUpdateMonitor, selectedEntries);

setResultConverter(viewModel::resultConverter);

Expand Down Expand Up @@ -200,6 +205,8 @@ public void initialize() {
searchRadioButton.selectedProperty().bindBidirectional(viewModel.typeSearchProperty());
autoRadioButton.selectedProperty().bindBidirectional(viewModel.typeAutoProperty());
texRadioButton.selectedProperty().bindBidirectional(viewModel.typeTexProperty());
selectionRadioButton.selectedProperty().bindBidirectional(viewModel.typeSelectionProperty());
selectionRadioButton.disableProperty().bind(viewModel.entriesAreSelectedProperty().not());

keywordGroupSearchTerm.textProperty().bindBidirectional(viewModel.keywordGroupSearchTermProperty());
keywordGroupSearchField.textProperty().bindBidirectional(viewModel.keywordGroupSearchFieldProperty());
Expand Down
46 changes: 44 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.Keyword;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.groups.AbstractGroup;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class GroupDialogViewModel {
private final BooleanProperty typeSearchProperty = new SimpleBooleanProperty();
private final BooleanProperty typeAutoProperty = new SimpleBooleanProperty();
private final BooleanProperty typeTexProperty = new SimpleBooleanProperty();
private final BooleanProperty typeSelectionProperty = new SimpleBooleanProperty();

// Option Groups
private final StringProperty keywordGroupSearchTermProperty = new SimpleStringProperty("");
Expand All @@ -94,6 +96,7 @@ public class GroupDialogViewModel {
private final StringProperty autoGroupPersonsFieldProperty = new SimpleStringProperty("");

private final StringProperty texGroupFilePathProperty = new SimpleStringProperty("");
private final BooleanProperty entriesAreSelected = new SimpleBooleanProperty(false);

private Validator nameValidator;
private Validator nameContainsDelimiterValidator;
Expand All @@ -112,24 +115,38 @@ public class GroupDialogViewModel {
private final AbstractGroup editedGroup;
private final GroupTreeNode parentNode;
private final FileUpdateMonitor fileUpdateMonitor;
private final List<BibEntry> selectedEntries;

public GroupDialogViewModel(DialogService dialogService,
BibDatabaseContext currentDatabase,
PreferencesService preferencesService,
@Nullable AbstractGroup editedGroup,
@Nullable GroupTreeNode parentNode,
FileUpdateMonitor fileUpdateMonitor) {
FileUpdateMonitor fileUpdateMonitor,
List<BibEntry> selectedEntries) {
this.dialogService = dialogService;
this.preferencesService = preferencesService;
this.currentDatabase = currentDatabase;
this.editedGroup = editedGroup;
this.parentNode = parentNode;
this.fileUpdateMonitor = fileUpdateMonitor;
this.selectedEntries = selectedEntries;

setupValidation();
setValues();
}

public GroupDialogViewModel(
DialogService dialogService,
BibDatabaseContext currentDatabase,
PreferencesService preferencesService,
@Nullable AbstractGroup editedGroup,
@Nullable GroupTreeNode parentNode,
FileUpdateMonitor fileUpdateMonitor
) {
this(dialogService, currentDatabase, preferencesService, editedGroup, parentNode, fileUpdateMonitor, new ArrayList<>());
}

private void setupValidation() {
validator = new CompositeValidator();

Expand Down Expand Up @@ -371,6 +388,14 @@ public AbstractGroup resultConverter(ButtonType button) {
new DefaultAuxParser(new BibDatabase()),
fileUpdateMonitor,
currentDatabase.getMetaData());
} else if (typeSelectionProperty.getValue()) {
ExplicitGroup tempResultingGroup = new ExplicitGroup(
groupName,
groupHierarchySelectedProperty.getValue(),
preferencesService.getBibEntryPreferences().getKeywordSeparator()
);
tempResultingGroup.add(selectedEntries);
resultingGroup = tempResultingGroup;
}

if (resultingGroup != null) {
Expand Down Expand Up @@ -405,7 +430,16 @@ public void setValues() {
.ifPresent(iconProperty::setValue);
parentNode.getGroup().getColor().ifPresent(color -> colorUseProperty.setValue(true));
}
typeExplicitProperty.setValue(true);
if (!selectedEntries.isEmpty()) {
entriesAreSelected.setValue(true);
if (selectedEntries.size() > 1) {
typeSelectionProperty.setValue(true);
} else {
typeExplicitProperty.setValue(true);
}
} else {
typeExplicitProperty.setValue(true);
}
groupHierarchySelectedProperty.setValue(preferencesService.getGroupsPreferences().getDefaultHierarchicalContext());
autoGroupKeywordsOptionProperty.setValue(Boolean.TRUE);
} else {
Expand Down Expand Up @@ -587,6 +621,10 @@ public BooleanProperty typeTexProperty() {
return typeTexProperty;
}

public BooleanProperty typeSelectionProperty() {
return typeSelectionProperty;
}

public StringProperty keywordGroupSearchTermProperty() {
return keywordGroupSearchTermProperty;
}
Expand Down Expand Up @@ -638,4 +676,8 @@ public StringProperty autoGroupPersonsFieldProperty() {
public StringProperty texGroupFilePathProperty() {
return texGroupFilePathProperty;
}

public BooleanProperty entriesAreSelectedProperty() {
return entriesAreSelected;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private void updateSelection(List<TreeItem<GroupNodeViewModel>> newSelectedGroup
}

private void selectNode(GroupNodeViewModel value) {
selectNode(value, false);
selectNode(value, true);
}

private void selectNode(GroupNodeViewModel value, boolean expandParents) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public void addNewSubgroup(GroupNodeViewModel parent, GroupDialogHeader groupDia
database,
parent.getGroupNode(),
null,
groupDialogHeader));
groupDialogHeader,
stateManager.getSelectedEntries()
));

newGroup.ifPresent(group -> {
parent.addSubgroup(group);
Expand Down Expand Up @@ -260,7 +262,9 @@ public void editGroup(GroupNodeViewModel oldGroup) {
database,
oldGroup.getGroupNode().getParent().orElse(null),
oldGroup.getGroupNode().getGroup(),
GroupDialogHeader.SUBGROUP));
GroupDialogHeader.SUBGROUP,
stateManager.getSelectedEntries()
));
newGroup.ifPresent(group -> {

AbstractGroup oldGroupDef = oldGroup.getGroupNode().getGroup();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2649,3 +2649,5 @@ Note\:\ The\ study\ directory\ should\ be\ empty.=Note: The study directory shou
Warning\:\ The\ selected\ directory\ is\ not\ empty.=Warning: The selected directory is not empty.
Warning\:\ Failed\ to\ check\ if\ the\ directory\ is\ empty.=Warning: Failed to check if the directory is empty.
Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The selected directory is not a valid directory.
Current\ selection=Current selection
Group\ all\ entries\ currently\ selected=Group all entries currently selected
Loading