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

Extended Hints - Alternative to #4971 #4975

Merged
merged 10 commits into from
May 18, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We added an option in the settings to set the default action in JabRef when right clicking on any entry in any database and selecting "Open folder". [#4763](https://github.com/JabRef/jabref/issues/4763)
- The Medline fetcher now normalizes the author names according to the BibTeX-Standard [#4345](https://github.com/JabRef/jabref/issues/4345)
- We added an option on the Linked File Viewer to rename the attached file of an entry directly on the JabRef. [#4844](https://github.com/JabRef/jabref/issues/4844)
- We added an option in the preference dialog box that allows user to enable helpful tooltips.[#3599](https://github.com/JabRef/jabref/issues/3599)


### Fixed
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/jabref/gui/preferences/AdvancedTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ public AdvancedTab(DialogService dialogService, JabRefPreferences prefs) {
Label remoteOperation = new Label(Localization.lang("Remote operation"));
remoteOperation.getStyleClass().add("sectionHeader");
builder.add(remoteOperation, 2, 1);
Text textRemote = new Text(Localization.lang("This feature lets new files be opened or imported into an already running instance of JabRef " +
"instead of opening a new instance. For instance, this is useful when you open a file in JabRef " +
"from your web browser. Note that this will prevent you from running more than one instance of JabRef at a time."));
textRemote.setWrappingWidth(600);
builder.add(textRemote, 2, 4);
if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS)) {
Text textRemote = new Text(Localization.lang("This feature lets new files be opened or imported into an already running instance of JabRef " +
"instead of opening a new instance. For instance, this is useful when you open a file in JabRef " +
"from your web browser. Note that this will prevent you from running more than one instance of JabRef at a time."));
textRemote.setWrappingWidth(600);
builder.add(textRemote, 2, 4);
}

HBox p = new HBox();
p.setSpacing(8);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/preferences/GeneralTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GeneralTab extends Pane implements PrefsTab {
private final CheckBox confirmDelete;
private final CheckBox memoryStick;
private final CheckBox inspectionWarnDupli;
private final CheckBox showAdvancedHints;
private final CheckBox useTimeStamp;
private final CheckBox updateTimeStamp;
private final CheckBox overwriteTimeStamp;
Expand Down Expand Up @@ -77,6 +78,7 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
timeStampFormat = new TextField();
timeStampField = new TextField();
inspectionWarnDupli = new CheckBox(Localization.lang("Warn about unresolved duplicates when closing inspection window"));
showAdvancedHints = new CheckBox(Localization.lang("Show advanced hints (i.e. helpful tooltips, suggestions and explanation)"));
shouldCollectTelemetry = new CheckBox(Localization.lang("Collect and share telemetry data to help improve JabRef."));
encodings = new ComboBox<>(FXCollections.observableArrayList(Encodings.ENCODINGS));

Expand Down Expand Up @@ -135,6 +137,8 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
Label defaultBibliographyMode = new Label(Localization.lang("Default bibliography mode"));
biblioBox.getChildren().addAll(defaultBibliographyMode, biblatexMode);
builder.add(biblioBox, 1, 29);

builder.add(showAdvancedHints,1,30);
}

@Override
Expand Down Expand Up @@ -164,6 +168,7 @@ public void setValues() {
}
encodings.setValue(prefs.getDefaultEncoding());
languageSelection.setValue(prefs.getLanguage());
showAdvancedHints.setSelected(prefs.getBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS));
}

@Override
Expand All @@ -181,6 +186,7 @@ public void storeSettings() {
+ " rename or remove the jabref.xml file in the same folder as JabRef."));
}
prefs.putBoolean(JabRefPreferences.MEMORY_STICK_MODE, memoryStick.isSelected());
prefs.putBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS, showAdvancedHints.isSelected());
prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, confirmDelete.isSelected());
prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, inspectionWarnDupli.isSelected());
String owner = defOwnerField.getText().trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private void storeAllSettings() {

GUIGlobals.updateEntryEditorColors();
frame.setupAllTables();
frame.getGlobalSearchBar().updateHintVisibility();
dialogService.notify(Localization.lang("Preferences recorded."));
}

Expand Down
45 changes: 40 additions & 5 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.search;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -27,6 +28,7 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.util.Duration;

Expand All @@ -43,10 +45,12 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.maintable.MainTable;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TooltipTextUtil;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.SearchQuery;
import org.jabref.logic.search.SearchQueryHighlightObservable;
import org.jabref.model.entry.Author;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.SearchPreferences;

import impl.org.controlsfx.skin.AutoCompletePopup;
Expand All @@ -72,6 +76,7 @@ public class GlobalSearchBar extends HBox {
private final ToggleButton regularExp;
private final Button searchModeButton = new Button();
private final Label currentResults = new Label("");
private final Tooltip tooltip = new Tooltip();
private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable();
private SearchWorker searchWorker;

Expand All @@ -86,6 +91,11 @@ public GlobalSearchBar(JabRefFrame frame) {
// fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the frame width is too small
currentResults.setPrefWidth(150);

tooltip.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
tooltip.setMaxHeight(10);
searchField.setTooltip(null);
updateHintVisibility();

KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs();
searchField.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
Optional<KeyBinding> keyBinding = keyBindingRepository.mapToKeyBinding(event);
Expand Down Expand Up @@ -188,6 +198,7 @@ public void focus() {
private void clearSearch() {
currentResults.setText("");
searchField.setText("");
setHintTooltip(null);
searchQueryHighlightObservable.reset();

Globals.stateManager.clearSearchQuery();
Expand Down Expand Up @@ -284,11 +295,35 @@ public void updateResults(int matched, TextFlow description, boolean grammarBase
// TODO: switch Icon color
//searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getIcon());
}
Tooltip tooltip = new Tooltip();
tooltip.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
tooltip.setGraphic(description);
tooltip.setMaxHeight(10);
searchField.setTooltip(tooltip);

setHintTooltip(description);
}

private void setHintTooltip(TextFlow description) {
if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS)) {
String genericDescription = Localization.lang("Hint: To search specific fields only, enter for example:<p><tt>author=smith and title=electrical</tt>");
genericDescription = genericDescription.replace("<p>", "\n");
List<Text> genericDescriptionTexts = TooltipTextUtil.formatToTexts(genericDescription, new TooltipTextUtil.TextReplacement("<tt>author=smith and title=electrical</tt>", "author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));

if (description != null) {
description.getChildren().add(new Text("\n\n"));
description.getChildren().addAll(genericDescriptionTexts);
tooltip.setGraphic(description);
} else {
TextFlow emptyHintTooltip = new TextFlow();
emptyHintTooltip.getChildren().setAll(genericDescriptionTexts);
tooltip.setGraphic(emptyHintTooltip);
}
}
}

public void updateHintVisibility() {
if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS)) {
searchField.setTooltip(tooltip);
} else {
searchField.setTooltip(null);
}
calixtus marked this conversation as resolved.
Show resolved Hide resolved
setHintTooltip(null);
}

public void setSearchTerm(String searchTerm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public TextFlow getDescription() {
}
}

String genericDescription = "\n\n" + Localization.lang("Hint: To search specific fields only, enter for example:<p><tt>author=smith and title=electrical</tt>");
genericDescription = genericDescription.replace("<p>", "\n");
List<Text> genericDescriptionTexts = TooltipTextUtil.formatToTexts(genericDescription, new TooltipTextUtil.TextReplacement("<tt>author=smith and title=electrical</tt>", "author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
textList.add(getCaseSensitiveDescription());
textList.addAll(genericDescriptionTexts);

TextFlow searchDescription = new TextFlow();
searchDescription.getChildren().setAll(textList);
return searchDescription;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String RECENT_DATABASES = "recentDatabases";
public static final String RENAME_ON_MOVE_FILE_TO_FILE_DIR = "renameOnMoveFileToFileDir";
public static final String MEMORY_STICK_MODE = "memoryStickMode";
public static final String SHOW_ADVANCED_HINTS = "showAdvancedHints";
public static final String DEFAULT_OWNER = "defaultOwner";
public static final String DEFAULT_ENCODING = "defaultEncoding";
public static final String TOOLBAR_VISIBLE = "toolbarVisible";
Expand Down Expand Up @@ -590,6 +591,7 @@ private JabRefPreferences() {
defaults.put(DEFAULT_ENCODING, StandardCharsets.UTF_8.name());
defaults.put(DEFAULT_OWNER, System.getProperty("user.name"));
defaults.put(MEMORY_STICK_MODE, Boolean.FALSE);
defaults.put(SHOW_ADVANCED_HINTS, Boolean.TRUE);
defaults.put(RENAME_ON_MOVE_FILE_TO_FILE_DIR, Boolean.TRUE);

defaults.put(FONT_STYLE, Font.PLAIN);
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 @@ -533,6 +533,8 @@ Link=Link
Listen\ for\ remote\ operation\ on\ port=Listen for remote operation on port
Load\ and\ Save\ preferences\ from/to\ jabref.xml\ on\ start-up\ (memory\ stick\ mode)=Load and Save preferences from/to jabref.xml on start-up (memory stick mode)

Show\ advanced\ hints\ (i.e.\ helpful\ tooltips,\ suggestions\ and\ explanation)=Show advanced hints (i.e. helpful tooltips, suggestions and explanation)

Main\ file\ directory=Main file directory

Manage\ custom\ exports=Manage custom exports
Expand Down