mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
More quick access fixes
This commit is contained in:
parent
76379b5a5d
commit
baee77d47f
4 changed files with 37 additions and 16 deletions
|
@ -528,11 +528,13 @@ final class BrowserFileListComp extends SimpleComp {
|
||||||
|
|
||||||
Node imageView = PrettyImageHelper.ofFixedSize(img, 24, 24).createRegion();
|
Node imageView = PrettyImageHelper.ofFixedSize(img, 24, 24).createRegion();
|
||||||
HBox graphic = new HBox(imageView,
|
HBox graphic = new HBox(imageView,
|
||||||
new Spacer(7),
|
new Spacer(5),
|
||||||
quickAccess,
|
quickAccess,
|
||||||
new Spacer(3),
|
new Spacer(1),
|
||||||
textField);
|
textField);
|
||||||
|
quickAccess.prefHeightProperty().bind(graphic.heightProperty());
|
||||||
graphic.setAlignment(Pos.CENTER_LEFT);
|
graphic.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
graphic.setPrefHeight(34);
|
||||||
HBox.setHgrow(textField, Priority.ALWAYS);
|
HBox.setHgrow(textField, Priority.ALWAYS);
|
||||||
graphic.setAlignment(Pos.CENTER_LEFT);
|
graphic.setAlignment(Pos.CENTER_LEFT);
|
||||||
setGraphic(graphic);
|
setGraphic(graphic);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import javafx.scene.layout.Region;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ public class BrowserQuickAccessButtonComp extends SimpleComp {
|
||||||
button.apply(struc -> {
|
button.apply(struc -> {
|
||||||
struc.get().setOnAction(event -> {
|
struc.get().setOnAction(event -> {
|
||||||
showMenu(struc.get());
|
showMenu(struc.get());
|
||||||
|
event.consume();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return button.createRegion();
|
return button.createRegion();
|
||||||
|
@ -62,8 +64,9 @@ public class BrowserQuickAccessButtonComp extends SimpleComp {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var actionsMenu = new AtomicReference<ContextMenu>();
|
||||||
var r = new Menu();
|
var r = new Menu();
|
||||||
var newItems = updateMenuItems(cm, r, fileEntry, true);
|
var newItems = updateMenuItems(cm, r, fileEntry, true, actionsMenu);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
cm.getItems().addAll(r.getItems());
|
cm.getItems().addAll(r.getItems());
|
||||||
cm.show(anchor, Side.RIGHT, 0, 0);
|
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));
|
var browserCm = new BrowserContextMenu(model, new BrowserEntry(fileEntry, model.getFileList(), false));
|
||||||
browserCm.setOnAction(e -> {
|
browserCm.setOnAction(e -> {
|
||||||
contextMenu.hide();
|
contextMenu.hide();
|
||||||
|
@ -89,6 +92,7 @@ public class BrowserQuickAccessButtonComp extends SimpleComp {
|
||||||
}
|
}
|
||||||
|
|
||||||
browserCm.show(m.getStyleableNode(), Side.RIGHT, 0, 0);
|
browserCm.show(m.getStyleableNode(), Side.RIGHT, 0, 0);
|
||||||
|
showingActionsMenu.set(browserCm);
|
||||||
});
|
});
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -103,23 +107,31 @@ public class BrowserQuickAccessButtonComp extends SimpleComp {
|
||||||
|
|
||||||
var hover = new SimpleBooleanProperty();
|
var hover = new SimpleBooleanProperty();
|
||||||
m.setOnShowing(event -> {
|
m.setOnShowing(event -> {
|
||||||
browserCm.hide();
|
var actionsMenu = showingActionsMenu.get();
|
||||||
|
if (actionsMenu != null) {
|
||||||
|
actionsMenu.hide();
|
||||||
|
showingActionsMenu.set(null);
|
||||||
|
}
|
||||||
hover.set(true);
|
hover.set(true);
|
||||||
event.consume();
|
event.consume();
|
||||||
});
|
});
|
||||||
m.setOnHiding(event -> {
|
m.setOnHiding(event -> {
|
||||||
browserCm.hide();
|
var actionsMenu = showingActionsMenu.get();
|
||||||
|
if (actionsMenu != null) {
|
||||||
|
actionsMenu.hide();
|
||||||
|
showingActionsMenu.set(null);
|
||||||
|
}
|
||||||
hover.set(false);
|
hover.set(false);
|
||||||
event.consume();
|
event.consume();
|
||||||
});
|
});
|
||||||
new BooleanTimer(hover, 500, () -> {
|
new BooleanTimer(hover, 100, () -> {
|
||||||
if (m.isShowing() && !m.getItems().getFirst().equals(empty)) {
|
if (m.isShowing() && !m.getItems().getFirst().equals(empty)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MenuItem> newItems = null;
|
List<MenuItem> newItems = null;
|
||||||
try {
|
try {
|
||||||
newItems = updateMenuItems(contextMenu, m, fileEntry, false);
|
newItems = updateMenuItems(contextMenu, m, fileEntry, false, showingActionsMenu);
|
||||||
m.getItems().setAll(newItems);
|
m.getItems().setAll(newItems);
|
||||||
if (!browserCm.isShowing()) {
|
if (!browserCm.isShowing()) {
|
||||||
m.hide();
|
m.hide();
|
||||||
|
@ -135,21 +147,24 @@ public class BrowserQuickAccessButtonComp extends SimpleComp {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browserCm.isShowing()) {
|
var actionsMenu = showingActionsMenu.get();
|
||||||
browserCm.hide();
|
if (actionsMenu != null && actionsMenu.isShowing()) {
|
||||||
|
actionsMenu.hide();
|
||||||
|
showingActionsMenu.set(null);
|
||||||
m.show();
|
m.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m.hide();
|
m.hide();
|
||||||
browserCm.show(m.getStyleableNode(), Side.RIGHT, 0, 0);
|
browserCm.show(m.getStyleableNode(), Side.RIGHT, 0, 0);
|
||||||
|
showingActionsMenu.set(browserCm);
|
||||||
event.consume();
|
event.consume();
|
||||||
});
|
});
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MenuItem> updateMenuItems(
|
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());
|
var newFiles = model.getFileSystem().listFiles(fileEntry.getPath());
|
||||||
try (var s = newFiles) {
|
try (var s = newFiles) {
|
||||||
var list = s.toList();
|
var list = s.toList();
|
||||||
|
@ -169,12 +184,12 @@ public class BrowserQuickAccessButtonComp extends SimpleComp {
|
||||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||||
})
|
})
|
||||||
.collect(Collectors.toMap(
|
.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()
|
var dirs = list.stream()
|
||||||
.filter(e -> e.getKind() == FileKind.DIRECTORY)
|
.filter(e -> e.getKind() == FileKind.DIRECTORY)
|
||||||
.toList();
|
.toList();
|
||||||
if (dirs.size() == 1) {
|
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());
|
newItems.addAll(menus.values());
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class BooleanTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
var nowMs = now;
|
var nowMs = now;
|
||||||
if ((nowMs - init) > duration * 1000L) {
|
if ((nowMs - init) > duration * 1_000_000L) {
|
||||||
toExecute.run();
|
toExecute.run();
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,11 @@ public final class HumanReadableFormat {
|
||||||
ci.next();
|
ci.next();
|
||||||
}
|
}
|
||||||
var f = "%.1f";
|
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) {
|
public static String progressByteCount(long bytes) {
|
||||||
|
|
Loading…
Reference in a new issue