Show file attributes in file explorer

This commit is contained in:
crschnick
2023-04-26 23:01:27 +00:00
parent a458f6ffe5
commit dbd0cb2d68
4 changed files with 39 additions and 7 deletions

View File

@@ -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<FileSystem.FileEntry, String>("Attributes");
modeCol.setCellValueFactory(
param -> new SimpleObjectProperty<>(param.getValue().getMode()));
modeCol.setCellFactory(col -> new FileModeCell());
var table = new TableView<FileSystem.FileEntry>();
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<FileSystem.FileEntry, String> {
@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<FileSystem.FileEntry, Instant> {
@Override

View File

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

View File

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

View File

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