diff --git a/app/src/main/java/io/xpipe/app/browser/FileBrowserNavigationHistory.java b/app/src/main/java/io/xpipe/app/browser/FileBrowserHistory.java similarity index 96% rename from app/src/main/java/io/xpipe/app/browser/FileBrowserNavigationHistory.java rename to app/src/main/java/io/xpipe/app/browser/FileBrowserHistory.java index b9c4186cd..6fe19adb3 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileBrowserNavigationHistory.java +++ b/app/src/main/java/io/xpipe/app/browser/FileBrowserHistory.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -final class FileBrowserNavigationHistory { +final class FileBrowserHistory { private final IntegerProperty cursor = new SimpleIntegerProperty(0); private final List history = new ArrayList<>(); @@ -25,7 +25,7 @@ final class FileBrowserNavigationHistory { return history.size() > 0 ? history.get(cursor.get()) : null; } - public void cd(String s) { + public void updateCurrent(String s) { if (s == null) { return; } diff --git a/app/src/main/java/io/xpipe/app/browser/FileListModel.java b/app/src/main/java/io/xpipe/app/browser/FileListModel.java index 35487117f..b060ee5cd 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileListModel.java +++ b/app/src/main/java/io/xpipe/app/browser/FileListModel.java @@ -19,6 +19,7 @@ import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.function.Predicate; +import java.util.stream.Stream; @Getter final class FileListModel { @@ -31,8 +32,8 @@ final class FileListModel { private final OpenFileSystemModel fileSystemModel; private final Property> comparatorProperty = new SimpleObjectProperty<>(FILE_TYPE_COMPARATOR); - private final Property> all = new SimpleObjectProperty<>(List.of()); - private final Property> shown = new SimpleObjectProperty<>(List.of()); + private final Property> all = new SimpleObjectProperty<>(new ArrayList<>()); + private final Property> shown = new SimpleObjectProperty<>(new ArrayList<>()); private final ObjectProperty> predicateProperty = new SimpleObjectProperty<>(path -> true); private final ObservableList selected = FXCollections.observableArrayList(); @@ -58,6 +59,14 @@ final class FileListModel { refreshShown(); } + public void setAll(Stream newFiles) { + try (var s = newFiles) { + var l = s.limit(5000).toList(); + all.setValue(l); + refreshShown(); + } + } + public void setComparator(Comparator comparator) { comparatorProperty.setValue(comparator); refreshShown(); diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index cbd7eccd5..26bdc8b95 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -18,11 +18,9 @@ import lombok.SneakyThrows; import java.io.IOException; import java.nio.file.Path; import java.time.Instant; -import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; @Getter final class OpenFileSystemModel { @@ -32,7 +30,7 @@ final class OpenFileSystemModel { private final Property filter = new SimpleStringProperty(); private final FileListModel fileList; private final ReadOnlyObjectWrapper currentPath = new ReadOnlyObjectWrapper<>(); - private final FileBrowserNavigationHistory history = new FileBrowserNavigationHistory(); + private final FileBrowserHistory history = new FileBrowserHistory(); private final BooleanProperty busy = new SimpleBooleanProperty(); private final FileBrowserModel browserModel; private final BooleanProperty noDirectory = new SimpleBooleanProperty(); @@ -76,28 +74,28 @@ final class OpenFileSystemModel { } public Optional cd(String path) { - if (Objects.equals(path, currentPath.get())) { - return Optional.empty(); - } - - String newPath = null; - try { - newPath = FileSystemHelper.resolveDirectoryPath(this, path); - } catch (Exception ex) { - ErrorEvent.fromThrowable(ex).handle(); - return Optional.of(currentPath.get()); - } - - if (!Objects.equals(path, newPath)) { - return Optional.of(newPath); - } - - ThreadHelper.runFailableAsync(() -> { - try (var ignored = new BusyProperty(busy)) { - cdSync(path); + if (Objects.equals(path, currentPath.get())) { + return Optional.empty(); } - }); - return Optional.empty(); + + String newPath = null; + try { + newPath = FileSystemHelper.resolveDirectoryPath(this, path); + } catch (Exception ex) { + ErrorEvent.fromThrowable(ex).handle(); + return Optional.of(currentPath.get()); + } + + if (!Objects.equals(path, newPath)) { + return Optional.of(newPath); + } + + ThreadHelper.runFailableAsync(() -> { + try (var ignored = new BusyProperty(busy)) { + cdSync(path); + } + }); + return Optional.empty(); } private void cdSync(String path) throws Exception { @@ -107,28 +105,27 @@ final class OpenFileSystemModel { this.fileSystem = fs; } - // Assumed that the path is normalized to improve performance! + // Assume that the path is normalized to improve performance! // path = FileSystemHelper.normalizeDirectoryPath(this, path); - navigateToSync(path); filter.setValue(null); currentPath.set(path); - history.cd(path); + history.updateCurrent(path); + loadFilesSync(path); } - private boolean navigateToSync(String dir) { + private boolean loadFilesSync(String dir) { try { - List newList; if (dir != null) { - newList = getFileSystem().listFiles(dir).collect(Collectors.toCollection(ArrayList::new)); + var stream = getFileSystem().listFiles(dir); noDirectory.set(false); + fileList.setAll(stream); } else { - newList = getFileSystem().listRoots().stream() - .map(s -> new FileSystem.FileEntry(getFileSystem(), s, Instant.now(), true, false, false, 0, null)) - .collect(Collectors.toCollection(ArrayList::new)); + var stream = getFileSystem().listRoots().stream() + .map(s -> new FileSystem.FileEntry(getFileSystem(), s, Instant.now(), true, false, false, 0, null)); noDirectory.set(true); + fileList.setAll(stream); } - fileList.setAll(newList); return true; } catch (Exception e) { fileList.setAll(List.of()); @@ -287,15 +284,19 @@ final class OpenFileSystemModel { }); } - public FileBrowserNavigationHistory getHistory() { + public FileBrowserHistory getHistory() { return history; } public void back() { - history.back().ifPresent(s -> cd(s)); + try (var ignored = new BusyProperty(busy)) { + history.back().ifPresent(s -> cd(s)); + } } public void forth() { - history.forth().ifPresent(s -> cd(s)); + try (var ignored = new BusyProperty(busy)) { + history.forth().ifPresent(s -> cd(s)); + } } } diff --git a/app/src/main/resources/io/xpipe/app/resources/style/browser.css b/app/src/main/resources/io/xpipe/app/resources/style/browser.css index 71cc34214..7aefa3fb7 100644 --- a/app/src/main/resources/io/xpipe/app/resources/style/browser.css +++ b/app/src/main/resources/io/xpipe/app/resources/style/browser.css @@ -1,6 +1,6 @@ .download-background { -fx-border-color: -color-neutral-muted; --fx-border-width: 2px 0 0 0; +-fx-border-width: 3px 0 0 0; -fx-padding: 1em; } @@ -25,7 +25,11 @@ -fx-border-width: 0; -fx-border-radius: 0; -fx-background-radius: 0; --fx-background-insets: 1px 2px 1px 0; +-fx-background-insets: 0; +} + +.bookmark-list .button:hover { + -fx-background-color: -color-accent-muted; } *:drag-over .download-background { @@ -82,7 +86,7 @@ -fx-opacity: 0.8; } -.browser .table-row-cell:hover { +.browser .table-row-cell:file:hover,.table-row-cell:folder:hover { -fx-background-color: -color-accent-subtle; }