Skip to content

Commit

Permalink
Hide user comment button
Browse files Browse the repository at this point in the history
remove from grid

todo move to prefs
  • Loading branch information
Siedlerchr committed Nov 26, 2023
1 parent b9b4da0 commit 9cef70d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
52 changes: 27 additions & 25 deletions src/main/java/org/jabref/gui/entryeditor/CommentsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.SequencedSet;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

import javafx.collections.ObservableList;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
Expand All @@ -22,6 +20,7 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.fieldeditors.FieldEditorFX;
import org.jabref.gui.fieldeditors.FieldNameLabel;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
Expand All @@ -39,6 +38,11 @@ public class CommentsTab extends FieldsEditorTab {
public static final String NAME = "Comments";

private final String defaultOwner;
private final UserSpecificCommentField userSpecificCommentField;

// TODO: Move this to the preferences
private boolean showUserComment = true;

public CommentsTab(PreferencesService preferences,
BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
Expand All @@ -65,14 +69,20 @@ public CommentsTab(PreferencesService preferences,
this.defaultOwner = preferences.getOwnerPreferences().getDefaultOwner();
setText(Localization.lang("Comments"));
setGraphic(IconTheme.JabRefIcons.COMMENT.getGraphicNode());

userSpecificCommentField = new UserSpecificCommentField(defaultOwner);
}

@Override
protected SequencedSet<Field> determineFieldsToShow(BibEntry entry) {

SequencedSet<Field> comments = new LinkedHashSet<>();
if (showUserComment) {
comments.add(userSpecificCommentField);
}
comments.add(StandardField.COMMENT);
comments.addAll(entry.getFields().stream()
.filter(field -> field instanceof UserSpecificCommentField ||
.filter(field -> (field instanceof UserSpecificCommentField && showUserComment) ||
field.getName().toLowerCase().contains("comment"))
.sorted(Comparator.comparing(Field::getName))
.collect(Collectors.toCollection(LinkedHashSet::new)));
Expand Down Expand Up @@ -112,6 +122,8 @@ protected void setupPanel(BibEntry entry, boolean compressed) {

boolean hasDefaultOwnerField = false;

Optional<FieldEditorFX> fieldEditorForUserDefinedComment = editors.entrySet().stream().filter(f -> f.getKey().getName().contains(defaultOwner)).map(Map.Entry::getValue).findFirst();

for (Map.Entry<Field, FieldEditorFX> fieldEditorEntry : editors.entrySet()) {
Field field = fieldEditorEntry.getKey();
FieldEditorFX editor = fieldEditorEntry.getValue();
Expand All @@ -123,30 +135,20 @@ protected void setupPanel(BibEntry entry, boolean compressed) {
editor.getNode().setDisable(!shouldBeEnabled);
}

if (!hasDefaultOwnerField) {
if (hasDefaultOwnerField) {
BorderPane container = new BorderPane();
Button addDefaultOwnerCommentButton = new Button(Localization.lang("Add"));
addDefaultOwnerCommentButton.setOnAction(e -> {
ObservableList<Node> children = gridPane.getChildren();
int rows = gridPane.getRowCount();

// remove button
children.removeLast();

// add comment field for current user
UserSpecificCommentField userSpecificCommentField = new UserSpecificCommentField(defaultOwner);
Label label = createLabelAndEditor(entry, userSpecificCommentField);
Parent node = editors.get(userSpecificCommentField).getNode();
gridPane.addRow(rows - 1, label, node);
setCompressedRowLayout(gridPane, rows);
node.requestFocus();
Button hideDefaultOwnerCommentButton = new Button(Localization.lang("Hide user comments"));
hideDefaultOwnerCommentButton.setOnAction(e -> {
var labelForfield = gridPane.getChildren().stream().filter(s -> s instanceof FieldNameLabel).filter(x -> ((FieldNameLabel) x).getText().equals(userSpecificCommentField.getDisplayName())).findFirst();
labelForfield.ifPresent(label -> gridPane.getChildren().remove(label));
fieldEditorForUserDefinedComment.ifPresent(f -> gridPane.getChildren().remove(f.getNode()));
editors.remove(userSpecificCommentField);

showUserComment = false;
setupPanel(entry, false);
});
// container.setCenter(addDefaultOwnerCommentButton);
gridPane.add(addDefaultOwnerCommentButton, 1, gridPane.getRowCount(), 2, 1);
// setRegularRowLayout(gridPane);
gridPane.add(hideDefaultOwnerCommentButton, 1, gridPane.getRowCount(), 2, 1);
setCompressedRowLayout();
// gridPane.getRowConstraints().add(new RowConstraints(addDefaultOwnerCommentButton.getMinHeight()));
// setCompressedRowLayout(gridPane, gridPane.getRowCount());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Field)) {
if (!(o instanceof Field other)) {
return false;
}
Field other = (Field) o;
return name.equals(other.getName());
}

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 @@ -2621,3 +2621,5 @@ Would\ you\ like\ to\ enable\ fetching\ of\ journal\ information?\ This\ can\ be
Enable=Enable
Keep\ disabled=Keep disabled
Hide\ user\ comments=Hide user comments

0 comments on commit 9cef70d

Please sign in to comment.