mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-24 00:21:11 -04:00
Show file attributes in file explorer
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user