Ordering fixes

This commit is contained in:
crschnick 2024-05-30 10:08:27 +00:00
parent ae02fb3791
commit bc9b962be9
14 changed files with 85 additions and 34 deletions

View file

@ -428,7 +428,7 @@ public abstract class StoreEntryComp extends SimpleComp {
}
var order = new Menu(AppI18n.get("order"), new FontIcon("mdal-bookmarks"));
var noOrder = new MenuItem("None");
var noOrder = new MenuItem(AppI18n.get("none"), new FontIcon("mdi2r-reorder-horizontal"));
noOrder.setOnAction(event -> {
DataStorage.get().orderBefore(wrapper.getEntry(), null);
event.consume();
@ -437,7 +437,8 @@ public abstract class StoreEntryComp extends SimpleComp {
noOrder.setDisable(true);
}
order.getItems().add(noOrder);
var stick = new MenuItem(AppI18n.get("stickToTop"));
order.getItems().add(new SeparatorMenuItem());
var stick = new MenuItem(AppI18n.get("stickToTop"), new FontIcon("mdi2o-order-bool-descending"));
stick.setOnAction(event -> {
DataStorage.get().orderBefore(wrapper.getEntry(), wrapper.getEntry());
event.consume();
@ -447,22 +448,27 @@ public abstract class StoreEntryComp extends SimpleComp {
}
order.getItems().add(stick);
order.getItems().add(new SeparatorMenuItem());
var desc = new MenuItem(AppI18n.get("orderAheadOf"), new FontIcon("mdi2o-order-bool-descending-variant"));
desc.setDisable(true);
order.getItems().add(desc);
var section = StoreViewState.get().getParentSectionForWrapper(wrapper);
section.get().getAllChildren().getList().forEach(other -> {
var ow = other.getWrapper();
var op = ow.getEntry().getProvider();
MenuItem m = new MenuItem(ow.getName().getValue(),
op != null ? PrettyImageHelper.ofFixedSizeSquare(op.getDisplayIconFileName(ow.getEntry().getStore()),
16).createRegion() : null);
if (ow.getEntry().getUuid().equals(wrapper.getEntry().getOrderBefore())) {
m.setDisable(true);
}
m.setOnAction(event -> {
wrapper.orderBefore(ow);
event.consume();
if (section.isPresent()) {
section.get().getAllChildren().getList().forEach(other -> {
var ow = other.getWrapper();
var op = ow.getEntry().getProvider();
MenuItem m = new MenuItem(ow.getName().getValue(),
op != null ? PrettyImageHelper.ofFixedSizeSquare(op.getDisplayIconFileName(ow.getEntry().getStore()),
16).createRegion() : null);
if (other.getWrapper().equals(wrapper) || ow.getEntry().getUuid().equals(wrapper.getEntry().getOrderBefore())) {
m.setDisable(true);
}
m.setOnAction(event -> {
wrapper.orderBefore(ow);
event.consume();
});
order.getItems().add(m);
});
order.getItems().add(m);
});
}
contextMenu.getItems().add(order);
contextMenu.getItems().add(new SeparatorMenuItem());

View file

@ -15,7 +15,10 @@ import javafx.collections.FXCollections;
import lombok.Value;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.function.ToIntFunction;
@Value
public class StoreSection {
@ -62,29 +65,36 @@ public class StoreSection {
return list;
}
var explicitOrderComp = new Comparator<StoreSection>() {
var explicitOrderComp = Comparator.<StoreSection>comparingInt(new ToIntFunction<>() {
@Override
public int compare(StoreSection o1, StoreSection o2) {
var explicit1 = o1.getWrapper().getEntry().getOrderBefore();
var explicit2 = o2.getWrapper().getEntry().getOrderBefore();
if (explicit1 == null && explicit2 == null) {
return 0;
}
if (explicit1 != null && explicit2 == null) {
return -1;
}
if (explicit2 != null && explicit1 == null) {
public int applyAsInt(StoreSection value) {
var explicit = value.getWrapper().getEntry().getOrderBefore();
if (explicit == null) {
return 1;
}
if (explicit1.equals(o2.getWrapper().getEntry().getUuid())) {
return -1;
if (explicit.equals(value.getWrapper().getEntry().getUuid())) {
return Integer.MIN_VALUE;
}
if (explicit2.equals(o1.getWrapper().getEntry().getUuid())) {
return -1;
}
return 0;
return -count(value.getWrapper(), new HashSet<>());
}
};
private int count(StoreEntryWrapper wrapper, Set<StoreEntryWrapper> seen) {
if (seen.contains(wrapper)) {
// Loop!
return 0;
}
seen.add(wrapper);
var found = list.getList().stream().filter(section -> wrapper.getEntry().getOrderBefore().equals(section.getWrapper().getEntry().getUuid())).findFirst();
if (found.isPresent()) {
return count(found.get().getWrapper(), seen);
} else {
return seen.size();
}
}
});
var usableComp = Comparator.<StoreSection>comparingInt(
value -> value.getWrapper().getEntry().getValidity().isUsable() ? -1 : 1);
var comp = explicitOrderComp.thenComparing(usableComp);

View file

@ -457,3 +457,6 @@ history=Browsing-historik
skipAll=Spring alle over
notes=Bemærkninger
addNotes=Tilføj noter
order=Bestille ...
stickToTop=Hold dig på toppen
orderAheadOf=Bestil på forhånd ...

View file

@ -451,3 +451,6 @@ history=Browsing-Verlauf
skipAll=Alles überspringen
notes=Anmerkungen
addNotes=Notizen hinzufügen
order=Bestellen ...
stickToTop=Oben bleiben
orderAheadOf=Vorbestellen ...

View file

@ -456,3 +456,5 @@ notes=Notes
addNotes=Add notes
#context: verb
order=Order ...
stickToTop=Keep on top
orderAheadOf=Order ahead of ...

View file

@ -438,3 +438,6 @@ history=Historial de navegación
skipAll=Saltar todo
notes=Notas
addNotes=Añadir notas
order=Ordenar ...
stickToTop=Mantener arriba
orderAheadOf=Haz tu pedido antes de ...

View file

@ -438,3 +438,6 @@ history=Historique de navigation
skipAll=Sauter tout
notes=Notes
addNotes=Ajouter des notes
order=Commander...
stickToTop=Garde le dessus
orderAheadOf=Commande en avance...

View file

@ -438,3 +438,6 @@ history=Cronologia di navigazione
skipAll=Salta tutto
notes=Note
addNotes=Aggiungi note
order=Ordinare ...
stickToTop=Continua a essere in cima
orderAheadOf=Ordina prima di ...

View file

@ -438,3 +438,6 @@ history=閲覧履歴
skipAll=すべてスキップする
notes=備考
addNotes=メモを追加する
order=注文する
stickToTop=トップをキープする
orderAheadOf=先に注文する

View file

@ -438,3 +438,6 @@ history=Browsegeschiedenis
skipAll=Alles overslaan
notes=Opmerkingen
addNotes=Opmerkingen toevoegen
order=Bestellen ...
stickToTop=Bovenaan houden
orderAheadOf=Vooruitbestellen ...

View file

@ -438,3 +438,6 @@ history=Histórico de navegação
skipAll=Salta tudo
notes=Nota
addNotes=Adiciona notas
order=Encomenda ...
stickToTop=Mantém-te no topo
orderAheadOf=Encomenda antes de ...

View file

@ -438,3 +438,6 @@ history=История просмотров
skipAll=Пропустить все
notes=Заметки
addNotes=Добавляй заметки
order=Заказать ...
stickToTop=Держись на высоте
orderAheadOf=Заказать заранее ...

View file

@ -439,3 +439,6 @@ history=Tarama geçmişi
skipAll=Tümünü atla
notes=Notlar
addNotes=Notlar ekleyin
order=Sipariş ...
stickToTop=Zirvede kal
orderAheadOf=Önceden sipariş verin ...

View file

@ -438,3 +438,6 @@ history=浏览历史
skipAll=全部跳过
notes=说明
addNotes=添加注释
order=订购 ...
stickToTop=保持在顶部
orderAheadOf=提前订购...