Skip to content

Conversation

Akanksha928
Copy link

Closes #13780

This PR introduces a dedicated "Clear content" tab in the Automatic Field Editor:

  • Added a new "Clear content" tab with a dropdown to select the field to clear
  • Added a "Show only set fields" checkbox to filter the dropdown to fields actually filled in selected entries
  • Removed the "Clear field content" button from the "Edit content" tab (moved functionality to the new tab)
  • Clearing supports Undo/Redo via NamedCompound + UndoableFieldChange
  • Added i18n keys for all new UI text
image

Steps to test

  1. Open or create a library with a few entries (fill in some fields like author, journal).
  2. Select one or more entries.
  3. Open Edit → Automatic field editor.
  4. Switch to the new Clear content tab.
  5. Toggle the "Show only set fields" checkbox: the dropdown should shrink to only the fields currently filled.
  6. Select a field (e.g., author) and click Clear field content: the field value should be removed from all selected entries.
  7. Press Ctrl+Z: the cleared field(s) should be restored.

screenshot of Clear content tab

Mandatory checks

Field chosen = fieldCombo.getValue(); // keep ComboBox<Field>
if (chosen != null) {
viewModel.clearField(chosen); // VM builds/publishes the undo compound
System.out.println("Cleared field: " + chosen.getName());
Copy link
Member

Choose a reason for hiding this comment

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

No System.out and remove the comments


List<BibEntry> selected = stateManager.getSelectedEntries();
for (BibEntry entry : selected) {
// clearField returns Optional<FieldChange>
Copy link
Member

Choose a reason for hiding this comment

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

remove comments

List<BibEntry> selected = stateManager.getSelectedEntries();
Set<Field> setFields = new LinkedHashSet<>();

for (BibEntry entry : selected) {
Copy link
Member

Choose a reason for hiding this comment

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

can be refactored into a stream

private final ClearContentViewModel viewModel;

public ClearContentTabView(StateManager stateManager) {
super();
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reasony why you did not creae an fxml? I guess you used AI..

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I initially used AI to generate the layout in Java so I could focus on getting the logic working first but forgot to move it into a proper FXML file. I've made the changes now.

@Siedlerchr Siedlerchr added the status: changes-required Pull requests that are not yet complete label Sep 8, 2025
Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

.

@calixtus
Copy link
Member

calixtus commented Sep 8, 2025

Sorry, misunderstood PR. Nevermind.

Comment on lines +28 to +33
public Set<Field> getSetFieldsOnly() {
return stateManager.getSelectedEntries().stream()
.flatMap(entry -> entry.getFields().stream()
.filter(f -> entry.getField(f).isPresent() && !entry.getField(f).get().isBlank()))
.collect(Collectors.toCollection(LinkedHashSet::new));
}
Copy link

Choose a reason for hiding this comment

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

The method uses Optional.isPresent() followed by get() which is an anti-pattern. Should use Optional.map() or filter() instead to handle the Optional value in a more functional way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes-required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic field editor: Checkbox: Show only set fields
3 participants