Skip to content

Commit

Permalink
added search for key binds (JabRef#11953)
Browse files Browse the repository at this point in the history
* added search for key binds

* use the correct localization key to deal with ellipsis

---------

Co-authored-by: Carl Christian Snethlage <[email protected]>
  • Loading branch information
2 people authored and ExrosZ-Alt committed Oct 21, 2024
1 parent b60d898 commit 9c47fc4
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)
- We added a setting which always adds the literal "Cited on pages" text before each JStyle citation. [#11691](https://github.com/JabRef/jabref/pull/11732)
- We added a new plain citation parser that uses LLMs. [#11825](https://github.com/JabRef/jabref/issues/11825)
- We added a search bar for filtering keyboard shortcuts. [#11686](https://github.com/JabRef/jabref/issues/11686)
- By double clicking on a local citation in the Citation Relations Tab you can now jump the the linked entry. [#11955](https://github.com/JabRef/jabref/pull/11955)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/groups/GroupDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void openIconPicker() {
}

CustomTextField searchBox = new CustomTextField();
searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setPromptText(Localization.lang("Search..."));
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());
searchBox.textProperty().addListener((obs, oldValue, newValue) ->
filteredList.setPredicate(ikon -> newValue.isEmpty() || ikon.getDescription().toLowerCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void initialize() {
preferenceTabList.getSelectionModel().clearSelection();
preferenceTabList.getSelectionModel().selectFirst();
});
searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setPromptText(Localization.lang("Search..."));
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());

EasyBind.subscribe(preferenceTabList.getSelectionModel().selectedItemProperty(), tab -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void initialize() {
setBindings();
setAnimations();

searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setPromptText(Localization.lang("Search..."));
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());
}

Expand Down Expand Up @@ -139,7 +139,7 @@ private void setBindings() {

private void setAnimations() {
ObjectProperty<Color> flashingColor = new SimpleObjectProperty<>(Color.TRANSPARENT);
StringProperty flashingColorStringProperty = createFlashingColorStringProperty(flashingColor);
StringProperty flashingColorStringProperty = ColorUtil.createFlashingColorStringProperty(flashingColor);

searchBox.styleProperty().bind(
new SimpleStringProperty("-fx-control-inner-background: ").concat(flashingColorStringProperty).concat(";")
Expand Down Expand Up @@ -183,17 +183,6 @@ private void addAbbreviationActions() {
editAbbreviation();
}

private static StringProperty createFlashingColorStringProperty(final ObjectProperty<Color> flashingColor) {
final StringProperty flashingColorStringProperty = new SimpleStringProperty();
setColorStringFromColor(flashingColorStringProperty, flashingColor);
flashingColor.addListener((observable, oldValue, newValue) -> setColorStringFromColor(flashingColorStringProperty, flashingColor));
return flashingColorStringProperty;
}

private static void setColorStringFromColor(StringProperty colorStringProperty, ObjectProperty<Color> color) {
colorStringProperty.set(ColorUtil.toRGBACode(color.get()));
}

@FXML
private void editAbbreviation() {
journalAbbreviationsTable.edit(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
Expand All @@ -8,23 +9,32 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import org.jabref.gui.icon.JabRefIconView?>
<?import org.controlsfx.control.textfield.CustomTextField?>
<fx:root spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jabref.gui.preferences.keybindings.KeyBindingsTab">

<Label styleClass="titleHeader" text="%Keyboard shortcuts"/>

<TreeTableView fx:id="keyBindingsTable" showRoot="false" styleClass="keybinding-table">
<columns>
<TreeTableColumn fx:id="actionColumn" prefWidth="200.0" text="%Action"/>
<TreeTableColumn fx:id="shortcutColumn" prefWidth="100.0" text="%Shortcut"/>
<TreeTableColumn fx:id="resetColumn" maxWidth="25.0" prefWidth="25.0" minWidth="25.0"/>
<TreeTableColumn fx:id="clearColumn" maxWidth="25.0" prefWidth="25.0" minWidth="25.0"/>
</columns>
<columnResizePolicy>
<TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TreeTableView>
<VBox spacing="10.0" HBox.hgrow="ALWAYS">
<CustomTextField fx:id="searchBox" promptText="%Filter" VBox.vgrow="NEVER">
<VBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0"/>
</VBox.margin>
</CustomTextField>

<TreeTableView fx:id="keyBindingsTable" showRoot="false" styleClass="keybinding-table">
<columns>
<TreeTableColumn fx:id="actionColumn" prefWidth="200.0" text="%Action"/>
<TreeTableColumn fx:id="shortcutColumn" prefWidth="100.0" text="%Shortcut"/>
<TreeTableColumn fx:id="resetColumn" maxWidth="25.0" prefWidth="25.0" minWidth="25.0"/>
<TreeTableColumn fx:id="clearColumn" maxWidth="25.0" prefWidth="25.0" minWidth="25.0"/>
</columns>
<columnResizePolicy>
<TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TreeTableView>
</VBox>

<HBox spacing="10.0" alignment="CENTER_RIGHT">
<MenuButton fx:id="presetsButton" text="%Presets" styleClass="button"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.jabref.gui.preferences.keybindings;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
Expand All @@ -8,22 +12,27 @@
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.paint.Color;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.preferences.keybindings.presets.KeyBindingPreset;
import org.jabref.gui.util.ColorUtil;
import org.jabref.gui.util.RecursiveTreeItem;
import org.jabref.gui.util.ViewModelTreeTableCellFactory;
import org.jabref.logic.l10n.Localization;

import com.airhacks.afterburner.views.ViewLoader;
import com.tobiasdiez.easybind.EasyBind;
import jakarta.inject.Inject;
import org.controlsfx.control.textfield.CustomTextField;

public class KeyBindingsTab extends AbstractPreferenceTabView<KeyBindingsTabViewModel> implements PreferencesTab {

@FXML private CustomTextField searchBox;
@FXML private TreeTableView<KeyBindingViewModel> keyBindingsTable;
@FXML private TreeTableColumn<KeyBindingViewModel, String> actionColumn;
@FXML private TreeTableColumn<KeyBindingViewModel, String> shortcutColumn;
Expand Down Expand Up @@ -71,6 +80,19 @@ private void initialize() {
.install(clearColumn);

viewModel.keyBindingPresets().forEach(preset -> presetsButton.getItems().add(createMenuItem(preset)));

searchBox.textProperty().addListener((observable, previousText, searchTerm) ->
viewModel.filterValues(searchTerm));

ObjectProperty<Color> flashingColor = new SimpleObjectProperty<>(Color.TRANSPARENT);
StringProperty flashingColorStringProperty = ColorUtil.createFlashingColorStringProperty(flashingColor);

searchBox.styleProperty().bind(
new SimpleStringProperty("-fx-control-inner-background: ").concat(flashingColorStringProperty).concat(";")
);

searchBox.setPromptText(Localization.lang("Search..."));
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());
}

private MenuItem createMenuItem(KeyBindingPreset preset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,28 @@ public KeyBindingsTabViewModel(KeyBindingRepository keyBindingRepository, Dialog
@Override
public void setValues() {
KeyBindingViewModel root = new KeyBindingViewModel(keyBindingRepository, KeyBindingCategory.FILE);
rootKeyBinding.set(root);
filterValues("");
}

public void filterValues(String term) {
KeyBindingViewModel root = rootKeyBinding.get();
root.clear();
root.getChildren().clear();
for (KeyBindingCategory category : KeyBindingCategory.values()) {
KeyBindingViewModel categoryItem = new KeyBindingViewModel(keyBindingRepository, category);
keyBindingRepository.getKeyBindings().forEach((keyBinding, bind) -> {
if (keyBinding.getCategory() == category) {
if (keyBinding.getCategory() == category &&
(keyBinding.getLocalization().toLowerCase().contains(term.toLowerCase()) ||
keyBinding.getCategory().getName().toLowerCase().contains(term.toLowerCase()))) {
KeyBindingViewModel keyBindViewModel = new KeyBindingViewModel(keyBindingRepository, keyBinding, bind);
categoryItem.getChildren().add(keyBindViewModel);
}
});
root.getChildren().add(categoryItem);
if (!categoryItem.getChildren().isEmpty()) {
root.getChildren().add(categoryItem);
}
}
rootKeyBinding.set(root);
}

public void setNewBindingForCurrent(KeyEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void initialize() {
showAsTabCheckBox.selectedProperty().bindBidirectional(viewModel.showAsExtraTabProperty());
showPreviewTooltipCheckBox.selectedProperty().bindBidirectional(viewModel.showPreviewInEntryTableTooltip());

searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setPromptText(Localization.lang("Search..."));
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());

ActionFactory factory = new ActionFactory();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/gui/util/ColorUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jabref.gui.util;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.paint.Color;

public class ColorUtil {
Expand All @@ -22,4 +25,15 @@ public static String toRGBACode(Color color) {
public static String toHex(Color validFieldBackgroundColor) {
return "#%02x%02x%02x".formatted((int) validFieldBackgroundColor.getRed(), (int) validFieldBackgroundColor.getGreen(), (int) validFieldBackgroundColor.getBlue());
}

public static StringProperty createFlashingColorStringProperty(final ObjectProperty<Color> flashingColor) {
final StringProperty flashingColorStringProperty = new SimpleStringProperty();
setColorStringFromColor(flashingColorStringProperty, flashingColor);
flashingColor.addListener((observable, oldValue, newValue) -> setColorStringFromColor(flashingColorStringProperty, flashingColor));
return flashingColorStringProperty;
}

public static void setColorStringFromColor(StringProperty colorStringProperty, ObjectProperty<Color> color) {
colorStringProperty.set(ColorUtil.toRGBACode(color.get()));
}
}

0 comments on commit 9c47fc4

Please sign in to comment.