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

Adds a browse button next to the path text field for aux-based groups #4743

Merged
merged 6 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -55,6 +55,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We grouped and reordered the Main Menu (File, Edit, Library, Quality, Tools, and View tabs & icons). [#4666](https://github.com/JabRef/jabref/issues/4666) [#4667](https://github.com/JabRef/jabref/issues/4667) [#4668](https://github.com/JabRef/jabref/issues/4668) [#4669](https://github.com/JabRef/jabref/issues/4669) [#4670](https://github.com/JabRef/jabref/issues/4670) [#4671](https://github.com/JabRef/jabref/issues/4671) [#4672](https://github.com/JabRef/jabref/issues/4672) [#4673](https://github.com/JabRef/jabref/issues/4673)
- We added additional modifiers (capitalize, titlecase and sentencecase) to the Bibtex key generator. [#1506](https://github.com/JabRef/jabref/issues/1506)
- We grouped the toolbar icons and changed the Open Library and Copy icons. [#4584](https://github.com/JabRef/jabref/issues/4584)
- We added a browse button next to the path text field for aux-based groups. [#4586](https://github.com/JabRef/jabref/issues/4586)


### Fixed
Expand Down
50 changes: 38 additions & 12 deletions src/main/java/org/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.swing.JOptionPane;

import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
Expand All @@ -24,6 +27,7 @@
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
Expand All @@ -33,13 +37,16 @@

import org.jabref.Globals;
import org.jabref.JabRefGUI;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.search.rules.describer.SearchDescribers;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.TooltipTextUtil;
import org.jabref.logic.auxparser.DefaultAuxParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.SearchQuery;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.Keyword;
Expand Down Expand Up @@ -83,6 +90,8 @@ class GroupDialog extends BaseDialog<AbstractGroup> {
private final RadioButton independentButton = new RadioButton(Localization.lang("Independent group: When selected, view only this group's entries"));
private final RadioButton intersectionButton = new RadioButton(Localization.lang("Refine supergroup: When selected, view entries contained in both this group and its supergroup"));
private final RadioButton unionButton = new RadioButton(Localization.lang("Include subgroups: When selected, view entries contained in this group or its subgroups"));
private final DialogService dialogService;
private final JabRefPreferences prefs;

// for KeywordGroup
private final TextField keywordGroupSearchTerm = new TextField();
Expand All @@ -105,6 +114,8 @@ class GroupDialog extends BaseDialog<AbstractGroup> {

// for TexGroup
private final TextField texGroupFilePath = new TextField();
private final Button texGroupBrowseButton = new Button("Browse");
private final HBox texGroupHBox = new HBox(10);

// for all types
private final TextFlow descriptionTextFlow = new TextFlow();
Expand All @@ -118,7 +129,7 @@ class GroupDialog extends BaseDialog<AbstractGroup> {
* @param editedGroup The group being edited, or null if a new group is to be
* created.
*/
public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
public GroupDialog(DialogService dialogService, BasePanel basePanel, JabRefPreferences prefs, AbstractGroup editedGroup) {
this.setTitle(Localization.lang("Edit group"));

explicitRadioButton.setSelected(true);
Expand All @@ -128,8 +139,11 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
descriptionTextFlow.setMinHeight(180);
descriptionTextFlow.setPrefHeight(180);

this.dialogService = dialogService;
this.prefs = prefs;

// set default values (overwritten if editedGroup != null)
keywordGroupSearchField.setText(jabrefFrame.prefs().get(JabRefPreferences.GROUPS_DEFAULT_FIELD));
keywordGroupSearchField.setText(prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD));

// configure elements
ToggleGroup groupType = new ToggleGroup();
Expand Down Expand Up @@ -261,11 +275,11 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
if (explicitRadioButton.isSelected()) {
Character keywordDelimiter = Globals.prefs.getKeywordDelimiter();
if (groupName.contains(Character.toString(keywordDelimiter))) {
jabrefFrame.showMessage(
JOptionPane.showMessageDialog(null,
samiyac marked this conversation as resolved.
Show resolved Hide resolved
Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter)));
}

Optional<GroupTreeNode> rootGroup = jabrefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getGroups();
Optional<GroupTreeNode> rootGroup = basePanel.getBibDatabaseContext().getMetaData().getGroups();
if (rootGroup.isPresent()) {
int groupsWithSameName = rootGroup.get().findChildrenSatisfying(group -> group.getName().equals(groupName)).size();
boolean warnAboutSameName = false;
Expand All @@ -279,7 +293,7 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
}

if (warnAboutSameName) {
jabrefFrame.showMessage(
JOptionPane.showMessageDialog(null,
Localization.lang("There exists already a group with the same name.", Character.toString(keywordDelimiter)));
return null;
}
Expand Down Expand Up @@ -323,7 +337,7 @@ groupName, getContext(),
resultingGroup.setIconName(iconField.getText());
return resultingGroup;
} catch (IllegalArgumentException | IOException exception) {
jabrefFrame.showMessage(exception.getLocalizedMessage());
JOptionPane.showMessageDialog(null, exception.getLocalizedMessage());
return null;
}
}
Expand Down Expand Up @@ -404,12 +418,12 @@ groupName, getContext(),
getDialogPane().getScene().getWindow().sizeToScene();
}

public GroupDialog() {
this(JabRefGUI.getMainFrame(), null);
public GroupDialog(DialogService dialogService) {
this(dialogService, JabRefGUI.getMainFrame().getCurrentBasePanel(), Globals.prefs, null);
}

public GroupDialog(AbstractGroup editedGroup) {
this(JabRefGUI.getMainFrame(), editedGroup);
public GroupDialog(DialogService dialogService, AbstractGroup editedGroup) {
this(dialogService, JabRefGUI.getMainFrame().getCurrentBasePanel(), Globals.prefs, editedGroup);
}

private static String formatRegExException(String regExp, Exception e) {
Expand Down Expand Up @@ -442,7 +456,11 @@ private VBox createOptionsTexGroup() {
VBox texPanel = new VBox();
texPanel.setVisible(false);
texPanel.getChildren().add(new Label(Localization.lang("Aux file")));
texPanel.getChildren().add(texGroupFilePath);
texGroupBrowseButton.setOnAction((ActionEvent e) -> openBrowseDialog());
texGroupHBox.getChildren().add(texGroupFilePath);
texGroupHBox.getChildren().add(texGroupBrowseButton);
texGroupHBox.setHgrow(texGroupFilePath, Priority.ALWAYS);
texPanel.getChildren().add(texGroupHBox);
return texPanel;
}

Expand Down Expand Up @@ -586,6 +604,14 @@ private void updateComponents() {
getDialogPane().lookupButton(ButtonType.OK).setDisable(!okEnabled);
}

private void openBrowseDialog() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.AUX)
.withDefaultExtension(StandardFileType.AUX)
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> texGroupFilePath.setText(file.toAbsolutePath().toString()));
}

private String fromTextFlowToHTMLString(TextFlow textFlow) {
StringBuilder htmlStringBuilder = new StringBuilder();
for (Node node : textFlow.getChildren()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
* Opens "New Group Dialog" and add the resulting group to the specified group
*/
public void addNewSubgroup(GroupNodeViewModel parent) {
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog());
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog(dialogService));
newGroup.ifPresent(group -> {
parent.addSubgroup(group);

Expand All @@ -166,7 +166,7 @@ private void writeGroupChangesToMetaData() {
*/
public void editGroup(GroupNodeViewModel oldGroup) {
Optional<AbstractGroup> newGroup = dialogService
.showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup()));
.showCustomDialogAndWait(new GroupDialog(dialogService, oldGroup.getGroupNode().getGroup()));
newGroup.ifPresent(group -> {
// TODO: Keep assignments
boolean keepPreviousAssignments = dialogService.showConfirmationDialogAndWait(
Expand Down