From bc9b962be9467e5ed36730fad194b97623f6b1d4 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 30 May 2024 10:08:27 +0000 Subject: [PATCH] Ordering fixes --- .../xpipe/app/comp/store/StoreEntryComp.java | 38 ++++++++------- .../io/xpipe/app/comp/store/StoreSection.java | 46 +++++++++++-------- lang/app/strings/translations_da.properties | 3 ++ lang/app/strings/translations_de.properties | 3 ++ lang/app/strings/translations_en.properties | 2 + lang/app/strings/translations_es.properties | 3 ++ lang/app/strings/translations_fr.properties | 3 ++ lang/app/strings/translations_it.properties | 3 ++ lang/app/strings/translations_ja.properties | 3 ++ lang/app/strings/translations_nl.properties | 3 ++ lang/app/strings/translations_pt.properties | 3 ++ lang/app/strings/translations_ru.properties | 3 ++ lang/app/strings/translations_tr.properties | 3 ++ lang/app/strings/translations_zh.properties | 3 ++ 14 files changed, 85 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java index 6e150d61e..da3ab6bed 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java @@ -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()); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java b/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java index ae13e0c76..67bb0cda9 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreSection.java @@ -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() { + var explicitOrderComp = Comparator.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 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.comparingInt( value -> value.getWrapper().getEntry().getValidity().isUsable() ? -1 : 1); var comp = explicitOrderComp.thenComparing(usableComp); diff --git a/lang/app/strings/translations_da.properties b/lang/app/strings/translations_da.properties index ebdcf59ed..6ef13280d 100644 --- a/lang/app/strings/translations_da.properties +++ b/lang/app/strings/translations_da.properties @@ -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 ... diff --git a/lang/app/strings/translations_de.properties b/lang/app/strings/translations_de.properties index 6007c593e..50229daea 100644 --- a/lang/app/strings/translations_de.properties +++ b/lang/app/strings/translations_de.properties @@ -451,3 +451,6 @@ history=Browsing-Verlauf skipAll=Alles überspringen notes=Anmerkungen addNotes=Notizen hinzufügen +order=Bestellen ... +stickToTop=Oben bleiben +orderAheadOf=Vorbestellen ... diff --git a/lang/app/strings/translations_en.properties b/lang/app/strings/translations_en.properties index 325bd4a49..6d5fbbda9 100644 --- a/lang/app/strings/translations_en.properties +++ b/lang/app/strings/translations_en.properties @@ -456,3 +456,5 @@ notes=Notes addNotes=Add notes #context: verb order=Order ... +stickToTop=Keep on top +orderAheadOf=Order ahead of ... diff --git a/lang/app/strings/translations_es.properties b/lang/app/strings/translations_es.properties index f76d3d62c..b93169c4b 100644 --- a/lang/app/strings/translations_es.properties +++ b/lang/app/strings/translations_es.properties @@ -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 ... diff --git a/lang/app/strings/translations_fr.properties b/lang/app/strings/translations_fr.properties index 1694af0fe..1c88ecabb 100644 --- a/lang/app/strings/translations_fr.properties +++ b/lang/app/strings/translations_fr.properties @@ -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... diff --git a/lang/app/strings/translations_it.properties b/lang/app/strings/translations_it.properties index 395a0cccf..3f4d5ddbb 100644 --- a/lang/app/strings/translations_it.properties +++ b/lang/app/strings/translations_it.properties @@ -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 ... diff --git a/lang/app/strings/translations_ja.properties b/lang/app/strings/translations_ja.properties index 3291c001c..79f1ae8f4 100644 --- a/lang/app/strings/translations_ja.properties +++ b/lang/app/strings/translations_ja.properties @@ -438,3 +438,6 @@ history=閲覧履歴 skipAll=すべてスキップする notes=備考 addNotes=メモを追加する +order=注文する +stickToTop=トップをキープする +orderAheadOf=先に注文する diff --git a/lang/app/strings/translations_nl.properties b/lang/app/strings/translations_nl.properties index d4eacd941..9236fd5e2 100644 --- a/lang/app/strings/translations_nl.properties +++ b/lang/app/strings/translations_nl.properties @@ -438,3 +438,6 @@ history=Browsegeschiedenis skipAll=Alles overslaan notes=Opmerkingen addNotes=Opmerkingen toevoegen +order=Bestellen ... +stickToTop=Bovenaan houden +orderAheadOf=Vooruitbestellen ... diff --git a/lang/app/strings/translations_pt.properties b/lang/app/strings/translations_pt.properties index 8a33fd4d7..ae0171a76 100644 --- a/lang/app/strings/translations_pt.properties +++ b/lang/app/strings/translations_pt.properties @@ -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 ... diff --git a/lang/app/strings/translations_ru.properties b/lang/app/strings/translations_ru.properties index fcc988d47..06c9f19ec 100644 --- a/lang/app/strings/translations_ru.properties +++ b/lang/app/strings/translations_ru.properties @@ -438,3 +438,6 @@ history=История просмотров skipAll=Пропустить все notes=Заметки addNotes=Добавляй заметки +order=Заказать ... +stickToTop=Держись на высоте +orderAheadOf=Заказать заранее ... diff --git a/lang/app/strings/translations_tr.properties b/lang/app/strings/translations_tr.properties index d967eefa0..24e7ed2bc 100644 --- a/lang/app/strings/translations_tr.properties +++ b/lang/app/strings/translations_tr.properties @@ -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 ... diff --git a/lang/app/strings/translations_zh.properties b/lang/app/strings/translations_zh.properties index 798616c51..56d1dcc51 100644 --- a/lang/app/strings/translations_zh.properties +++ b/lang/app/strings/translations_zh.properties @@ -438,3 +438,6 @@ history=浏览历史 skipAll=全部跳过 notes=说明 addNotes=添加注释 +order=订购 ... +stickToTop=保持在顶部 +orderAheadOf=提前订购...