From baee77d47f829f1c34b7c63024fa7afd42c84338 Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 27 Mar 2024 12:44:35 +0000 Subject: [PATCH] More quick access fixes --- .../app/browser/BrowserFileListComp.java | 6 ++- .../browser/BrowserQuickAccessButtonComp.java | 37 +++++++++++++------ .../java/io/xpipe/app/util/BooleanTimer.java | 4 +- .../xpipe/app/util/HumanReadableFormat.java | 6 ++- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java index b37bd48df..04427da13 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserFileListComp.java @@ -528,11 +528,13 @@ final class BrowserFileListComp extends SimpleComp { Node imageView = PrettyImageHelper.ofFixedSize(img, 24, 24).createRegion(); HBox graphic = new HBox(imageView, - new Spacer(7), + new Spacer(5), quickAccess, - new Spacer(3), + new Spacer(1), textField); + quickAccess.prefHeightProperty().bind(graphic.heightProperty()); graphic.setAlignment(Pos.CENTER_LEFT); + graphic.setPrefHeight(34); HBox.setHgrow(textField, Priority.ALWAYS); graphic.setAlignment(Pos.CENTER_LEFT); setGraphic(graphic); diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java index 549cd06ee..b7fecf2f1 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java @@ -20,6 +20,7 @@ import javafx.scene.layout.Region; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -39,6 +40,7 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { button.apply(struc -> { struc.get().setOnAction(event -> { showMenu(struc.get()); + event.consume(); }); }); return button.createRegion(); @@ -62,8 +64,9 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { return; } + var actionsMenu = new AtomicReference(); var r = new Menu(); - var newItems = updateMenuItems(cm, r, fileEntry, true); + var newItems = updateMenuItems(cm, r, fileEntry, true, actionsMenu); Platform.runLater(() -> { cm.getItems().addAll(r.getItems()); cm.show(anchor, Side.RIGHT, 0, 0); @@ -71,7 +74,7 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { }); } - private MenuItem createItem(ContextMenu contextMenu, FileSystem.FileEntry fileEntry) { + private MenuItem createItem(ContextMenu contextMenu, FileSystem.FileEntry fileEntry, AtomicReference showingActionsMenu) { var browserCm = new BrowserContextMenu(model, new BrowserEntry(fileEntry, model.getFileList(), false)); browserCm.setOnAction(e -> { contextMenu.hide(); @@ -89,6 +92,7 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { } browserCm.show(m.getStyleableNode(), Side.RIGHT, 0, 0); + showingActionsMenu.set(browserCm); }); return m; } @@ -103,23 +107,31 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { var hover = new SimpleBooleanProperty(); m.setOnShowing(event -> { - browserCm.hide(); + var actionsMenu = showingActionsMenu.get(); + if (actionsMenu != null) { + actionsMenu.hide(); + showingActionsMenu.set(null); + } hover.set(true); event.consume(); }); m.setOnHiding(event -> { - browserCm.hide(); + var actionsMenu = showingActionsMenu.get(); + if (actionsMenu != null) { + actionsMenu.hide(); + showingActionsMenu.set(null); + } hover.set(false); event.consume(); }); - new BooleanTimer(hover, 500, () -> { + new BooleanTimer(hover, 100, () -> { if (m.isShowing() && !m.getItems().getFirst().equals(empty)) { return; } List newItems = null; try { - newItems = updateMenuItems(contextMenu, m, fileEntry, false); + newItems = updateMenuItems(contextMenu, m, fileEntry, false, showingActionsMenu); m.getItems().setAll(newItems); if (!browserCm.isShowing()) { m.hide(); @@ -135,21 +147,24 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { return; } - if (browserCm.isShowing()) { - browserCm.hide(); + var actionsMenu = showingActionsMenu.get(); + if (actionsMenu != null && actionsMenu.isShowing()) { + actionsMenu.hide(); + showingActionsMenu.set(null); m.show(); return; } m.hide(); browserCm.show(m.getStyleableNode(), Side.RIGHT, 0, 0); + showingActionsMenu.set(browserCm); event.consume(); }); return m; } private List updateMenuItems( - ContextMenu contextMenu, Menu m, FileSystem.FileEntry fileEntry, boolean updateInstantly) throws Exception { + ContextMenu contextMenu, Menu m, FileSystem.FileEntry fileEntry, boolean updateInstantly, AtomicReference showingActionsMenu) throws Exception { var newFiles = model.getFileSystem().listFiles(fileEntry.getPath()); try (var s = newFiles) { var list = s.toList(); @@ -169,12 +184,12 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { return o1.getName().compareToIgnoreCase(o2.getName()); }) .collect(Collectors.toMap( - e -> e, e -> createItem(contextMenu, e), (v1, v2) -> v2, LinkedHashMap::new)); + e -> e, e -> createItem(contextMenu, e, showingActionsMenu), (v1, v2) -> v2, LinkedHashMap::new)); var dirs = list.stream() .filter(e -> e.getKind() == FileKind.DIRECTORY) .toList(); if (dirs.size() == 1) { - updateMenuItems(contextMenu, (Menu) menus.get(dirs.getFirst()), list.getFirst(), updateInstantly); + updateMenuItems(contextMenu, (Menu) menus.get(dirs.getFirst()), list.getFirst(), updateInstantly, showingActionsMenu); } newItems.addAll(menus.values()); } diff --git a/app/src/main/java/io/xpipe/app/util/BooleanTimer.java b/app/src/main/java/io/xpipe/app/util/BooleanTimer.java index 8bcd70c1a..20546843e 100644 --- a/app/src/main/java/io/xpipe/app/util/BooleanTimer.java +++ b/app/src/main/java/io/xpipe/app/util/BooleanTimer.java @@ -24,7 +24,7 @@ public class BooleanTimer { if (timer.get() == null) { timer.set(new AnimationTimer() { - long init =0; + long init = 0; @Override public void handle(long now) { @@ -33,7 +33,7 @@ public class BooleanTimer { } var nowMs = now; - if ((nowMs - init) > duration * 1000L) { + if ((nowMs - init) > duration * 1_000_000L) { toExecute.run(); stop(); } diff --git a/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java b/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java index 626e2c0c3..9fb9b1095 100644 --- a/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java +++ b/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java @@ -28,7 +28,11 @@ public final class HumanReadableFormat { ci.next(); } var f = "%.1f"; - return String.format(f + " %cB", bytes / (double) b, ci.current()); + var r = String.format(f + " %cB", bytes / (double) b, ci.current()); + if (r.endsWith(".0")) { + r = r.substring(0, r.length() - 2); + } + return r; } public static String progressByteCount(long bytes) {