Skip to content

Commit

Permalink
Resort the strings table for new entry
Browse files Browse the repository at this point in the history
Adding a new entry should also preserve the sorting of the strings
table, thus we need to resort the entries and take care that the focus
in the table is still on the newly-created entry.
  • Loading branch information
stephanlukasczyk committed Jul 15, 2023
1 parent 6450bd9 commit 90adb53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ public void initialize() {
cellItem.setLabel(cellEvent.getNewValue());
}

cellEvent.getTableView().refresh();
// Resort the entries based on the keys and set the focus to the newly-created entry
viewModel.resortStrings();
var selectionModel = cellEvent.getTableView().getSelectionModel();
var tableView = cellEvent.getTableView();
selectionModel.select(cellItem);
selectionModel.focus(selectionModel.getSelectedIndex());
tableView.refresh();
tableView.scrollTo(cellItem);
});

contentColumn.setSortable(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.libraryproperties.constants;

import java.util.Comparator;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -70,6 +72,11 @@ public void removeString(ConstantsItemModel item) {
stringsListProperty.remove(item);
}

public void resortStrings() {
// Resort the strings list in the same order as setValues() does
stringsListProperty.sort(Comparator.comparing(c -> c.labelProperty().get().toLowerCase(Locale.ROOT)));
}

private ConstantsItemModel convertFromBibTexString(BibtexString bibtexString) {
return new ConstantsItemModel(bibtexString.getName(), bibtexString.getContent());
}
Expand Down

0 comments on commit 90adb53

Please sign in to comment.