File browser fixes

This commit is contained in:
crschnick 2024-07-21 04:31:33 +00:00
parent 5748bb4bfc
commit 981c51e405
3 changed files with 50 additions and 41 deletions

View file

@ -1,11 +1,11 @@
package io.xpipe.app.browser.file; package io.xpipe.app.browser.file;
import atlantafx.base.controls.Spacer;
import atlantafx.base.theme.Styles;
import io.xpipe.app.browser.action.BrowserAction; import io.xpipe.app.browser.action.BrowserAction;
import io.xpipe.app.comp.base.LazyTextFieldComp; import io.xpipe.app.comp.base.LazyTextFieldComp;
import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.AppI18n;
import io.xpipe.app.fxcomps.SimpleComp; import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.fxcomps.SimpleCompStructure;
import io.xpipe.app.fxcomps.augment.ContextMenuAugment;
import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import io.xpipe.app.fxcomps.impl.PrettyImageHelper;
import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.util.*; import io.xpipe.app.util.*;
@ -13,7 +13,6 @@ import io.xpipe.core.process.OsType;
import io.xpipe.core.store.FileKind; import io.xpipe.core.store.FileKind;
import io.xpipe.core.store.FileNames; import io.xpipe.core.store.FileNames;
import io.xpipe.core.store.FileSystem; import io.xpipe.core.store.FileSystem;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.*; import javafx.beans.property.*;
@ -34,14 +33,13 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import atlantafx.base.controls.Spacer; import java.time.Duration;
import atlantafx.base.theme.Styles;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import static io.xpipe.app.util.HumanReadableFormat.byteCount; import static io.xpipe.app.util.HumanReadableFormat.byteCount;
import static javafx.scene.control.TableColumn.SortType.ASCENDING; import static javafx.scene.control.TableColumn.SortType.ASCENDING;
@ -134,6 +132,7 @@ public final class BrowserFileListComp extends SimpleComp {
} }
private void prepareTypedSelectionModel(TableView<BrowserEntry> table) { private void prepareTypedSelectionModel(TableView<BrowserEntry> table) {
AtomicReference<Instant> lastFail = new AtomicReference<>();
table.addEventHandler(KeyEvent.KEY_PRESSED,event -> { table.addEventHandler(KeyEvent.KEY_PRESSED,event -> {
var typed = event.getText(); var typed = event.getText();
if (typed.isEmpty()) { if (typed.isEmpty()) {
@ -143,15 +142,26 @@ public final class BrowserFileListComp extends SimpleComp {
var updated = typedSelection.get() + typed; var updated = typedSelection.get() + typed;
var find = fileList.getShown().getValue().stream().filter(browserEntry -> browserEntry.getFileName().toLowerCase().startsWith(updated.toLowerCase())).findFirst(); var find = fileList.getShown().getValue().stream().filter(browserEntry -> browserEntry.getFileName().toLowerCase().startsWith(updated.toLowerCase())).findFirst();
if (find.isEmpty()) { if (find.isEmpty()) {
if (lastFail.get() == null) {
lastFail.set(Instant.now());
}
var inCooldown = Duration.between(lastFail.get(), Instant.now()).toMillis() < 1000;
if (inCooldown) {
event.consume();
return;
}
lastFail.set(null);
typedSelection.set(""); typedSelection.set("");
table.getSelectionModel().clearSelection(); table.getSelectionModel().clearSelection();
event.consume(); event.consume();
return; return;
} }
lastFail.set(null);
typedSelection.set(updated); typedSelection.set(updated);
table.scrollTo(find.get()); table.scrollTo(find.get());
table.getSelectionModel().select(find.get()); table.getSelectionModel().clearAndSelect(fileList.getShown().getValue().indexOf(find.get()));
event.consume(); event.consume();
}); });
@ -270,38 +280,6 @@ public final class BrowserFileListComp extends SimpleComp {
return row.getItem() != null; return row.getItem() != null;
}, },
row.itemProperty())); row.itemProperty()));
new ContextMenuAugment<>(
event -> {
if (row.getItem() == null) {
return event.getButton() == MouseButton.SECONDARY;
}
if (row.getItem() != null
&& row.getItem()
.getRawFileEntry()
.resolved()
.getKind()
== FileKind.DIRECTORY) {
return event.getButton() == MouseButton.SECONDARY;
}
if (row.getItem() != null
&& row.getItem()
.getRawFileEntry()
.resolved()
.getKind()
!= FileKind.DIRECTORY) {
return event.getButton() == MouseButton.SECONDARY
|| event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2;
}
return false;
},
null,
() -> {
return new BrowserContextMenu(fileList.getFileSystemModel(), row.getItem(), false);
})
.augment(new SimpleCompStructure<>(row));
var listEntry = Bindings.createObjectBinding( var listEntry = Bindings.createObjectBinding(
() -> new BrowserFileListCompEntry(table, row, row.getItem(), fileList), row.itemProperty()); () -> new BrowserFileListCompEntry(table, row, row.getItem(), fileList), row.itemProperty());

View file

@ -7,6 +7,7 @@ import io.xpipe.core.store.FileKind;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.input.*; import javafx.scene.input.*;
@ -31,6 +32,7 @@ public class BrowserFileListCompEntry {
private Point2D lastOver = new Point2D(-1, -1); private Point2D lastOver = new Point2D(-1, -1);
private TimerTask activeTask; private TimerTask activeTask;
private ContextMenu lastContextMenu;
public BrowserFileListCompEntry( public BrowserFileListCompEntry(
TableView<BrowserEntry> tv, Node row, BrowserEntry item, BrowserFileListModel model) { TableView<BrowserEntry> tv, Node row, BrowserEntry item, BrowserFileListModel model) {
@ -41,6 +43,19 @@ public class BrowserFileListCompEntry {
} }
public void onMouseClick(MouseEvent t) { public void onMouseClick(MouseEvent t) {
if (showContextMenu(t)) {
if (lastContextMenu != null) {
lastContextMenu.hide();
lastContextMenu = null;
}
var cm = new BrowserContextMenu(model.getFileSystemModel(), item, false);
cm.show(row, t.getScreenX(), t.getScreenY());
lastContextMenu = cm;
t.consume();
return;
}
if (item == null) { if (item == null) {
// Only clear for normal clicks // Only clear for normal clicks
if (t.isStillSincePress()) { if (t.isStillSincePress()) {
@ -62,6 +77,23 @@ public class BrowserFileListCompEntry {
t.consume(); t.consume();
} }
private boolean showContextMenu(MouseEvent event) {
if (item == null) {
return event.getButton() == MouseButton.SECONDARY;
}
if (item.getRawFileEntry().resolved().getKind() == FileKind.DIRECTORY) {
return event.getButton() == MouseButton.SECONDARY;
}
if (item.getRawFileEntry().resolved().getKind() != FileKind.DIRECTORY) {
return event.getButton() == MouseButton.SECONDARY
|| event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2;
}
return false;
}
public void onMouseShiftClick(MouseEvent t) { public void onMouseShiftClick(MouseEvent t) {
if (t.getButton() != MouseButton.PRIMARY) { if (t.getButton() != MouseButton.PRIMARY) {
return; return;

View file

@ -115,8 +115,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
&& getCurrentPath().get() != null) { && getCurrentPath().get() != null) {
if (getBrowserModel() instanceof BrowserSessionModel bm) { if (getBrowserModel() instanceof BrowserSessionModel bm) {
bm.getSavedState() bm.getSavedState()
.add(new BrowserSavedState.Entry( .add(new BrowserSavedState.Entry(getEntry().get().getUuid(), getCurrentPath().get()));
getEntry().get().getUuid(), getCurrentPath().get()));
} }
} }
try { try {