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

Tooltips for entry editor fields #6046

Merged
merged 18 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -97,7 +97,7 @@ private void setupPanel(BibEntry entry, boolean compressed) {
fieldEditor.bindToEntry(entry);

editors.put(field, fieldEditor);
labels.add(new FieldNameLabel(field));
labels.add(new FieldNameLabel(field, field.getName()));
ShikunXiong marked this conversation as resolved.
Show resolved Hide resolved
}

ColumnConstraints columnExpand = new ColumnConstraints();
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/FieldNameLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,39 @@
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;

public class FieldNameLabel extends Label {
private Tooltip tip;

public FieldNameLabel(Field field) {
public FieldNameLabel(Field field, String name) {
super(field.getDisplayName());

setPadding(new Insets(4, 0, 0, 0));
setAlignment(Pos.CENTER);
setPrefHeight(Double.POSITIVE_INFINITY);
setTip(name);
}

public void setTip(String name) {
tip = new Tooltip();
if (StandardField.AUTHOR.getName().equals(name)) {
Copy link
Member

@calixtus calixtus Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for testing field.getName() instead of field directly?
I think you could use field as an argument for setTip and test field instead.

Suggested change
if (StandardField.AUTHOR.getName().equals(name)) {
switch (field) {
case AUTHOR:
tip.setText(etc...);
break;
case BIBTEXKEY:
etc...
default:
break;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use field as an argument for setTip and test field instead

Thank you for the suggestion. I have changed it.

tip.setText(Localization.lang("AUTHOR TIP"));
} else if (StandardField.BIBTEXKEY.getName().equals(name)) {
tip.setText(Localization.lang("BIBTEXKEY TIP"));
} else if (StandardField.JOURNAL.getName().equals(name)) {
tip.setText(Localization.lang("JOURNAL TIP"));
} else if (StandardField.TITLE.getName().equals(name)) {
tip.setText(Localization.lang("TITLE TIP"));
} else if (StandardField.YEAR.getName().equals(name)) {
tip.setText(Localization.lang("YEAR TIP"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing because the l10n-key should be the same as the value.
E.g.: tip.setText(Localization.lang("Multiple authors separated with 'and', e.g. author1 and author2"));

} else {
return;
}
this.setTooltip(tip);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, tooltips are only added for five fields (author, journal, title, year and key). It would be really great, if the other fields (e.g. in the other tabs of the entry editor) would get tooltips as well. Examples: date, editor, DOI, pages, number, language, volume, urldate, ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what I made is just a start.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really good to hear! Thank you for your effort! :)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum StandardField implements Field {
ARCHIVEPREFIX("archiveprefix"),
ASSIGNEE("assignee", FieldProperty.PERSON_NAMES),
AUTHOR("author", FieldProperty.PERSON_NAMES),
BIBTEXKEY("bibtexkey"),
BOOKAUTHOR("bookauthor", FieldProperty.PERSON_NAMES),
BOOKPAGINATION("bookpagination", FieldProperty.PAGINATION),
BOOKSUBTITLE("booksubtitle", FieldProperty.BOOK_NAME),
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2117,3 +2117,9 @@ Entry\ type\ cannot\ be\ empty.\ Please\ enter\ a\ name.=Entry type cannot be em
Field\ cannot\ be\ empty.\ Please\ enter\ a\ name.=Field cannot be empty. Please enter a name.
Shared\ database=Shared database
Lookup=Lookup

AUTHOR\ TIP=Multiple authors separated with 'and', e.g. author1 and author2
BIBTEXKEY\ TIP =[First author'last name][Article year] e.g. Jones2020
JOURNAL\ TIP=The name of the journal
TITLE\ TIP=The title of the article
YEAR\ TIP=The year of publication, e.g. 2005