More quick access fixes

This commit is contained in:
crschnick 2024-03-27 12:44:35 +00:00
parent 76379b5a5d
commit baee77d47f
4 changed files with 37 additions and 16 deletions

View file

@ -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);

View file

@ -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<ContextMenu>();
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<ContextMenu> 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<MenuItem> 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<MenuItem> updateMenuItems(
ContextMenu contextMenu, Menu m, FileSystem.FileEntry fileEntry, boolean updateInstantly) throws Exception {
ContextMenu contextMenu, Menu m, FileSystem.FileEntry fileEntry, boolean updateInstantly, AtomicReference<ContextMenu> 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());
}

View file

@ -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();
}

View file

@ -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) {