Skip to content

Commit

Permalink
Adds a browse button next to the path text field for aux-based groups (
Browse files Browse the repository at this point in the history
…#4743)

* Fixes #4586

* implementing suggestions from code review

* Updated constructor to remove JabRefFrame object

* Using DialogService to show warnings/errors

* changes implemented
  • Loading branch information
samiyac authored and tobiasdiez committed Mar 11, 2019
1 parent 3d3eecc commit fa984a7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
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: 36 additions & 14 deletions src/main/java/org/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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 +25,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 +35,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 +88,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 +112,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 +127,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 +137,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 +273,10 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
if (explicitRadioButton.isSelected()) {
Character keywordDelimiter = Globals.prefs.getKeywordDelimiter();
if (groupName.contains(Character.toString(keywordDelimiter))) {
jabrefFrame.showMessage(
Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter)));
dialogService.showWarningDialogAndWait(null, 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,8 +290,7 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
}

if (warnAboutSameName) {
jabrefFrame.showMessage(
Localization.lang("There exists already a group with the same name.", Character.toString(keywordDelimiter)));
dialogService.showErrorDialogAndWait(Localization.lang("There exists already a group with the same name.", Character.toString(keywordDelimiter)));
return null;
}
}
Expand Down Expand Up @@ -323,7 +333,7 @@ groupName, getContext(),
resultingGroup.setIconName(iconField.getText());
return resultingGroup;
} catch (IllegalArgumentException | IOException exception) {
jabrefFrame.showMessage(exception.getLocalizedMessage());
dialogService.showErrorDialogAndWait(exception.getLocalizedMessage(), exception);
return null;
}
}
Expand Down Expand Up @@ -404,12 +414,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 +452,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 +600,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

0 comments on commit fa984a7

Please sign in to comment.