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

Change the popup to enter types to the combo box for custom entry types #10912

Merged
merged 4 commits into from
Feb 25, 2024
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
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextInputDialog;
import javafx.util.StringConverter;

import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.DirectoryDialogConfiguration;
Expand Down Expand Up @@ -42,6 +43,12 @@ default <T> Optional<T> showChoiceDialogAndWait(String title, String content, St
return showChoiceDialogAndWait(title, content, okButtonLabel, null, choices);
}

<T> Optional<T> showEditableChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices, StringConverter<T> converter);

default <T> Optional<T> showEditableChoiceDialogAndWait(String title, String content, String okButtonLabel, Collection<T> choices, StringConverter<T> converter) {
return showEditableChoiceDialogAndWait(title, content, okButtonLabel, null, choices, converter);
}

/**
* This will create and display new {@link TextInputDialog} with a text fields to enter data
*/
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
Expand All @@ -35,6 +36,7 @@
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration;
import javafx.util.StringConverter;

import org.jabref.gui.help.ErrorConsoleAction;
import org.jabref.gui.icon.IconTheme;
Expand Down Expand Up @@ -129,8 +131,7 @@ public static String shortenDialogMessage(String dialogMessage) {
return (dialogMessage.substring(0, Math.min(dialogMessage.length(), JabRefDialogService.DIALOG_SIZE_LIMIT)) + "...").trim();
}

@Override
public <T> Optional<T> showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices) {
private <T> ChoiceDialog<T> createChoiceDialog(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices) {
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(defaultChoice, choices);
((Stage) choiceDialog.getDialogPane().getScene().getWindow()).getIcons().add(IconTheme.getJabRefImage());
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
Expand All @@ -139,6 +140,21 @@ public <T> Optional<T> showChoiceDialogAndWait(String title, String content, Str
choiceDialog.setTitle(title);
choiceDialog.setContentText(content);
choiceDialog.initOwner(mainWindow);
return choiceDialog;
}

@Override
public <T> Optional<T> showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices) {
return createChoiceDialog(title, content, okButtonLabel, defaultChoice, choices).showAndWait();
}

@Override
public <T> Optional<T> showEditableChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices, StringConverter<T> converter) {
ChoiceDialog<T> choiceDialog = createChoiceDialog(title, content, okButtonLabel, defaultChoice, choices);
ComboBox<T> comboBox = (ComboBox<T>) choiceDialog.getDialogPane().lookup(".combo-box");
comboBox.setEditable(true);
comboBox.setConverter(converter);
EasyBind.subscribe(comboBox.getEditor().textProperty(), text -> comboBox.setValue(converter.fromString(text)));
return choiceDialog.showAndWait();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.libraryproperties.PropertiesTabViewModel;
import org.jabref.gui.util.FieldsUtil;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
Expand Down Expand Up @@ -126,8 +127,11 @@ BooleanBinding isNoKeywordSelected() {
}

void showInputFieldNameDialog() {
dialogService.showInputDialogAndWait(Localization.lang("Add new field name"), Localization.lang("Field name"))
.map(FieldFactory::parseField)
dialogService.showEditableChoiceDialogAndWait(Localization.lang("Add new field name"),
Localization.lang("Field name"),
Localization.lang("Add"),
FXCollections.observableArrayList(FieldFactory.getStandardFieldsWithCitationKey()),
FieldsUtil.FIELD_STRING_CONVERTER)
.ifPresent(this::addFieldIfUnique);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void initialize() {
setupFieldsTable();

addNewEntryTypeButton.disableProperty().bind(viewModel.entryTypeValidationStatus().validProperty().not());
addNewFieldButton.disableProperty().bind(viewModel.fieldValidationStatus().validProperty().not());
addNewFieldButton.disableProperty().bind(viewModel.fieldValidationStatus().validProperty().not().or(viewModel.selectedEntryTypeProperty().isNull()));

Platform.runLater(() -> {
visualizer.initVisualization(viewModel.entryTypeValidationStatus(), addNewEntryType, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import javafx.collections.FXCollections;

import org.jabref.gui.DialogService;
import org.jabref.gui.util.FieldsUtil;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;

Expand Down Expand Up @@ -146,10 +148,13 @@ private void removeKeyword(Field field, String keyword) {
}

private void addField(Field field) {
when(dialogService.showInputDialogAndWait(
Localization.lang("Add new field name"), Localization.lang("Field name")))
.thenReturn(Optional.of(field.getDisplayName()));

when(dialogService.showEditableChoiceDialogAndWait(
Localization.lang("Add new field name"),
Localization.lang("Field name"),
Localization.lang("Add"),
FXCollections.observableArrayList(FieldFactory.getStandardFieldsWithCitationKey()),
FieldsUtil.FIELD_STRING_CONVERTER))
.thenReturn(Optional.of(field));
viewModel.showInputFieldNameDialog();
}

Expand Down
Loading