From dbd0cb2d689e4eea4f54bdb9658203ed5fe0f356 Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 26 Apr 2023 23:01:27 +0000 Subject: [PATCH] Show file attributes in file explorer --- .../io/xpipe/app/browser/FileListComp.java | 31 +++++++++++++++++-- .../xpipe/app/browser/FileSystemHelper.java | 4 ++- .../app/browser/OpenFileSystemModel.java | 6 ++-- .../java/io/xpipe/core/store/FileSystem.java | 5 ++- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/FileListComp.java b/app/src/main/java/io/xpipe/app/browser/FileListComp.java index f4779da23..348c582f6 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileListComp.java +++ b/app/src/main/java/io/xpipe/app/browser/FileListComp.java @@ -12,6 +12,7 @@ import io.xpipe.app.fxcomps.util.SimpleChangeListener; import io.xpipe.app.util.Containers; import io.xpipe.app.util.HumanReadableFormat; import io.xpipe.core.impl.FileNames; +import io.xpipe.core.process.OsType; import io.xpipe.core.store.FileSystem; import javafx.beans.binding.Bindings; import javafx.beans.property.*; @@ -85,12 +86,16 @@ final class FileListComp extends AnchorPane { mtimeCol.setCellFactory(col -> new FileTimeCell()); mtimeCol.getStyleClass().add(Tweaks.ALIGN_RIGHT); - // ~ + + var modeCol = new TableColumn("Attributes"); + modeCol.setCellValueFactory( + param -> new SimpleObjectProperty<>(param.getValue().getMode())); + modeCol.setCellFactory(col -> new FileModeCell()); var table = new TableView(); table.setPlaceholder(new Region()); table.getStyleClass().add(Styles.STRIPED); - table.getColumns().setAll(filenameCol, sizeCol, mtimeCol); + table.getColumns().setAll(filenameCol, sizeCol, modeCol, mtimeCol); table.getSortOrder().add(filenameCol); table.setSortPolicy(param -> { var comp = table.getComparator(); @@ -246,6 +251,15 @@ final class FileListComp extends AnchorPane { } } + var hasAttributes = fileList.getFileSystemModel().getFileSystem() != null && !fileList.getFileSystemModel().getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS); + if (!hasAttributes) { + table.getColumns().remove(modeCol); + } else { + if (!table.getColumns().contains(modeCol)) { + table.getColumns().add(modeCol); + } + } + table.getItems().setAll(newItems); var currentDirectory = fileList.getFileSystemModel().getCurrentDirectory(); @@ -372,6 +386,19 @@ final class FileListComp extends AnchorPane { } } + private class FileModeCell extends TableCell { + + @Override + protected void updateItem(String mode, boolean empty) { + super.updateItem(mode, empty); + if (empty || getTableRow() == null || getTableRow().getItem() == null) { + setText(null); + } else { + setText(mode); + } + } + } + private static class FileTimeCell extends TableCell { @Override diff --git a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java index e31bb9aaf..9fd2bec85 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java +++ b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java @@ -86,7 +86,9 @@ public class FileSystemHelper { Files.isDirectory(file), Files.isHidden(file), Files.isExecutable(file), - Files.size(file)); + Files.size(file), + null + ); } public static void dropLocalFilesInto(FileSystem.FileEntry entry, List files) { 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 e21907cbe..cbd7eccd5 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -64,7 +64,7 @@ final class OpenFileSystemModel { return null; } - return new FileSystem.FileEntry(fileSystem, parent, null, true, false, false, 0); + return new FileSystem.FileEntry(fileSystem, parent, null, true, false, false, 0, null); } public FileSystem.FileEntry getCurrentDirectory() { @@ -72,7 +72,7 @@ final class OpenFileSystemModel { return null; } - return new FileSystem.FileEntry(fileSystem, currentPath.get(), null, true, false, false, 0); + return new FileSystem.FileEntry(fileSystem, currentPath.get(), null, true, false, false, 0, null); } public Optional cd(String path) { @@ -124,7 +124,7 @@ final class OpenFileSystemModel { noDirectory.set(false); } else { newList = getFileSystem().listRoots().stream() - .map(s -> new FileSystem.FileEntry(getFileSystem(), s, Instant.now(), true, false, false, 0)) + .map(s -> new FileSystem.FileEntry(getFileSystem(), s, Instant.now(), true, false, false, 0, null)) .collect(Collectors.toCollection(ArrayList::new)); noDirectory.set(true); } diff --git a/core/src/main/java/io/xpipe/core/store/FileSystem.java b/core/src/main/java/io/xpipe/core/store/FileSystem.java index a59e4d1ba..7d4760267 100644 --- a/core/src/main/java/io/xpipe/core/store/FileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/FileSystem.java @@ -26,12 +26,15 @@ public interface FileSystem extends Closeable, AutoCloseable { boolean hidden; Boolean executable; long size; + String mode; public FileEntry( @NonNull FileSystem fileSystem, @NonNull String path, Instant date, boolean directory, boolean hidden, Boolean executable, - long size + long size, + String mode ) { this.fileSystem = fileSystem; + this.mode = mode; this.path = directory ? FileNames.toDirectory(path) : path; this.date = date; this.directory = directory;