File browser fixes

This commit is contained in:
crschnick 2023-05-19 15:00:06 +00:00
parent 288f526019
commit 55d54fad01
5 changed files with 48 additions and 25 deletions

View file

@ -25,7 +25,10 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
@Override @Override
protected Region createSimple() { protected Region createSimple() {
Callback<Breadcrumbs.BreadCrumbItem<String>, ButtonBase> crumbFactory = crumb -> { Callback<Breadcrumbs.BreadCrumbItem<String>, ButtonBase> crumbFactory = crumb -> {
var btn = new Button(crumb.getValue().equals("/") ? "/" : FileNames.getFileName(crumb.getValue()), null); var name = crumb.getValue().equals("/")
? "/"
: FileNames.getFileName(crumb.getValue());
var btn = new Button(name, null);
btn.setMnemonicParsing(false); btn.setMnemonicParsing(false);
btn.setFocusTraversable(false); btn.setFocusTraversable(false);
return btn; return btn;
@ -57,7 +60,7 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
return new Label(""); return new Label("");
} }
return !item.isLast() ? new Label(sc.get().getOsType().getFileSystemSeparator()) : null; return new Label(sc.get().getOsType().getFileSystemSeparator());
}); });
} }
@ -66,7 +69,8 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
if (val.startsWith("/")) { if (val.startsWith("/")) {
modifiedElements.add(0, "/"); modifiedElements.add(0, "/");
} }
Breadcrumbs.BreadCrumbItem<String> items = Breadcrumbs.buildTreeModel(modifiedElements.toArray(String[]::new)); Breadcrumbs.BreadCrumbItem<String> items =
Breadcrumbs.buildTreeModel(modifiedElements.toArray(String[]::new));
breadcrumbs.setSelectedCrumb(items); breadcrumbs.setSelectedCrumb(items);
}); });
@ -78,7 +82,7 @@ public class FileBrowserBreadcrumbBar extends SimpleComp {
} }
breadcrumbs.selectedCrumbProperty().addListener((obs, old, val) -> { breadcrumbs.selectedCrumbProperty().addListener((obs, old, val) -> {
model.cd(val.getValue()).ifPresent(s -> { model.cd(val != null ? val.getValue() : null).ifPresent(s -> {
model.cd(s); model.cd(s);
}); });
}); });

View file

@ -31,10 +31,10 @@ public class FileSystemHelper {
.get() .get()
.getOsType() .getOsType()
.getHomeDirectory(fileSystem.getShell().get()); .getHomeDirectory(fileSystem.getShell().get());
return FileSystemHelper.resolveDirectoryPath(model, current); return validateDirectoryPath(model, resolvePath(model, current));
} }
public static String resolveDirectoryPath(OpenFileSystemModel model, String path) throws Exception { public static String resolvePath(OpenFileSystemModel model, String path) {
if (path == null) { if (path == null) {
return null; return null;
} }
@ -58,6 +58,19 @@ public class FileSystemHelper {
return path + "\\"; return path + "\\";
} }
return path;
}
public static String validateDirectoryPath(OpenFileSystemModel model, String path) throws Exception {
if (path == null) {
return null;
}
var shell = model.getFileSystem().getShell();
if (shell.isEmpty()) {
return path;
}
var normalized = shell.get() var normalized = shell.get()
.getShellDialect() .getShellDialect()
.normalizeDirectory(shell.get(), path) .normalizeDirectory(shell.get(), path)
@ -68,7 +81,6 @@ public class FileSystemHelper {
} }
model.getFileSystem().directoryAccessible(normalized); model.getFileSystem().directoryAccessible(normalized);
return FileNames.toDirectory(normalized); return FileNames.toDirectory(normalized);
} }

View file

@ -125,47 +125,53 @@ public final class OpenFileSystemModel {
return Optional.empty(); return Optional.empty();
} }
// Fix common issues with paths
var normalizedPath = FileSystemHelper.resolvePath(this, path);
if (!Objects.equals(path, normalizedPath)) {
return Optional.of(normalizedPath);
}
// Handle commands typed into navigation bar // Handle commands typed into navigation bar
if (!FileNames.isAbsolute(path) && fileSystem.getShell().isPresent()) { if (normalizedPath != null && !FileNames.isAbsolute(normalizedPath) && fileSystem.getShell().isPresent()) {
var directory = currentPath.get(); var directory = currentPath.get();
var name = path + " - " var name = normalizedPath + " - "
+ XPipeDaemon.getInstance().getStoreName(store).orElse("?"); + XPipeDaemon.getInstance().getStoreName(store).orElse("?");
ThreadHelper.runFailableAsync(() -> { ThreadHelper.runFailableAsync(() -> {
if (ShellDialects.ALL.stream().anyMatch(dialect -> path.startsWith(dialect.getOpenCommand()))) { if (ShellDialects.ALL.stream().anyMatch(dialect -> normalizedPath.startsWith(dialect.getOpenCommand()))) {
var cmd = fileSystem var cmd = fileSystem
.getShell() .getShell()
.get() .get()
.subShell(path) .subShell(normalizedPath)
.initWith(fileSystem .initWith(fileSystem
.getShell() .getShell()
.get() .get()
.getShellDialect() .getShellDialect()
.getCdCommand(currentPath.get())) .getCdCommand(currentPath.get()))
.prepareTerminalOpen(name); .prepareTerminalOpen(name);
TerminalHelper.open(path, cmd); TerminalHelper.open(normalizedPath, cmd);
} else { } else {
var cmd = fileSystem var cmd = fileSystem
.getShell() .getShell()
.get() .get()
.command(path) .command(normalizedPath)
.workingDirectory(directory) .workingDirectory(directory)
.prepareTerminalOpen(name); .prepareTerminalOpen(name);
TerminalHelper.open(path, cmd); TerminalHelper.open(normalizedPath, cmd);
} }
}); });
return Optional.of(currentPath.get()); return Optional.of(currentPath.get());
} }
String newPath = null; String dirPath = null;
try { try {
newPath = FileSystemHelper.resolveDirectoryPath(this, path); dirPath = FileSystemHelper.validateDirectoryPath(this, normalizedPath);
} catch (Exception ex) { } catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle(); ErrorEvent.fromThrowable(ex).handle();
return Optional.of(currentPath.get()); return Optional.of(currentPath.get());
} }
if (!Objects.equals(path, newPath)) { if (!Objects.equals(path, dirPath)) {
return Optional.of(newPath); return Optional.of(dirPath);
} }
ThreadHelper.runFailableAsync(() -> { ThreadHelper.runFailableAsync(() -> {

View file

@ -23,10 +23,8 @@ public class OpenInNativeManagerAction implements LeafAction {
} }
case OsType.Linux linux -> { case OsType.Linux linux -> {
var dbus = String.format(""" var dbus = String.format("""
dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"%s" string:"" dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"file://%s" string:""
""", entry.getRawFileEntry().getPath()); """, entry.getRawFileEntry().getPath());
// sc.executeSimpleCommand(
// "xdg-open " + d.fileArgument(entry.getRawFileEntry().getPath()));
sc.executeSimpleCommand(dbus); sc.executeSimpleCommand(dbus);
} }
case OsType.MacOs macOs -> { case OsType.MacOs macOs -> {
@ -49,7 +47,7 @@ public class OpenInNativeManagerAction implements LeafAction {
@Override @Override
public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) { public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
return true; return model.isLocal();
} }
@Override @Override

View file

@ -28,7 +28,9 @@ public class OpenNativeFileDetailsAction implements LeafAction {
sub.command(content).notComplex().execute(); sub.command(content).notComplex().execute();
} }
} }
case OsType.Linux linux -> {} case OsType.Linux linux -> {
throw new UnsupportedOperationException();
}
case OsType.MacOs macOs -> { case OsType.MacOs macOs -> {
sc.osascriptCommand(String.format( sc.osascriptCommand(String.format(
""" """
@ -53,11 +55,12 @@ public class OpenNativeFileDetailsAction implements LeafAction {
@Override @Override
public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) { public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
return true; var os = model.getFileSystem().getShell();
return os.isPresent() && !os.get().getOsType().equals(OsType.LINUX);
} }
@Override @Override
public String getName(OpenFileSystemModel model, List<FileBrowserEntry> entries) { public String getName(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
return "Details"; return "Show details";
} }
} }