File browser refinements

This commit is contained in:
crschnick 2023-05-08 23:12:53 +00:00
parent 5845abb481
commit d0ca3e8a27
7 changed files with 78 additions and 65 deletions

View file

@ -44,7 +44,7 @@ final class BookmarkList extends SimpleComp {
button.setOnAction(event -> { button.setOnAction(event -> {
var fileSystem = ((ShellStore) e.getEntry().getStore()); var fileSystem = ((ShellStore) e.getEntry().getStore());
model.openFileSystem(fileSystem); model.openFileSystemAsync(fileSystem);
event.consume(); event.consume();
}); });
GrowAugment.create(true, false).augment(new SimpleCompStructure<>(button)); GrowAugment.create(true, false).augment(new SimpleCompStructure<>(button));

View file

@ -71,14 +71,14 @@ public class FileBrowserModel {
if (found.isPresent()) { if (found.isPresent()) {
selected.setValue(found.get()); selected.setValue(found.get());
} else { } else {
openFileSystem(store); openFileSystemAsync(store);
} }
} }
public void openFileSystem(ShellStore store) { public void openFileSystemAsync(ShellStore store) {
// Prevent multiple tabs in non browser modes // Prevent multiple tabs in non browser modes
if (!mode.equals(Mode.BROWSER)) { if (!mode.equals(Mode.BROWSER)) {
ThreadHelper.runAsync(() -> { ThreadHelper.runFailableAsync(() -> {
var open = openFileSystems.size() > 0 ? openFileSystems.get(0) : null; var open = openFileSystems.size() > 0 ? openFileSystems.get(0) : null;
if (open != null) { if (open != null) {
open.closeSync(); open.closeSync();
@ -88,23 +88,16 @@ public class FileBrowserModel {
var model = new OpenFileSystemModel(this); var model = new OpenFileSystemModel(this);
openFileSystems.add(model); openFileSystems.add(model);
selected.setValue(model); selected.setValue(model);
model.switchAsync(store); model.switchSync(store);
}); });
return; return;
} }
// Duplication protection (Not needed for now) ThreadHelper.runFailableAsync(() -> {
// var found = openFileSystems.stream() var model = new OpenFileSystemModel(this);
// .filter(fileSystemModel -> fileSystemModel.getStore().getValue().equals(store)) openFileSystems.add(model);
// .findFirst(); selected.setValue(model);
// if (found.isPresent()) { model.switchSync(store);
// selected.setValue(found.get()); });
// return;
// }
var model = new OpenFileSystemModel(this);
openFileSystems.add(model);
selected.setValue(model);
model.switchAsync(store);
} }
} }

View file

@ -8,9 +8,11 @@ import io.xpipe.app.fxcomps.util.PlatformThread;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.scene.control.ToolBar; import javafx.scene.control.ToolBar;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import lombok.EqualsAndHashCode;
import lombok.Value; import lombok.Value;
@Value @Value
@EqualsAndHashCode(callSuper = true)
public class FileBrowserStatusBarComp extends SimpleComp { public class FileBrowserStatusBarComp extends SimpleComp {
OpenFileSystemModel model; OpenFileSystemModel model;
@ -20,7 +22,7 @@ public class FileBrowserStatusBarComp extends SimpleComp {
var cc = PlatformThread.sync(FileBrowserClipboard.currentCopyClipboard); var cc = PlatformThread.sync(FileBrowserClipboard.currentCopyClipboard);
var ccCount = Bindings.createStringBinding(() -> { var ccCount = Bindings.createStringBinding(() -> {
if (cc.getValue() != null && cc.getValue().getEntries().size() > 0) { if (cc.getValue() != null && cc.getValue().getEntries().size() > 0) {
return String.valueOf(cc.getValue().getEntries().size()) + " file" + (cc.getValue().getEntries().size() > 1 ? "s" : "") + " in clipboard"; return cc.getValue().getEntries().size() + " file" + (cc.getValue().getEntries().size() > 1 ? "s" : "") + " in clipboard";
} else { } else {
return null; return null;
} }

View file

@ -178,6 +178,13 @@ final class FileListComp extends AnchorPane {
} }
}); });
prepareTableEntries(table);
prepareTableChanges(table, mtimeCol, modeCol);
return table;
}
private void prepareTableEntries(TableView<FileSystem.FileEntry> table) {
var emptyEntry = new FileListCompEntry(table, null, fileList); var emptyEntry = new FileListCompEntry(table, null, fileList);
table.setOnDragOver(event -> { table.setOnDragOver(event -> {
emptyEntry.onDragOver(event); emptyEntry.onDragOver(event);
@ -242,16 +249,17 @@ final class FileListComp extends AnchorPane {
return row; return row;
}); });
}
private void prepareTableChanges(TableView<FileSystem.FileEntry> table, TableColumn<FileSystem.FileEntry, Instant> mtimeCol, TableColumn<FileSystem.FileEntry, String> modeCol) {
var lastDir = new SimpleObjectProperty<FileSystem.FileEntry>(); var lastDir = new SimpleObjectProperty<FileSystem.FileEntry>();
SimpleChangeListener.apply(fileList.getShown(), (newValue) -> { Runnable updateHandler = () -> {
PlatformThread.runLaterIfNeeded(() -> { PlatformThread.runLaterIfNeeded(() -> {
var newItems = new ArrayList<FileSystem.FileEntry>(); var newItems = new ArrayList<FileSystem.FileEntry>();
var parentEntry = fileList.getFileSystemModel().getCurrentParentDirectory(); var parentEntry = fileList.getFileSystemModel().getCurrentParentDirectory();
if (parentEntry != null) { if (parentEntry != null) {
newItems.add(parentEntry); newItems.add(parentEntry);
} }
newItems.addAll(newValue); newItems.addAll(fileList.getShown().getValue());
var hasModifiedDate = var hasModifiedDate =
newItems.size() == 0 || newItems.stream().anyMatch(entry -> entry.getDate() != null); newItems.size() == 0 || newItems.stream().anyMatch(entry -> entry.getDate() != null);
@ -278,7 +286,9 @@ final class FileListComp extends AnchorPane {
} }
} }
table.getItems().setAll(newItems); if (!table.getItems().equals(newItems)) {
table.getItems().setAll(newItems);
}
var currentDirectory = fileList.getFileSystemModel().getCurrentDirectory(); var currentDirectory = fileList.getFileSystemModel().getCurrentDirectory();
if (!Objects.equals(lastDir.get(), currentDirectory)) { if (!Objects.equals(lastDir.get(), currentDirectory)) {
@ -295,9 +305,16 @@ final class FileListComp extends AnchorPane {
} }
lastDir.setValue(currentDirectory); lastDir.setValue(currentDirectory);
}); });
};
updateHandler.run();
fileList.getShown().addListener((observable, oldValue, newValue) -> {
updateHandler.run();
});
fileList.getFileSystemModel().getCurrentPath().addListener((observable, oldValue, newValue) -> {
if (oldValue == null) {
updateHandler.run();
}
}); });
return table;
} }
private void borderScroll(TableView<?> tableView, DragEvent event) { private void borderScroll(TableView<?> tableView, DragEvent event) {

View file

@ -84,7 +84,10 @@ public class OpenFileSystemComp extends SimpleComp {
FileListComp directoryView = new FileListComp(model.getFileList()); FileListComp directoryView = new FileListComp(model.getFileList());
var root = new VBox(topBar, directoryView, new FileBrowserStatusBarComp(model).createRegion()); var root = new VBox(topBar, directoryView);
if (model.getBrowserModel().getMode() == FileBrowserModel.Mode.BROWSER) {
root.getChildren().add(new FileBrowserStatusBarComp(model).createRegion());
}
VBox.setVgrow(directoryView, Priority.ALWAYS); VBox.setVgrow(directoryView, Priority.ALWAYS);
root.setPadding(Insets.EMPTY); root.setPadding(Insets.EMPTY);
model.getFileList().predicateProperty().set(PREDICATE_NOT_HIDDEN); model.getFileList().predicateProperty().set(PREDICATE_NOT_HIDDEN);

View file

@ -75,28 +75,28 @@ final class OpenFileSystemModel {
} }
public Optional<String> cd(String path) { public Optional<String> cd(String path) {
if (Objects.equals(path, currentPath.get())) { 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);
}
});
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 { private void cdSync(String path) throws Exception {
@ -123,7 +123,8 @@ final class OpenFileSystemModel {
fileList.setAll(stream); fileList.setAll(stream);
} else { } else {
var stream = getFileSystem().listRoots().stream() var stream = getFileSystem().listRoots().stream()
.map(s -> new FileSystem.FileEntry(getFileSystem(), s, Instant.now(), true, false, false, 0, null)); .map(s -> new FileSystem.FileEntry(
getFileSystem(), s, Instant.now(), true, false, false, 0, null));
noDirectory.set(true); noDirectory.set(true);
fileList.setAll(stream); fileList.setAll(stream);
} }
@ -248,22 +249,16 @@ final class OpenFileSystemModel {
store = null; store = null;
} }
private void switchSync(FileSystemStore fileSystem) throws Exception { public void switchSync(FileSystemStore fileSystem) throws Exception {
closeSync(); BusyProperty.execute(busy, () -> {
this.store.setValue(fileSystem); closeSync();
var fs = fileSystem.createFileSystem(); this.store.setValue(fileSystem);
fs.open(); var fs = fileSystem.createFileSystem();
this.fileSystem = fs; fs.open();
this.fileSystem = fs;
var current = FileSystemHelper.getStartDirectory(this); var current = FileSystemHelper.getStartDirectory(this);
cdSync(current); cdSync(current);
}
public void switchAsync(FileSystemStore fileSystem) {
ThreadHelper.runFailableAsync(() -> {
BusyProperty.execute(busy, () -> {
switchSync(fileSystem);
});
}); });
} }
@ -278,7 +273,10 @@ final class OpenFileSystemModel {
var connection = ((ConnectionFileSystem) fileSystem).getShellControl(); var connection = ((ConnectionFileSystem) fileSystem).getShellControl();
var command = s.control() var command = s.control()
.initWith(connection.getShellDialect().getCdCommand(directory)) .initWith(connection.getShellDialect().getCdCommand(directory))
.prepareTerminalOpen(directory + " - " + XPipeDaemon.getInstance().getStoreName(store.getValue()).orElse("?")); .prepareTerminalOpen(directory + " - "
+ XPipeDaemon.getInstance()
.getStoreName(store.getValue())
.orElse("?"));
TerminalHelper.open(directory, command); TerminalHelper.open(directory, command);
} }
}); });

View file

@ -66,7 +66,7 @@ public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {
.filter(e -> e.equals(s)) .filter(e -> e.equals(s))
.findAny() .findAny()
.flatMap(store -> { .flatMap(store -> {
if (ShellStore.isLocal(store.asNeeded()) && mode == Mode.PROXY) { if (mode == Mode.PROXY && ShellStore.isLocal(store.asNeeded())) {
return Optional.of(AppI18n.get("none")); return Optional.of(AppI18n.get("none"));
} }