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

Added icon picker in group dialog #7776

Merged
merged 16 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added the option to copy the DOI of an entry directly from the context menu copy submenu. [#7826](https://github.com/JabRef/jabref/issues/7826)
- We added a fulltext search feature. [#2838](https://github.com/JabRef/jabref/pull/2838)
- We added unprotect_terms to the list of bracketed pattern modifiers [#7826](https://github.com/JabRef/jabref/pull/7960)
- We added an icon picker in group edit dialog. [#6142](https://github.com/JabRef/jabref/issues/6142)

### Changed

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
<HBox spacing="10.0">
<VBox HBox.hgrow="ALWAYS">
<Label text="%Icon"/>
<TextField fx:id="iconField"/>
<HBox>
<TextField fx:id="iconField"/>
<Button fx:id="iconPickerButton" onAction="#openIconPicker" styleClass="icon-button,narrow">
<graphic>
<JabRefIconView glyph="SELECT_ICONS"/>
</graphic>
</Button>
</HBox>
</VBox>
<VBox layoutX="10.0" layoutY="10.0" minWidth="130.0" maxWidth="130.0" prefWidth="130.0">
<Label text="%Color"/>
Expand Down
100 changes: 90 additions & 10 deletions src/main/java/org/jabref/gui/groups/GroupDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@

import java.util.EnumMap;
import java.util.EnumSet;
import java.util.ServiceLoader;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

import org.jabref.gui.DialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabrefIconProvider;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.gui.util.ViewModelListCellFactory;
Expand All @@ -28,13 +42,21 @@

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
import org.controlsfx.control.GridCell;
import org.controlsfx.control.GridView;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.textfield.CustomTextField;
import org.kordamp.ikonli.Ikon;
import org.kordamp.ikonli.IkonProvider;
import org.kordamp.ikonli.javafx.FontIcon;

public class GroupDialogView extends BaseDialog<AbstractGroup> {

// Basic Settings
@FXML private TextField nameField;
@FXML private TextField descriptionField;
@FXML private TextField iconField;
@FXML private Button iconPickerButton;
@FXML private ColorPicker colorField;
@FXML private ComboBox<GroupHierarchyType> hierarchicalContextCombo;

Expand Down Expand Up @@ -70,7 +92,11 @@ public class GroupDialogView extends BaseDialog<AbstractGroup> {
private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();
private final GroupDialogViewModel viewModel;

public GroupDialogView(DialogService dialogService, BibDatabaseContext currentDatabase, PreferencesService preferencesService, AbstractGroup editedGroup, GroupDialogHeader groupDialogHeader) {
public GroupDialogView(DialogService dialogService,
BibDatabaseContext currentDatabase,
PreferencesService preferencesService,
AbstractGroup editedGroup,
GroupDialogHeader groupDialogHeader) {
viewModel = new GroupDialogViewModel(dialogService, currentDatabase, preferencesService, editedGroup, groupDialogHeader);

ViewLoader.view(this)
Expand All @@ -91,6 +117,7 @@ public GroupDialogView(DialogService dialogService, BibDatabaseContext currentDa
getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL);

final Button confirmDialogButton = (Button) getDialogPane().lookupButton(ButtonType.OK);
confirmDialogButton.disableProperty().bind(viewModel.validationStatus().validProperty().not());
// handle validation before closing dialog and calling resultConverter
confirmDialogButton.addEventFilter(ActionEvent.ACTION, viewModel::validationHandler);
}
Expand Down Expand Up @@ -168,15 +195,6 @@ public void initialize() {
validationVisualizer.initVisualization(viewModel.texGroupFilePathValidatonStatus(), texGroupFilePath);
nameField.requestFocus();
});

// Binding to the button throws a NPE, since it doesn't exist yet. Working around.
viewModel.validationStatus().validProperty().addListener((obs, _oldValue, validationStatus) -> {
if (validationStatus) {
getDialogPane().lookupButton(ButtonType.OK).setDisable(false);
} else {
getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
}
});
}

@FXML
Expand All @@ -188,4 +206,66 @@ private void texGroupBrowse() {
private void openHelp() {
viewModel.openHelpPage();
}

@FXML
private void openIconPicker() {
ObservableList<Ikon> ikonList = FXCollections.observableArrayList();
FilteredList<Ikon> filteredList = new FilteredList<>(ikonList);

for (IkonProvider provider : ServiceLoader.load(IkonProvider.class.getModule().getLayer(), IkonProvider.class)) {
if (provider.getClass() != JabrefIconProvider.class) {
ikonList.addAll(EnumSet.allOf(provider.getIkon()));
}
}

CustomTextField searchBox = new CustomTextField();
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()
.contains(newValue.toLowerCase())));

GridView<Ikon> ikonGridView = new GridView<>(FXCollections.observableArrayList());
ikonGridView.setCellFactory(gridView -> new IkonliCell());
ikonGridView.setPrefWidth(520);
ikonGridView.setPrefHeight(400);
ikonGridView.setHorizontalCellSpacing(4);
ikonGridView.setVerticalCellSpacing(4);
ikonGridView.setItems(filteredList);

VBox vBox = new VBox(10, searchBox, ikonGridView);
vBox.setPadding(new Insets(10));

PopOver popOver = new PopOver(vBox);
popOver.setDetachable(false);
popOver.setArrowSize(0);
popOver.setCornerRadius(0);
popOver.setTitle("Icon picker");
popOver.show(iconPickerButton);
}

public class IkonliCell extends GridCell<Ikon> {
@Override
protected void updateItem(Ikon ikon, boolean empty) {
super.updateItem(ikon, empty);
if (empty || ikon == null) {
setText(null);
setGraphic(null);
} else {
FontIcon fontIcon = FontIcon.of(ikon);
fontIcon.getStyleClass().setAll("font-icon");
fontIcon.setIconSize(22);
setGraphic(fontIcon);
setAlignment(Pos.BASELINE_CENTER);
setPadding(new Insets(1));
setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderStroke.THIN)));

setOnMouseClicked(event -> {
iconField.textProperty().setValue(String.valueOf(fontIcon.getIconCode()));
PopOver stage = (PopOver) this.getGridView().getParent().getScene().getWindow();
stage.hide();
});
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ public enum JabRefIcons implements JabRefIcon {
HOME(MaterialDesignH.HOME),
LINK(MaterialDesignL.LINK),
LINK_VARIANT(MaterialDesignL.LINK_VARIANT),
PROTECT_STRING(MaterialDesignC.CODE_BRACES);
PROTECT_STRING(MaterialDesignC.CODE_BRACES),
SELECT_ICONS(MaterialDesignA.APPS);

private final JabRefIcon icon;

Expand Down